From 666ea2be9d3d8105b0f85dfb9bc2925ef3db1fd6 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 30 Mar 2024 20:10:01 +0100 Subject: [PATCH] chore: change tests to reflect new action parsing behaviour --- .../Commands/Sequence/SequenceActionTests.cpp | 73 ++++++++----------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceActionTests.cpp b/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceActionTests.cpp index 2c89f3a0..ef9aeea2 100644 --- a/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceActionTests.cpp +++ b/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceActionTests.cpp @@ -17,11 +17,12 @@ namespace test::parsing::commands::sequence::sequence_action std::unique_ptr m_state; std::unique_ptr> m_lexer; - StructDefinition* m_test_struct_raw; + StructDefinition* m_test_struct_t; StructureInformation* m_test_struct; - StructDefinition* m_test_struct2_raw; - StructureInformation* m_test_struct2; + StructDefinition* m_container_struct_t; + StructureInformation* m_container_struct; + MemberInformation* m_container_struct_child; StructDefinition* m_arg_struct_raw; StructureInformation* m_arg_struct; @@ -37,10 +38,12 @@ namespace test::parsing::commands::sequence::sequence_action private: void RetrieveInformationPointers() { - m_test_struct = m_repository->GetInformationFor(m_test_struct_raw); + m_test_struct = m_repository->GetInformationFor(m_test_struct_t); REQUIRE(m_test_struct != nullptr); - m_test_struct2 = m_repository->GetInformationFor(m_test_struct2_raw); - REQUIRE(m_test_struct2 != nullptr); + m_container_struct = m_repository->GetInformationFor(m_container_struct_t); + REQUIRE(m_container_struct != nullptr); + m_container_struct_child = m_container_struct->m_ordered_members[0].get(); + REQUIRE(m_container_struct_child != nullptr); m_arg_struct = m_repository->GetInformationFor(m_arg_struct_raw); REQUIRE(m_arg_struct != nullptr); m_arg_struct2 = m_repository->GetInformationFor(m_arg_struct2_raw); @@ -61,12 +64,12 @@ namespace test::parsing::commands::sequence::sequence_action { auto def = std::make_unique("", "test_struct_t", 8); def->m_members.emplace_back(std::make_shared("m_test", std::make_unique(BaseTypeDefinition::BOOL))); - m_test_struct_raw = def.get(); + m_test_struct_t = def.get(); m_repository->Add(std::move(def)); def = std::make_unique("", "container_struct_t", 8); - def->m_members.emplace_back(std::make_shared("m_child", std::make_unique(m_test_struct_raw))); - m_test_struct2_raw = def.get(); + def->m_members.emplace_back(std::make_shared("m_child", std::make_unique(m_test_struct_t))); + m_container_struct_t = def.get(); m_repository->Add(std::move(def)); def = std::make_unique("", "arg_t", 8); @@ -91,10 +94,10 @@ namespace test::parsing::commands::sequence::sequence_action CommandsSequenceTestsHelper() : m_repository(std::make_unique()), m_state(std::make_unique(m_repository.get())), - m_test_struct_raw(nullptr), + m_test_struct_t(nullptr), m_test_struct(nullptr), - m_test_struct2_raw(nullptr), - m_test_struct2(nullptr), + m_container_struct_t(nullptr), + m_container_struct(nullptr), m_arg_struct_raw(nullptr), m_arg_struct(nullptr), m_arg_struct2_raw(nullptr), @@ -339,9 +342,11 @@ namespace test::parsing::commands::sequence::sequence_action REQUIRE(result); REQUIRE(helper.m_consumed_token_count == 10); - REQUIRE(helper.m_test_struct->m_post_load_action); - REQUIRE(helper.m_test_struct->m_post_load_action->m_action_name == "TestMethod"); - REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty()); + REQUIRE(helper.m_test_struct->m_post_load_action == nullptr); + + REQUIRE(helper.m_container_struct_child->m_post_load_action); + REQUIRE(helper.m_container_struct_child->m_post_load_action->m_action_name == "TestMethod"); + REQUIRE(helper.m_container_struct_child->m_post_load_action->m_parameter_types.empty()); } TEST_CASE("SequenceAction: Ensure can parse action directive with type from member and in use", "[parsing][sequence]") @@ -358,15 +363,17 @@ namespace test::parsing::commands::sequence::sequence_action CommandsParserValue::Character(pos, ';'), CommandsParserValue::EndOfFile(pos), }); - helper.m_state->SetInUse(helper.m_test_struct2); + helper.m_state->SetInUse(helper.m_container_struct); auto result = helper.PerformTest(); REQUIRE(result); REQUIRE(helper.m_consumed_token_count == 7); - REQUIRE(helper.m_test_struct->m_post_load_action); - REQUIRE(helper.m_test_struct->m_post_load_action->m_action_name == "TestMethod"); - REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty()); + REQUIRE(helper.m_test_struct->m_post_load_action == nullptr); + + REQUIRE(helper.m_container_struct_child->m_post_load_action); + REQUIRE(helper.m_container_struct_child->m_post_load_action->m_action_name == "TestMethod"); + REQUIRE(helper.m_container_struct_child->m_post_load_action->m_parameter_types.empty()); } TEST_CASE("SequenceAction: Ensure can use different struct even though something is used", "[parsing][sequence]") @@ -392,30 +399,10 @@ namespace test::parsing::commands::sequence::sequence_action REQUIRE(result); REQUIRE(helper.m_consumed_token_count == 10); - REQUIRE(helper.m_test_struct->m_post_load_action); - REQUIRE(helper.m_test_struct->m_post_load_action->m_action_name == "TestMethod"); - REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty()); - } - - TEST_CASE("SequenceAction: Ensure member must be type with members", "[parsing][sequence]") - { - CommandsSequenceTestsHelper helper; - const TokenPos pos; - helper.Tokens({ - CommandsParserValue::Identifier(pos, new std::string("set")), - CommandsParserValue::Identifier(pos, new std::string("action")), - CommandsParserValue::Identifier(pos, new std::string("test_struct_t")), - CommandsParserValue::Character(pos, ':'), - CommandsParserValue::Character(pos, ':'), - CommandsParserValue::Identifier(pos, new std::string("m_test")), - CommandsParserValue::Identifier(pos, new std::string("TestMethod")), - CommandsParserValue::Character(pos, '('), - CommandsParserValue::Character(pos, ')'), - CommandsParserValue::Character(pos, ';'), - CommandsParserValue::EndOfFile(pos), - }); - - REQUIRE_THROWS_AS(helper.PerformTest(), ParsingException); REQUIRE(helper.m_test_struct->m_post_load_action == nullptr); + + REQUIRE(helper.m_container_struct_child->m_post_load_action); + REQUIRE(helper.m_container_struct_child->m_post_load_action->m_action_name == "TestMethod"); + REQUIRE(helper.m_container_struct_child->m_post_load_action->m_parameter_types.empty()); } } // namespace test::parsing::commands::sequence::sequence_action