add unit tests for sequence architecture

This commit is contained in:
Jan
2021-02-19 23:17:53 +01:00
parent 5a7b184aa2
commit e09793818f
3 changed files with 102 additions and 17 deletions

View File

@ -9,27 +9,22 @@ SequenceArchitecture::SequenceArchitecture()
AddMatchers({
create.Keyword("architecture"),
create.Or({
create.Keyword("x86").Tag(TAG_X86),
create.Keyword("x64").Tag(TAG_X64)
}),
create.Identifier().Capture(CAPTURE_ARCHITECTURE),
create.Char(';')
});
m_architecture_mapping["x86"] = Architecture::X86;
m_architecture_mapping["x64"] = Architecture::X64;
}
void SequenceArchitecture::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{
switch (result.NextTag())
{
case TAG_X86:
state->SetArchitecture(Architecture::X86);
break;
const auto& architectureToken = result.NextCapture(CAPTURE_ARCHITECTURE);
case TAG_X64:
state->SetArchitecture(Architecture::X64);
break;
const auto foundArchitecture = m_architecture_mapping.find(architectureToken.IdentifierValue());
default:
throw ParsingException(TokenPos(), "Unknown architecture!");
}
if(foundArchitecture == m_architecture_mapping.end())
throw ParsingException(architectureToken.GetPos(), "Unknown architecture");
state->SetArchitecture(foundArchitecture->second);
}

View File

@ -4,8 +4,9 @@
class SequenceArchitecture final : public CommandsParser::sequence_t
{
static constexpr auto TAG_X86 = 1;
static constexpr auto TAG_X64 = 2;
static constexpr auto CAPTURE_ARCHITECTURE = 1;
std::unordered_map<std::string, Architecture> m_architecture_mapping;
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;