Sfoglia il codice sorgente

tests: Add tests for 'register_global' and 'set_fields'

Ole 10 anni fa
parent
commit
54e6cb6228
1 ha cambiato i file con 29 aggiunte e 0 eliminazioni
  1. 29 0
      tests/stack.cpp

+ 29 - 0
tests/stack.cpp

@@ -41,3 +41,32 @@ TEST_CASE("stack_interaction") {
 
 	lua_close(state);
 }
+
+TEST_CASE("stack_register_global") {
+	lua_State* state = luaL_newstate();
+
+	luwra::register_global(state, "test", 1338);
+
+	REQUIRE(luaL_dostring(state, "return test") == LUA_OK);
+	REQUIRE(luwra::read<int>(state, -1) == 1338);
+
+	lua_close(state);
+}
+
+TEST_CASE("stack_set_fields") {
+	lua_State* state = luaL_newstate();
+
+	lua_newtable(state);
+	luwra::set_fields(
+		state, -1,
+		"test", 1338,
+		123, 456
+	);
+	lua_setglobal(state, "test");
+
+	REQUIRE(luaL_dostring(state, "return test.test, test[123]") == LUA_OK);
+	REQUIRE(luwra::read<int>(state, -2) == 1338);
+	REQUIRE(luwra::read<int>(state, -1) == 456);
+
+	lua_close(state);
+}