ERM_MC.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * ERM_MC.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "../scripting/ScriptFixture.h"
  12. namespace test
  13. {
  14. namespace scripting
  15. {
  16. using namespace ::testing;
  17. class ERM_MC : public Test, public ScriptFixture
  18. {
  19. protected:
  20. void SetUp() override
  21. {
  22. ScriptFixture::setUp();
  23. }
  24. };
  25. TEST_F(ERM_MC, SetNameForVVar)
  26. {
  27. std::stringstream source;
  28. source << "VERM" << std::endl;
  29. source << "!#MCv10:S@test@;" << std::endl;
  30. source << "!?PI;" << std::endl;
  31. source << "!!VR$test$:S42;" << std::endl;
  32. source << "!!VRv11:S$test$ +1;" << std::endl;
  33. const JsonNode actualState = runScript(VLC->scriptHandler->erm, source.str());
  34. SCOPED_TRACE("\n" + subject->code);
  35. const JsonNode & v = actualState["ERM"]["v"];
  36. EXPECT_EQ(v["10"], JsonUtils::floatNode(42)) << actualState.toJson(true);
  37. EXPECT_EQ(v["11"], JsonUtils::floatNode(43)) << actualState.toJson(true);
  38. const JsonNode & m = actualState["ERM"]["MDATA"]["test"];
  39. EXPECT_EQ(m["name"], JsonUtils::stringNode("v")) << actualState.toJson(true);
  40. EXPECT_EQ(m["index"], JsonUtils::stringNode("10")) << actualState.toJson(true);
  41. }
  42. TEST_F(ERM_MC, DeclareNewVariable)
  43. {
  44. std::stringstream source;
  45. source << "VERM" << std::endl;
  46. source << "!#MC:S@test2@;" << std::endl;
  47. source << "!?PI;" << std::endl;
  48. source << "!!VR$test2$:S42;" << std::endl;
  49. source << "!!VRv11:S$test2$ +1;" << std::endl;
  50. const JsonNode actualState = runScript(VLC->scriptHandler->erm, source.str());
  51. SCOPED_TRACE("\n" + subject->code);
  52. const JsonNode & v = actualState["ERM"]["v"];
  53. EXPECT_EQ(v["11"], JsonUtils::floatNode(43)) << actualState.toJson(true);
  54. EXPECT_EQ(v["test2"], JsonUtils::floatNode(42)) << actualState.toJson(true);
  55. const JsonNode & m = actualState["ERM"]["MDATA"]["test2"];
  56. EXPECT_EQ(m["name"], JsonUtils::stringNode("v")) << actualState.toJson(true);
  57. EXPECT_EQ(m["index"], JsonUtils::stringNode("test2")) << actualState.toJson(true);
  58. }
  59. }
  60. }