aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LuaBridge/Tests/Source/IteratorTests.cpp
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-28 00:57:57 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-28 00:57:57 -0400
commit85fb2bff38b2ef6cb17e86c5f602ee09a365b117 (patch)
treea8066d33233ec9b6a2b9bb281a1de040ab96be7b /lib/LuaBridge/Tests/Source/IteratorTests.cpp
parent787393dd86d6c37b5680847dd4eef14406a86687 (diff)
Added LuaBridge support
Diffstat (limited to 'lib/LuaBridge/Tests/Source/IteratorTests.cpp')
-rw-r--r--lib/LuaBridge/Tests/Source/IteratorTests.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/lib/LuaBridge/Tests/Source/IteratorTests.cpp b/lib/LuaBridge/Tests/Source/IteratorTests.cpp
new file mode 100644
index 0000000..d62c068
--- /dev/null
+++ b/lib/LuaBridge/Tests/Source/IteratorTests.cpp
@@ -0,0 +1,96 @@
+// https://github.com/vinniefalco/LuaBridge
+//
+// Copyright 2018, Dmitry Tarakanov
+// SPDX-License-Identifier: MIT
+
+#include "TestBase.h"
+
+#include "LuaBridge/detail/Iterator.h"
+
+struct IteratorTests : TestBase
+{
+};
+
+TEST_F (IteratorTests, DictionaryIteration)
+{
+ runLua (
+ "result = {"
+ " bool = true,"
+ " int = 5,"
+ " c = 3.14,"
+ " [true] = 'D',"
+ " [8] = 'abc',"
+ " fn = function (i)"
+ " result = i + 1"
+ " end"
+ "}");
+
+ std::map <luabridge::LuaRef, luabridge::LuaRef> expected {
+ {{L, "bool"}, {L, true}},
+ {{L, "int"}, {L, 5}},
+ {{L, 'c'}, {L, 3.14}},
+ {{L, true}, {L, 'D'}},
+ {{L, 8}, {L, "abc"}},
+ {{L, "fn"}, {L, result () ["fn"]}},
+ };
+
+ std::map <luabridge::LuaRef, luabridge::LuaRef> actual;
+
+ for (luabridge::Iterator iterator (result ()); !iterator.isNil (); ++iterator)
+ {
+ actual.emplace(iterator.key (), iterator.value ());
+ }
+
+ ASSERT_EQ (expected, actual);
+
+ actual.clear ();
+
+ for (auto&& pair : pairs (result ()))
+ {
+ actual.emplace (pair.first, pair.second);
+ }
+
+ ASSERT_EQ (expected, actual);
+}
+
+TEST_F (IteratorTests, SequenceIteration)
+{
+ runLua (
+ "result = {"
+ " true,"
+ " 5,"
+ " 3.14,"
+ " 'D',"
+ " 'abc',"
+ " function (i)"
+ " result = i + 1"
+ " end"
+ "}");
+
+ std::map <luabridge::LuaRef, luabridge::LuaRef> expected {
+ {{L, 1}, {L, true}},
+ {{L, 2}, {L, 5}},
+ {{L, 3}, {L, 3.14}},
+ {{L, 4}, {L, 'D'}},
+ {{L, 5}, {L, "abc"}},
+ {{L, 6}, {L, result () [6]}},
+ };
+
+ std::map <luabridge::LuaRef, luabridge::LuaRef> actual;
+
+ for (luabridge::Iterator iterator (result ()); !iterator.isNil (); ++iterator)
+ {
+ actual.emplace (iterator.key (), iterator.value ());
+ }
+
+ ASSERT_EQ (expected, actual);
+
+ actual.clear ();
+
+ for (auto&& pair : pairs (result ()))
+ {
+ actual.emplace (pair.first, pair.second);
+ }
+
+ ASSERT_EQ (expected, actual);
+}