#include "Parsing/Commands/Sequence/SequenceArchitecture.h" #include "Parsing/Mock/MockLexer.h" #include "Persistence/InMemory/InMemoryRepository.h" #include "Utils/ClassUtils.h" #include #include namespace test::parsing::commands::sequence::sequence_architecture { class CommandsSequenceTestsHelper { public: std::unique_ptr m_repository; std::unique_ptr m_state; std::unique_ptr> m_lexer; unsigned m_consumed_token_count; CommandsSequenceTestsHelper() : m_repository(std::make_unique()), m_state(std::make_unique(m_repository.get())), m_consumed_token_count(0u) { } void Tokens(std::initializer_list> tokens) { m_lexer = std::make_unique>(tokens, CommandsParserValue::EndOfFile(TokenPos())); } bool PerformTest() { REQUIRE(m_lexer); const auto sequence = std::make_unique(); return sequence->MatchSequence(m_lexer.get(), m_state.get(), m_consumed_token_count); } }; TEST_CASE("SequenceArchitecture: Ensure can set x86", "[parsing][sequence]") { CommandsSequenceTestsHelper helper; const TokenPos pos; helper.Tokens({ CommandsParserValue::Identifier(pos, new std::string("architecture")), CommandsParserValue::Identifier(pos, new std::string("x86")), CommandsParserValue::Character(pos, ';'), CommandsParserValue::EndOfFile(pos), }); auto result = helper.PerformTest(); REQUIRE(result); REQUIRE(helper.m_consumed_token_count == 3); REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86); } TEST_CASE("SequenceArchitecture: Ensure can set x64", "[parsing][sequence]") { CommandsSequenceTestsHelper helper; const TokenPos pos; helper.Tokens({ CommandsParserValue::Identifier(pos, new std::string("architecture")), CommandsParserValue::Identifier(pos, new std::string("x86")), CommandsParserValue::Character(pos, ';'), CommandsParserValue::EndOfFile(pos), }); auto result = helper.PerformTest(); REQUIRE(result); REQUIRE(helper.m_consumed_token_count == 3); REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86); } TEST_CASE("SequenceArchitecture: Ensure cannot match unknown value", "[parsing][sequence]") { CommandsSequenceTestsHelper helper; const TokenPos pos; helper.Tokens({ CommandsParserValue::Identifier(pos, new std::string("architecture")), CommandsParserValue::Identifier(pos, new std::string("x1337")), CommandsParserValue::Character(pos, ';'), CommandsParserValue::EndOfFile(pos), }); REQUIRE_THROWS_AS(helper.PerformTest(), ParsingException); REQUIRE(helper.m_repository->GetArchitecture() == Architecture::UNKNOWN); } } // namespace test::parsing::commands::sequence::sequence_architecture