From c467671ae8b6ec161c17e86f3383fd0625f755b8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 19 Aug 2022 19:48:10 -0400 Subject: remove sol2 (will re-add as submodule) --- .../runtime_tests/source/tables.traversal.cpp | 202 --------------------- 1 file changed, 202 deletions(-) delete mode 100644 lib/sol2/tests/runtime_tests/source/tables.traversal.cpp (limited to 'lib/sol2/tests/runtime_tests/source/tables.traversal.cpp') 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 - -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()) { - case 0: - REQUIRE((value.as() == "Hi")); - break; - case 1: - REQUIRE((value.as() == 123.45)); - break; - case 2: - REQUIRE((value.as() == "String value")); - break; - case 3: - REQUIRE((value.is())); - break; - } - break; - case sol::type::string: - if (key.as() == "WOOF") { - REQUIRE((value.as() == 123)); - } - break; - case sol::type::lua_nil: - REQUIRE((value.as() == 3)); - break; - default: - break; - } - }; - auto fxpair = [&fx](std::pair 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()) { - case 0: - REQUIRE((value.as() == "Hi")); - break; - case 1: - REQUIRE((value.as() == 123.45)); - break; - case 2: - REQUIRE((value.as() == "String value")); - break; - case 3: - REQUIRE((value.is())); - break; - } - break; - case sol::type::string: - if (key.as() == "WOOF") { - REQUIRE((value.as() == 123)); - } - break; - case sol::type::lua_nil: - REQUIRE((value.as() == 3)); - break; - default: - break; - } - }; - auto fxpair = [&fx](std::pair 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()) { - case 0: - REQUIRE((value.as() == "Hi")); - break; - case 1: - REQUIRE((value.as() == 123.45)); - break; - case 2: - REQUIRE((value.as() == "String value")); - break; - case 3: - REQUIRE((value.is())); - break; - } - break; - case sol::type::string: - if (key.as() == "WOOF") { - REQUIRE((value.as() == 123)); - } - break; - case sol::type::lua_nil: - REQUIRE((value.as() == 3)); - break; - default: - break; - } - }(kvp.first, kvp.second); - } - } - REQUIRE(begintop == endtop); - REQUIRE(iterations == tablesize); -} -- cgit v1.2.3