tables.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <catch.hpp>
  2. #include <luwra.hpp>
  3. #include <string>
  4. TEST_CASE("Path<Table, string>") {
  5. luwra::StateWrapper state;
  6. REQUIRE(state.runString("value = 1337") == LUA_OK);
  7. luwra::internal::Path<luwra::Table, std::string> path {state, "value"};
  8. REQUIRE(luwra::push(state, path) == 1);
  9. REQUIRE(luwra::read<int>(state, -1) == 1337);
  10. REQUIRE(path.read<int>(state) == 1337);
  11. REQUIRE(lua_gettop(state) == 1);
  12. path.write(state, 13.37);
  13. REQUIRE(luwra::push(state, path) == 1);
  14. REQUIRE(luwra::read<double>(state, -1) == 13.37);
  15. REQUIRE(path.read<double>(state) == 13.37);
  16. REQUIRE(lua_gettop(state) == 2);
  17. }
  18. TEST_CASE("Path<Reference, string>") {
  19. luwra::StateWrapper state;
  20. REQUIRE(state.runString("value = 1337") == LUA_OK);
  21. luwra::internal::Path<luwra::Reference, std::string> path {state.ref, "value"};
  22. REQUIRE(luwra::push(state, path) == 1);
  23. REQUIRE(luwra::read<int>(state, -1) == 1337);
  24. REQUIRE(path.read<int>(state) == 1337);
  25. REQUIRE(lua_gettop(state) == 1);
  26. path.write(state, 13.37);
  27. REQUIRE(luwra::push(state, path) == 1);
  28. REQUIRE(luwra::read<double>(state, -1) == 13.37);
  29. REQUIRE(path.read<double>(state) == 13.37);
  30. REQUIRE(lua_gettop(state) == 2);
  31. }
  32. TEST_CASE("Path<Path<Reference, string>, string>") {
  33. luwra::StateWrapper state;
  34. REQUIRE(state.runString("value = {field = 1337}") == LUA_OK);
  35. luwra::internal::Path<
  36. luwra::internal::Path<
  37. luwra::Reference,
  38. std::string
  39. >,
  40. std::string
  41. > path {{state.ref, "value"}, "field"};
  42. REQUIRE(luwra::push(state, path) == 1);
  43. REQUIRE(luwra::read<int>(state, -1) == 1337);
  44. REQUIRE(path.read<int>(state) == 1337);
  45. REQUIRE(lua_gettop(state) == 1);
  46. path.write(state, 13.37);
  47. REQUIRE(luwra::push(state, path) == 1);
  48. REQUIRE(luwra::read<double>(state, -1) == 13.37);
  49. REQUIRE(path.read<double>(state) == 13.37);
  50. REQUIRE(lua_gettop(state) == 2);
  51. REQUIRE(state.runString("return value.field") == LUA_OK);
  52. REQUIRE(luwra::read<double>(state, -1) == 13.37);
  53. }