auxiliary.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <catch.hpp>
  2. #include <lua.hpp>
  3. #include <luwra.hpp>
  4. TEST_CASE("equal") {
  5. luwra::StateWrapper state;
  6. REQUIRE(luwra::push(state, 1) == 1);
  7. REQUIRE(luwra::push(state, 2) == 1);
  8. REQUIRE(luwra::push(state, 1) == 1);
  9. REQUIRE(!luwra::equal(state, -1, -2));
  10. REQUIRE(!luwra::equal(state, -2, -1));
  11. REQUIRE(luwra::equal(state, -1, -3));
  12. REQUIRE(luwra::equal(state, -3, -1));
  13. REQUIRE(luwra::equal(state, -3, -3));
  14. REQUIRE(luwra::equal(state, -1, -1));
  15. }
  16. TEST_CASE("setGlobal") {
  17. luwra::StateWrapper state;
  18. luwra::setGlobal(state, "test", 1338);
  19. REQUIRE(luaL_dostring(state, "return test") == LUA_OK);
  20. REQUIRE(luwra::read<int>(state, -1) == 1338);
  21. }
  22. TEST_CASE("getGlobal") {
  23. luwra::StateWrapper state;
  24. REQUIRE(luaL_dostring(state, "test = 1337") == LUA_OK);
  25. REQUIRE(luwra::getGlobal<int>(state, "test") == 1337);
  26. }
  27. TEST_CASE("setFields") {
  28. luwra::StateWrapper state;
  29. lua_newtable(state);
  30. luwra::setFields(
  31. state, -1,
  32. "test", 1338,
  33. 123, 456
  34. );
  35. lua_setglobal(state, "test");
  36. REQUIRE(luaL_dostring(state, "return test.test, test[123]") == LUA_OK);
  37. REQUIRE(luwra::read<int>(state, -2) == 1338);
  38. REQUIRE(luwra::read<int>(state, -1) == 456);
  39. }
  40. TEST_CASE("getField") {
  41. luwra::StateWrapper state;
  42. REQUIRE(luaL_dostring(state, "return {hello = 123}") == LUA_OK);
  43. REQUIRE(luwra::getField<int>(state, -1, "hello") == 123);
  44. }