Skip to content

Commit 048d231

Browse files
committed
Lua tests for item categories
#1200
1 parent 5b42bca commit 048d231

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

trview.app.tests/Lua/Elements/Lua_ItemTests.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ TEST(Lua_Item, Angle)
4040
ASSERT_EQ(123, lua_tointeger(L, -1));
4141
}
4242

43+
TEST(Lua_Item, Categories)
44+
{
45+
auto item = mock_shared<MockItem>();
46+
EXPECT_CALL(*item, categories).WillOnce(Return<std::unordered_set<std::string>>({ "One", "Two" }));
47+
48+
LuaState L;
49+
lua::create_item(L, item);
50+
lua_setglobal(L, "i");
51+
52+
ASSERT_EQ(0, luaL_dostring(L, "return i.categories"));
53+
ASSERT_EQ(LUA_TTABLE, lua_type(L, -1));
54+
ASSERT_EQ(0, luaL_dostring(L, "x = i.categories[1]"));
55+
ASSERT_EQ(LUA_TSTRING, lua_type(L, -1));
56+
ASSERT_EQ("One", lua_tostring(L, -1));
57+
ASSERT_EQ(0, luaL_dostring(L, "x = i.categories[2]"));
58+
ASSERT_EQ(LUA_TSTRING, lua_type(L, -1));
59+
ASSERT_EQ("Two", lua_tostring(L, -1));
60+
}
61+
4362
TEST(Lua_Item, ClearBody)
4463
{
4564
auto item = mock_shared<MockItem>();
@@ -201,6 +220,21 @@ TEST(Lua_Item, Visible)
201220
ASSERT_EQ(true, lua_toboolean(L, -1));
202221
}
203222

223+
TEST(Lua_Item, SetCategories)
224+
{
225+
std::unordered_set<std::string> categories;
226+
auto item = mock_shared<MockItem>();
227+
EXPECT_CALL(*item, set_categories).WillOnce(SaveArg<0>(&categories));
228+
229+
LuaState L;
230+
lua::create_item(L, item);
231+
lua_setglobal(L, "i");
232+
233+
ASSERT_EQ(0, luaL_dostring(L, "i.categories = { \"One\", \"Two\" }"));
234+
235+
const std::unordered_set<std::string> expected{ "One", "Two" };
236+
ASSERT_EQ(categories, expected);
237+
}
204238
TEST(Lua_Item, SetVisible)
205239
{
206240
auto level = mock_shared<MockLevel>();

0 commit comments

Comments
 (0)