Skip to content

Commit

Permalink
add test case for eval
Browse files Browse the repository at this point in the history
  • Loading branch information
peacalm committed Jun 25, 2023
1 parent 5936f06 commit 61bfedb
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions test/unit_test/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,65 @@ TEST(eval, tuple) {

{
bool failed;
auto t = l.eval<std::tuple<>>("a=true b=2 c='tuple' ", false, &failed);
auto t =
l.eval<std::tuple<int, int>>("a=true b=2 c='str' ", false, &failed);
EXPECT_EQ(t, std::make_tuple(0, 0));
EXPECT_TRUE(failed);
EXPECT_EQ(l.gettop(), 0);
}
{
bool failed;
auto t = l.eval<std::tuple<int, int>>(
"a=true b=2 c='str'; return b", false, &failed);
EXPECT_EQ(t, std::make_tuple(2, 0));
EXPECT_FALSE(failed);
EXPECT_EQ(l.gettop(), 0);
}
{
bool failed;
auto t = l.eval<std::tuple<int, int>>(
"a=true b=2 c='str'; return nil", false, &failed);
EXPECT_EQ(t, std::make_tuple(0, 0));
EXPECT_FALSE(failed);
EXPECT_EQ(l.gettop(), 0);
}
{
bool failed;
auto t = l.eval<std::tuple<int, int>>(
"a=true b=2 c='str'; return c", false, &failed);
EXPECT_EQ(t, std::make_tuple(0, 0));
EXPECT_TRUE(failed);
EXPECT_EQ(l.gettop(), 0);
}

{
bool failed;
auto t = l.eval<std::tuple<>>("a=true b=2 c='str' ", false, &failed);
EXPECT_EQ(t, std::make_tuple());
EXPECT_FALSE(failed);
EXPECT_EQ(l.gettop(), 0);
}
{
bool failed;
auto t =
l.eval<const std::tuple<>>("a=true b=2 c='tuple' ", false, &failed);
auto t = l.eval<const std::tuple<>>("a=true b=2 c='str' ", false, &failed);
EXPECT_EQ(t, std::make_tuple());
EXPECT_FALSE(failed);
EXPECT_EQ(l.gettop(), 0);
}

{
bool failed;
auto t = l.eval<std::tuple<>>(
"a=true b=2 c='str'; return a, b, c", false, &failed);
EXPECT_EQ(t, std::make_tuple());
EXPECT_FALSE(failed);
EXPECT_EQ(l.gettop(), 0);
}
}

TEST(eval, void) {
luaw l;
l.eval<void>("a=true b=2 c='tuple' ");
l.eval<void>("a=true b=2 c='str' ");
l.eval<void>("return 1");
l.eval<void>("return 1,2,3");
}

0 comments on commit 61bfedb

Please sign in to comment.