aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sol2/tests/runtime_tests/source/tables.traversal.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-08-19 19:48:10 -0400
committerClyne Sullivan <clyne@bitgloo.com>2022-08-19 19:48:10 -0400
commitc467671ae8b6ec161c17e86f3383fd0625f755b8 (patch)
treefd126d5721256b15c0d71e4c47033e341bdb7816 /lib/sol2/tests/runtime_tests/source/tables.traversal.cpp
parentda0913771538fd9b1ca538615fd9aa0388608466 (diff)
remove sol2 (will re-add as submodule)
Diffstat (limited to 'lib/sol2/tests/runtime_tests/source/tables.traversal.cpp')
-rw-r--r--lib/sol2/tests/runtime_tests/source/tables.traversal.cpp202
1 files changed, 0 insertions, 202 deletions
diff --git a/lib/sol2/tests/runtime_tests/source/tables.traversal.cpp b/lib/sol2/tests/runtime_tests/source/tables.traversal.cpp
deleted file mode 100644
index 94b2085..0000000
--- a/lib/sol2/tests/runtime_tests/source/tables.traversal.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-// sol3
-
-// The MIT License (MIT)
-
-// Copyright (c) 2013-2019 Rapptz, ThePhD and contributors
-
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-#include "sol_test.hpp"
-
-#include <catch.hpp>
-
-TEST_CASE("tables/for_each", "Testing the use of for_each to get values from a lua table") {
- sol::state lua;
- lua.open_libraries(sol::lib::base);
-
- lua.safe_script(
- "arr = {\n"
- "[0] = \"Hi\",\n"
- "[1] = 123.45,\n"
- "[2] = \"String value\",\n"
- // Does nothing
- //"[3] = nil,\n"
- //"[nil] = 3,\n"
- "[\"WOOF\"] = 123,\n"
- "}");
- sol::table tbl = lua["arr"];
- std::size_t tablesize = 4;
- std::size_t iterations = 0;
- auto fx = [&iterations](sol::object key, sol::object value) {
- ++iterations;
- sol::type keytype = key.get_type();
- switch (keytype) {
- case sol::type::number:
- switch (key.as<int>()) {
- case 0:
- REQUIRE((value.as<std::string>() == "Hi"));
- break;
- case 1:
- REQUIRE((value.as<double>() == 123.45));
- break;
- case 2:
- REQUIRE((value.as<std::string>() == "String value"));
- break;
- case 3:
- REQUIRE((value.is<sol::lua_nil_t>()));
- break;
- }
- break;
- case sol::type::string:
- if (key.as<std::string>() == "WOOF") {
- REQUIRE((value.as<double>() == 123));
- }
- break;
- case sol::type::lua_nil:
- REQUIRE((value.as<double>() == 3));
- break;
- default:
- break;
- }
- };
- auto fxpair = [&fx](std::pair<sol::object, sol::object> kvp) { fx(kvp.first, kvp.second); };
- tbl.for_each(fx);
- REQUIRE(iterations == tablesize);
-
- iterations = 0;
- tbl.for_each(fxpair);
- REQUIRE(iterations == tablesize);
-}
-
-TEST_CASE("tables/for_each empty", "empty tables should not crash") {
- sol::state lua;
- lua.open_libraries(sol::lib::base);
-
- lua.safe_script("arr = {}");
- sol::table tbl = lua["arr"];
- REQUIRE(tbl.empty());
- std::size_t tablesize = 0;
- std::size_t iterations = 0;
- auto fx = [&iterations](sol::object key, sol::object value) {
- ++iterations;
- sol::type keytype = key.get_type();
- switch (keytype) {
- case sol::type::number:
- switch (key.as<int>()) {
- case 0:
- REQUIRE((value.as<std::string>() == "Hi"));
- break;
- case 1:
- REQUIRE((value.as<double>() == 123.45));
- break;
- case 2:
- REQUIRE((value.as<std::string>() == "String value"));
- break;
- case 3:
- REQUIRE((value.is<sol::lua_nil_t>()));
- break;
- }
- break;
- case sol::type::string:
- if (key.as<std::string>() == "WOOF") {
- REQUIRE((value.as<double>() == 123));
- }
- break;
- case sol::type::lua_nil:
- REQUIRE((value.as<double>() == 3));
- break;
- default:
- break;
- }
- };
- auto fxpair = [&fx](std::pair<sol::object, sol::object> kvp) { fx(kvp.first, kvp.second); };
- tbl.for_each(fx);
- REQUIRE(iterations == tablesize);
-
- iterations = 0;
- tbl.for_each(fxpair);
- REQUIRE(iterations == tablesize);
-
- iterations = 0;
- for (const auto& kvp : tbl) {
- fxpair(kvp);
- ++iterations;
- }
- REQUIRE(iterations == tablesize);
-}
-
-TEST_CASE("tables/iterators", "Testing the use of iteratrs to get values from a lua table") {
- sol::state lua;
- lua.open_libraries(sol::lib::base);
-
- lua.safe_script(
- "arr = {\n"
- "[0] = \"Hi\",\n"
- "[1] = 123.45,\n"
- "[2] = \"String value\",\n"
- // Does nothing
- //"[3] = nil,\n"
- //"[nil] = 3,\n"
- "[\"WOOF\"] = 123,\n"
- "}");
- sol::table tbl = lua["arr"];
- std::size_t tablesize = 4;
- std::size_t iterations = 0;
-
- int begintop = 0;
- int endtop = 0;
- {
- test_stack_guard s(lua.lua_state(), begintop, endtop);
- for (auto& kvp : tbl) {
- [&iterations](sol::object key, sol::object value) {
- ++iterations;
- sol::type keytype = key.get_type();
- switch (keytype) {
- case sol::type::number:
- switch (key.as<int>()) {
- case 0:
- REQUIRE((value.as<std::string>() == "Hi"));
- break;
- case 1:
- REQUIRE((value.as<double>() == 123.45));
- break;
- case 2:
- REQUIRE((value.as<std::string>() == "String value"));
- break;
- case 3:
- REQUIRE((value.is<sol::lua_nil_t>()));
- break;
- }
- break;
- case sol::type::string:
- if (key.as<std::string>() == "WOOF") {
- REQUIRE((value.as<double>() == 123));
- }
- break;
- case sol::type::lua_nil:
- REQUIRE((value.as<double>() == 3));
- break;
- default:
- break;
- }
- }(kvp.first, kvp.second);
- }
- }
- REQUIRE(begintop == endtop);
- REQUIRE(iterations == tablesize);
-}