Sfoglia il codice sorgente

test: Add cases for members in auxiliary.hpp

Ole 10 anni fa
parent
commit
9b190a1a29
3 ha cambiato i file con 55 aggiunte e 30 eliminazioni
  1. 1 1
      Makefile
  2. 54 0
      tests/auxiliary.cpp
  3. 0 29
      tests/stack.cpp

+ 1 - 1
Makefile

@@ -6,7 +6,7 @@ EXEC            = exec
 # Test artifacts
 TEST_DIR        := tests
 TEST_OUT        := $(TEST_DIR)/all
-TEST_SRCS       := all.cpp types.cpp stack.cpp functions.cpp usertypes.cpp
+TEST_SRCS       := all.cpp auxiliary.cpp types.cpp stack.cpp functions.cpp usertypes.cpp
 TEST_DEPS       := $(TEST_SRCS:%.cpp=$(TEST_DIR)/%.d)
 TEST_OBJS       := $(TEST_SRCS:%.cpp=$(TEST_DIR)/%.o)
 

+ 54 - 0
tests/auxiliary.cpp

@@ -0,0 +1,54 @@
+#include <catch.hpp>
+
+#include <lua.hpp>
+#include <luwra.hpp>
+
+TEST_CASE("equal") {
+	luwra::StateWrapper state;
+
+	REQUIRE(luwra::push(state, 1) == 1);
+	REQUIRE(luwra::push(state, 2) == 1);
+	REQUIRE(luwra::push(state, 1) == 1);
+
+	REQUIRE(!luwra::equal(state, -1, -2));
+	REQUIRE(!luwra::equal(state, -2, -1));
+
+	REQUIRE(luwra::equal(state, -1, -3));
+	REQUIRE(luwra::equal(state, -3, -1));
+	REQUIRE(luwra::equal(state, -3, -3));
+	REQUIRE(luwra::equal(state, -1, -1));
+}
+
+TEST_CASE("setGlobal") {
+	luwra::StateWrapper state;
+
+	luwra::setGlobal(state, "test", 1338);
+
+	REQUIRE(luaL_dostring(state, "return test") == LUA_OK);
+	REQUIRE(luwra::read<int>(state, -1) == 1338);
+}
+
+TEST_CASE("getGlobal") {
+	luwra::StateWrapper state;
+
+	REQUIRE(luaL_dostring(state, "test = 1337") == LUA_OK);
+	REQUIRE(luwra::getGlobal<int>(state, "test") == 1337);
+}
+
+TEST_CASE("setFields") {
+	luwra::StateWrapper state;
+
+	lua_newtable(state);
+	luwra::setFields(
+		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);
+}
+

+ 0 - 29
tests/stack.cpp

@@ -41,32 +41,3 @@ TEST_CASE("stack_interaction") {
 
 	lua_close(state);
 }
-
-TEST_CASE("stack_setGlobal") {
-	lua_State* state = luaL_newstate();
-
-	luwra::setGlobal(state, "test", 1338);
-
-	REQUIRE(luaL_dostring(state, "return test") == LUA_OK);
-	REQUIRE(luwra::read<int>(state, -1) == 1338);
-
-	lua_close(state);
-}
-
-TEST_CASE("stack_setFields") {
-	lua_State* state = luaL_newstate();
-
-	lua_newtable(state);
-	luwra::setFields(
-		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);
-}