Skip to content

Commit 3c6e6da

Browse files
committed
test_scope: Test unnamed classes.
Also test that creating a module inside a table really does not create a global (although it is technically impossible without a string name).
1 parent a8349df commit 3c6e6da

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/test_scope.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,21 @@ struct test_class2 : counted_type<test_class2>
4848
{ return 1; }
4949
};
5050

51+
struct test_class_unnamed : counted_type<test_class_unnamed>
52+
{
53+
test_class_unnamed() {}
54+
int f() { return 42; }
55+
};
56+
57+
test_class_unnamed create_unnamed()
58+
{
59+
return test_class_unnamed();
60+
}
61+
62+
5163
COUNTER_GUARD(test_class);
5264
COUNTER_GUARD(test_class2);
65+
COUNTER_GUARD(test_class_unnamed);
5366

5467
} // namespace unnamed
5568

@@ -92,8 +105,12 @@ void test_main(lua_State* L)
92105
namespace_("inner")
93106
[
94107
def("g", &g_)
95-
]
108+
],
96109

110+
class_<test_class_unnamed>()
111+
.def(constructor<>())
112+
.def("f", &test_class_unnamed::f),
113+
def("create_unnamed", &create_unnamed)
97114
];
98115

99116
module(L, "test")
@@ -131,5 +148,11 @@ void test_main(lua_State* L)
131148

132149
globals(L)["test_object"] = test;
133150

151+
DOSTRING(L, "assert(not inner)");
134152
DOSTRING(L, "assert(test_object.inner.h() == 6)");
153+
154+
DOSTRING(L, "assert(not test_class_unnamed)");
155+
DOSTRING(L,
156+
"u = test.create_unnamed()\n"
157+
"assert(u:f() == 42)");
135158
}

0 commit comments

Comments
 (0)