Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
peacalm committed Jun 27, 2023
1 parent 9b50932 commit a1a7035
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/unit_test/register_member.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

struct Obj {
Obj() {}
Obj(int v) : i(v) {}
Obj(int v, int cv = 1) : i(v), ci(cv) {}

int i = 1;
const int ci = 1;
Expand Down Expand Up @@ -66,6 +66,12 @@ TEST(register_member, register_ctor) {
EXPECT_EQ(l.get<int>({"a", "i"}), 2);
EXPECT_EQ(l.get<int>({"a", "ci"}), 1);

// another ctor
l.register_ctor<Obj(int, int)>("NewObj2"); // constructor with 2 argument
EXPECT_EQ(l.dostring("a = NewObj2(4, 5)"), LUA_OK);
EXPECT_EQ(l.eval<int>("return a.i"), 4);
EXPECT_EQ(l.eval<int>("return a.ci"), 5);

// l.register_ctor<Obj>("NewObj"); // error
EXPECT_EQ(l.gettop(), 0);
}
Expand Down

0 comments on commit a1a7035

Please sign in to comment.