mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-09 22:38:06 -05:00
add unit tests for sequence architecture
This commit is contained in:
@ -0,0 +1,89 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceArchitecture.h"
|
||||
#include "Parsing/Mock/MockLexer.h"
|
||||
#include "Persistence/InMemory/InMemoryRepository.h"
|
||||
|
||||
namespace test::parsing::commands::sequence::sequence_architecture
|
||||
{
|
||||
class CommandsSequenceTestsHelper
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<IDataRepository> m_repository;
|
||||
std::unique_ptr<CommandsParserState> m_state;
|
||||
std::unique_ptr<ILexer<CommandsParserValue>> m_lexer;
|
||||
|
||||
unsigned m_consumed_token_count;
|
||||
|
||||
CommandsSequenceTestsHelper()
|
||||
: m_repository(std::make_unique<InMemoryRepository>()),
|
||||
m_state(std::make_unique<CommandsParserState>(m_repository.get())),
|
||||
m_consumed_token_count(0u)
|
||||
{
|
||||
}
|
||||
|
||||
void Tokens(std::initializer_list<Movable<CommandsParserValue>> tokens)
|
||||
{
|
||||
m_lexer = std::make_unique<MockLexer<CommandsParserValue>>(tokens, CommandsParserValue::EndOfFile(TokenPos()));
|
||||
}
|
||||
|
||||
bool PerformTest()
|
||||
{
|
||||
REQUIRE(m_lexer);
|
||||
const auto sequence = std::make_unique<SequenceArchitecture>();
|
||||
return sequence->MatchSequence(m_lexer.get(), m_state.get(), m_consumed_token_count);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("SequenceAction: Ensure can set x86", "[parsing][parsingstream]")
|
||||
{
|
||||
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("SequenceAction: Ensure can set x64", "[parsing][parsingstream]")
|
||||
{
|
||||
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("SequenceAction: Ensure cannot match unknown value", "[parsing][parsingstream]")
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user