summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/sol2/test_containers.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-11-06 10:05:36 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2016-11-06 10:05:36 +0100
commitc2a75cb1799a31aa5687e576d1c0bdd50825fded (patch)
tree59144f444d666ae20ac8fb2bc4e4553d330945ca /3rdparty/sol2/test_containers.cpp
parentfffd464d345a6368cda7d90945d3409151218a06 (diff)
Updated sol2, made lua console not crash for nil data (nw)
Diffstat (limited to '3rdparty/sol2/test_containers.cpp')
-rw-r--r--3rdparty/sol2/test_containers.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/3rdparty/sol2/test_containers.cpp b/3rdparty/sol2/test_containers.cpp
index 015fbd20db0..d43db52d4b4 100644
--- a/3rdparty/sol2/test_containers.cpp
+++ b/3rdparty/sol2/test_containers.cpp
@@ -273,6 +273,57 @@ TEST_CASE("containers/arbitrary-creation", "userdata and tables should be usable
REQUIRE(c.get<std::string>("project") == "sol");
}
+TEST_CASE("containers/extra-functions", "make sure the manipulation functions are present and usable and working across various container types") {
+ sol::state lua;
+ lua.open_libraries();
+
+ lua.script(R"(
+function g (x)
+ x:add(20)
+end
+
+function h (x)
+ x:add(20, 40)
+end
+
+function i (x)
+ x:clear()
+end
+)");
+
+ // Have the function we
+ // just defined in Lua
+ sol::function g = lua["g"];
+ sol::function h = lua["h"];
+ sol::function i = lua["i"];
+
+ // Set a global variable called
+ // "arr" to be a vector of 5 lements
+ lua["arr"] = std::vector<int>{ 2, 4, 6, 8, 10 };
+ lua["map"] = std::map<int, int>{ { 1 , 2 },{ 2, 4 },{ 3, 6 },{ 4, 8 },{ 5, 10 } };
+ lua["set"] = std::set<int>{ 2, 4, 6, 8, 10 };
+ std::vector<int>& arr = lua["arr"];
+ std::map<int, int>& map = lua["map"];
+ std::set<int>& set = lua["set"];
+ REQUIRE(arr.size() == 5);
+ REQUIRE(map.size() == 5);
+ REQUIRE(set.size() == 5);
+
+ g(lua["set"]);
+ g(lua["arr"]);
+ h(lua["map"]);
+ REQUIRE(arr.size() == 6);
+ REQUIRE(map.size() == 6);
+ REQUIRE(set.size() == 6);
+
+ i(lua["arr"]);
+ i(lua["map"]);
+ i(lua["set"]);
+ REQUIRE(arr.empty());
+ REQUIRE(map.empty());
+ REQUIRE(set.empty());
+}
+
TEST_CASE("containers/usertype-transparency", "Make sure containers pass their arguments through transparently and push the results as references, not new values") {
class A {
public: