mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
add unit tests for game
This commit is contained in:
parent
e09793818f
commit
42851bcaf8
@ -122,7 +122,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can parse simple action directive", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can parse simple action directive", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -146,7 +146,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can parse simple action directive with one arg", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can parse simple action directive with one arg", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -172,7 +172,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types[0] == helper.m_arg_struct_raw);
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types[0] == helper.m_arg_struct_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can parse simple action directive with two args", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can parse simple action directive with two args", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -201,7 +201,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types[1] == helper.m_arg_struct2_raw);
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types[1] == helper.m_arg_struct2_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can parse simple action directive with three args", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can parse simple action directive with three args", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -233,7 +233,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types[2] == helper.m_arg_struct3_raw);
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types[2] == helper.m_arg_struct3_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Fails if base typename does not exist", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Fails if base typename does not exist", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -252,7 +252,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action == nullptr);
|
REQUIRE(helper.m_test_struct->m_post_load_action == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Fails if arg typename does not exist", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Fails if arg typename does not exist", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -276,7 +276,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action == nullptr);
|
REQUIRE(helper.m_test_struct->m_post_load_action == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Fails if no type and no use", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Fails if no type and no use", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -294,7 +294,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action == nullptr);
|
REQUIRE(helper.m_test_struct->m_post_load_action == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can parse action directive with used type", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can parse action directive with used type", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -318,7 +318,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can parse action directive with type from member", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can parse action directive with type from member", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -345,7 +345,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can parse action directive with type from member and in use", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can parse action directive with type from member and in use", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -370,7 +370,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can use different struct even though something is used", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure can use different struct even though something is used", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -398,7 +398,7 @@ namespace test::parsing::commands::sequence::sequence_action
|
|||||||
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
REQUIRE(helper.m_test_struct->m_post_load_action->m_parameter_types.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure member must be type with members", "[parsing][parsingstream]")
|
TEST_CASE("SequenceAction: Ensure member must be type with members", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
|
@ -36,7 +36,7 @@ namespace test::parsing::commands::sequence::sequence_architecture
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can set x86", "[parsing][parsingstream]")
|
TEST_CASE("SequenceArchitecture: Ensure can set x86", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -54,7 +54,7 @@ namespace test::parsing::commands::sequence::sequence_architecture
|
|||||||
REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86);
|
REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure can set x64", "[parsing][parsingstream]")
|
TEST_CASE("SequenceArchitecture: Ensure can set x64", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
@ -72,7 +72,7 @@ namespace test::parsing::commands::sequence::sequence_architecture
|
|||||||
REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86);
|
REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SequenceAction: Ensure cannot match unknown value", "[parsing][parsingstream]")
|
TEST_CASE("SequenceArchitecture: Ensure cannot match unknown value", "[parsing][sequence]")
|
||||||
{
|
{
|
||||||
CommandsSequenceTestsHelper helper;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
|
#include "Parsing/Commands/Sequence/SequenceGame.h"
|
||||||
|
#include "Parsing/Mock/MockLexer.h"
|
||||||
|
#include "Persistence/InMemory/InMemoryRepository.h"
|
||||||
|
|
||||||
|
namespace test::parsing::commands::sequence::sequence_game
|
||||||
|
{
|
||||||
|
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<SequenceGame>();
|
||||||
|
return sequence->MatchSequence(m_lexer.get(), m_state.get(), m_consumed_token_count);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_CASE("SequenceGame: Ensure can set game", "[parsing][sequence]")
|
||||||
|
{
|
||||||
|
CommandsSequenceTestsHelper helper;
|
||||||
|
const TokenPos pos;
|
||||||
|
helper.Tokens({
|
||||||
|
CommandsParserValue::Identifier(pos, new std::string("game")),
|
||||||
|
CommandsParserValue::Identifier(pos, new std::string("very_cool_game")),
|
||||||
|
CommandsParserValue::Character(pos, ';'),
|
||||||
|
CommandsParserValue::EndOfFile(pos)
|
||||||
|
});
|
||||||
|
|
||||||
|
auto result = helper.PerformTest();
|
||||||
|
|
||||||
|
REQUIRE(result);
|
||||||
|
REQUIRE(helper.m_consumed_token_count == 3);
|
||||||
|
REQUIRE(helper.m_repository->GetGameName() == "very_cool_game");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user