mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add tests for table getters.
This commit is contained in:
parent
74e7e504b5
commit
e633c53dc6
1 changed files with 41 additions and 0 deletions
|
@ -712,6 +712,47 @@ TEST_CASE("Reference")
|
|||
CHECK(dtorhits == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("ApiTables")
|
||||
{
|
||||
StateRef globalState(luaL_newstate(), lua_close);
|
||||
lua_State* L = globalState.get();
|
||||
|
||||
lua_newtable(L);
|
||||
lua_pushnumber(L, 123.0);
|
||||
lua_setfield(L, -2, "key");
|
||||
lua_pushstring(L, "test");
|
||||
lua_rawseti(L, -2, 5);
|
||||
|
||||
// lua_gettable
|
||||
lua_pushstring(L, "key");
|
||||
CHECK(lua_gettable(L, -2) == LUA_TNUMBER);
|
||||
CHECK(lua_tonumber(L, -1) == 123.0);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// lua_getfield
|
||||
CHECK(lua_getfield(L, -1, "key") == LUA_TNUMBER);
|
||||
CHECK(lua_tonumber(L, -1) == 123.0);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// lua_rawgetfield
|
||||
CHECK(lua_rawgetfield(L, -1, "key") == LUA_TNUMBER);
|
||||
CHECK(lua_tonumber(L, -1) == 123.0);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// lua_rawget
|
||||
lua_pushstring(L, "key");
|
||||
CHECK(lua_rawget(L, -2) == LUA_TNUMBER);
|
||||
CHECK(lua_tonumber(L, -1) == 123.0);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// lua_rawgeti
|
||||
CHECK(lua_rawgeti(L, -1, 5) == LUA_TSTRING);
|
||||
CHECK(strcmp(lua_tostring(L, -1), "test") == 0);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
TEST_CASE("ApiFunctionCalls")
|
||||
{
|
||||
StateRef globalState = runConformance("apicalls.lua");
|
||||
|
|
Loading…
Add table
Reference in a new issue