Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
peacalm committed Apr 23, 2023
1 parent ad79b90 commit ffcd2d5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/unit_test/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,29 +1709,37 @@ TEST(lua_wrapper, seek) {
l.settop(0);
l.dostring("g={{1,2,3.0}, {'a', 'b', 'c'}, m={{a=1},{a=2}} }");
EXPECT_EQ(l.gseek("g").seek(1).seek(1).to_int(), 1);
EXPECT_EQ(l.gettop(), 3);
l.settop(0);
EXPECT_EQ(l.gseek("g").seek(1).seek(3).to_int(), 3);
l.settop(0);
EXPECT_EQ(l.gseek("g").seek(1).seek(3).to_string(), "3.0");
EXPECT_EQ(l.gettop(), 3);
l.settop(0);
EXPECT_EQ(l.gseek("g").seek(2).seek(3).to<std::string>(), "c");
l.settop(0);
EXPECT_EQ(l.gseek("g").seek("m").seek(1).seek("a").to_int(), 1);
l.settop(0);
EXPECT_EQ(l.gseek("g").seek("m").seek(2).seek("a").to_int(), 2);
EXPECT_EQ(l.gettop(), 4);

l.settop(0);
EXPECT_EQ(l.gseek("g").seek(1).to<std::vector<int>>(),
(std::vector<int>{1, 2, 3}));
l.settop(0);
EXPECT_EQ(l.gseek("g").seek(1).to<std::vector<std::string>>(),
(std::vector<std::string>{"1", "2", "3.0"}));
EXPECT_EQ(l.gettop(), 2);

l.pop();
EXPECT_EQ(l.gettop(), 1);
EXPECT_EQ((l.seek("m").seek(2).to<std::map<std::string, int>>()),
(std::map<std::string, int>{{"a", 2}}));
EXPECT_EQ(l.gettop(), 3);

l.seek(3);
EXPECT_TRUE(l.isnil());
EXPECT_EQ(l.gettop(), 4);
l.pop();

l.settop(0);
Expand Down

0 comments on commit ffcd2d5

Please sign in to comment.