Add unit tests for most eventhandlerset script sequences

This commit is contained in:
Jan 2021-11-14 18:17:13 +01:00
parent 252dee03ba
commit 109955b8f2
3 changed files with 833 additions and 26 deletions

View File

@ -29,7 +29,7 @@ namespace menu
{ {
} }
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> ScriptNumeric() const _NODISCARD MatcherFactoryWrapper<SimpleParserValue> ScriptStrictNumeric() const
{ {
return Or({ return Or({
Type(SimpleParserValueType::INTEGER).Transform([](const token_list_t& tokens)-> SimpleParserValue Type(SimpleParserValueType::INTEGER).Transform([](const token_list_t& tokens)-> SimpleParserValue
@ -41,7 +41,14 @@ namespace menu
{ {
const auto& firstToken = tokens[0].get(); const auto& firstToken = tokens[0].get();
return SimpleParserValue::String(firstToken.GetPos(), new std::string(std::to_string(firstToken.FloatingPointValue()))); return SimpleParserValue::String(firstToken.GetPos(), new std::string(std::to_string(firstToken.FloatingPointValue())));
}), })
});
}
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> ScriptNumeric() const
{
return Or({
ScriptStrictNumeric(),
Or({ Or({
Type(SimpleParserValueType::CHARACTER), Type(SimpleParserValueType::CHARACTER),
Type(SimpleParserValueType::STRING), Type(SimpleParserValueType::STRING),
@ -97,10 +104,10 @@ namespace menu
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> ScriptColor() const _NODISCARD MatcherFactoryWrapper<SimpleParserValue> ScriptColor() const
{ {
return And({ return And({
Optional(ScriptNumeric()), ScriptStrictNumeric(),
Optional(ScriptNumeric()), Optional(ScriptStrictNumeric()),
Optional(ScriptNumeric()), Optional(ScriptStrictNumeric()),
Optional(ScriptNumeric()) Optional(ScriptStrictNumeric())
}); });
} }
}; };

View File

@ -1,6 +1,7 @@
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
#include "Parsing/Menu/Domain/EventHandler/CommonEventHandlerScript.h" #include "Parsing/Menu/Domain/EventHandler/CommonEventHandlerScript.h"
#include "Parsing/Menu/Domain/EventHandler/CommonEventHandlerSetLocalVar.h"
#include "Utils/ClassUtils.h" #include "Utils/ClassUtils.h"
#include "Parsing/Menu/Sequence/EventHandlerSetScopeSequences.h" #include "Parsing/Menu/Sequence/EventHandlerSetScopeSequences.h"
#include "Parsing/Mock/MockLexer.h" #include "Parsing/Mock/MockLexer.h"
@ -39,6 +40,11 @@ namespace test::parsing::menu::sequence::event_handler_set
m_lexer = std::make_unique<MockLexer<SimpleParserValue>>(tokens, SimpleParserValue::EndOfFile(TokenPos())); m_lexer = std::make_unique<MockLexer<SimpleParserValue>>(tokens, SimpleParserValue::EndOfFile(TokenPos()));
} }
void Tokens(std::vector<SimpleParserValue> tokens)
{
m_lexer = std::make_unique<MockLexer<SimpleParserValue>>(std::move(tokens), SimpleParserValue::EndOfFile(TokenPos()));
}
bool PerformTest() bool PerformTest()
{ {
REQUIRE(m_lexer); REQUIRE(m_lexer);
@ -55,26 +61,7 @@ namespace test::parsing::menu::sequence::event_handler_set
} }
}; };
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use fadeIn", "[parsing][sequence][menu]") #pragma region General
{
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
const TokenPos pos;
helper.Tokens({
SimpleParserValue::Identifier(pos, new std::string("fadeIn")),
SimpleParserValue::String(pos, new std::string("some_element")),
SimpleParserValue::Character(pos, ';'),
SimpleParserValue::EndOfFile(pos)
});
const auto result = helper.PerformTest();
REQUIRE(result);
REQUIRE(helper.m_consumed_token_count == 3);
const auto script = helper.m_state->m_current_script.str();
REQUIRE(script == R"("fadeIn" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Keyword casing doesnt matter", "[parsing][sequence][menu]") TEST_CASE("EventHandlerSetScopeSequences: Keyword casing doesnt matter", "[parsing][sequence][menu]")
{ {
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4); EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
@ -112,6 +99,810 @@ namespace test::parsing::menu::sequence::event_handler_set
REQUIRE(helper.m_consumed_token_count == 0); REQUIRE(helper.m_consumed_token_count == 0);
} }
#pragma endregion
void TestGenericScriptStatement(const std::initializer_list<Movable<SimpleParserValue>> tokens, const std::string& expectedScript)
{
std::vector<SimpleParserValue> tokenList(std::make_move_iterator(tokens.begin()), std::make_move_iterator(tokens.end()));
const auto initialValueCount = tokenList.size();
tokenList.emplace_back(SimpleParserValue::Character(TokenPos(), ';'));
tokenList.emplace_back(SimpleParserValue::EndOfFile(TokenPos()));
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
helper.Tokens(std::move(tokenList));
const auto result = helper.PerformTest();
REQUIRE(result);
REQUIRE(helper.m_consumed_token_count == initialValueCount + 1);
const auto script = helper.m_state->m_current_script.str();
REQUIRE(script == expectedScript);
}
#pragma region Command Tests
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use fadeIn", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("fadeIn")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("fadeIn" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use fadeOut", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("fadeOut")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("fadeOut" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use show", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("show")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("show" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use hide", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("hide")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("hide" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use showMenu", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("showMenu")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("showMenu" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use hideMenu", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("hideMenu")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("hideMenu" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setColor", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setColor")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
}, R"("setColor" "1" "1" "1" "1" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setColor with 3 colors", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setColor")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
}, R"("setColor" "1" "1" "1" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setColor with 2 colors", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setColor")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
}, R"("setColor" "1" "1" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setColor with 1 color", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setColor")),
SimpleParserValue::Integer(TokenPos(), 1),
}, R"("setColor" "1" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure cannot use setColor with no color", "[parsing][sequence][menu]")
{
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
const TokenPos pos;
helper.Tokens({
SimpleParserValue::Identifier(pos, new std::string("setColor")),
SimpleParserValue::Character(pos, ';'),
SimpleParserValue::EndOfFile(pos)
});
const auto result = helper.PerformTest();
REQUIRE(result == false);
REQUIRE(helper.m_consumed_token_count == 0);
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use open", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("open")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("open" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use close", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("close")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("close" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use escape", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("escape")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("escape" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use closeForAllPlayers", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("closeForAllPlayers")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("closeForAllPlayers" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use ingameOpen", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("ingameOpen")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("ingameOpen" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use ingameClose", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("ingameClose")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("ingameClose" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setBackground", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setBackground")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("setBackground" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setItemColor with forecolor", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setItemColor")),
SimpleParserValue::String(TokenPos(), new std::string("some_element")),
SimpleParserValue::String(TokenPos(), new std::string("forecolor")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
}, R"("setItemColor" "some_element" "forecolor" "1" "1" "1" "1" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setItemColor with backcolor", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setItemColor")),
SimpleParserValue::String(TokenPos(), new std::string("some_element")),
SimpleParserValue::String(TokenPos(), new std::string("backcolor")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
}, R"("setItemColor" "some_element" "backcolor" "1" "1" "1" "1" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setItemColor with bordercolor", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setItemColor")),
SimpleParserValue::String(TokenPos(), new std::string("some_element")),
SimpleParserValue::String(TokenPos(), new std::string("bordercolor")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Integer(TokenPos(), 1),
}, R"("setItemColor" "some_element" "bordercolor" "1" "1" "1" "1" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use focusFirst", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("focusFirst")),
}, R"("focusFirst" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setFocus", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setFocus")),
SimpleParserValue::String(TokenPos(), new std::string("some_element"))
}, R"("setFocus" "some_element" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setFocusByDvar", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setFocusByDvar")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar"))
}, R"("setFocusByDvar" "some_dvar" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setDvar", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setDvar")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::String(TokenPos(), new std::string("some_value")),
}, R"("setDvar" "some_dvar" "some_value" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use exec", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("exec")),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("exec" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use execNow", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("execNow")),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("execNow" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use execOnDvarStringValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("execOnDvarStringValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::String(TokenPos(), new std::string("some_value")),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("execOnDvarStringValue" "some_dvar" "some_value" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use execOnDvarIntValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("execOnDvarIntValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("execOnDvarIntValue" "some_dvar" "1" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use execOnDvarFloatValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("execOnDvarFloatValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("execOnDvarFloatValue" "some_dvar" "1" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use execNowOnDvarStringValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("execNowOnDvarStringValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::String(TokenPos(), new std::string("some_value")),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("execNowOnDvarStringValue" "some_dvar" "some_value" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use execNowOnDvarIntValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("execNowOnDvarIntValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("execNowOnDvarIntValue" "some_dvar" "1" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use execNowOnDvarFloatValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("execNowOnDvarFloatValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::String(TokenPos(), new std::string("some_command"))
}, R"("execNowOnDvarFloatValue" "some_dvar" "1" "some_command" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use play", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("play")),
SimpleParserValue::String(TokenPos(), new std::string("some_sound"))
}, R"("play" "some_sound" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use scriptMenuResponse", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("scriptMenuResponse")),
SimpleParserValue::String(TokenPos(), new std::string("some_response"))
}, R"("scriptMenuResponse" "some_response" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use respondOnDvarStringValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("respondOnDvarStringValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::String(TokenPos(), new std::string("some_value")),
SimpleParserValue::String(TokenPos(), new std::string("some_response"))
}, R"("respondOnDvarStringValue" "some_dvar" "some_value" "some_response" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use respondOnDvarIntValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("respondOnDvarIntValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::String(TokenPos(), new std::string("some_response"))
}, R"("respondOnDvarIntValue" "some_dvar" "1" "some_response" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use respondOnDvarFloatValue", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("respondOnDvarFloatValue")),
SimpleParserValue::String(TokenPos(), new std::string("some_dvar")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::String(TokenPos(), new std::string("some_response"))
}, R"("respondOnDvarFloatValue" "some_dvar" "1" "some_response" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setPlayerDataSp", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setPlayerDataSp"))
}, R"("setPlayerDataSp" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use updateMail", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("updateMail"))
}, R"("updateMail" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use openMail", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("openMail"))
}, R"("openMail" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use deleteMail", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("deleteMail"))
}, R"("deleteMail" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use doMailLottery", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("doMailLottery"))
}, R"("doMailLottery" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use resetStatsConfirm", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("resetStatsConfirm"))
}, R"("resetStatsConfirm" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use resetStatsCancel", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("resetStatsCancel"))
}, R"("resetStatsCancel" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use setGameMode", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setGameMode")),
SimpleParserValue::String(TokenPos(), new std::string("some_game_mode"))
}, R"("setGameMode" "some_game_mode" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use feederTop", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("feederTop"))
}, R"("feederTop" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use feederBottom", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("feederBottom"))
}, R"("feederBottom" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use showGamerCard", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("showGamerCard"))
}, R"("showGamerCard" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use openForGameType", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("openForGameType")),
SimpleParserValue::String(TokenPos(), new std::string("some_game_type"))
}, R"("openForGameType" "some_game_type" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use closeForGameType", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("closeForGameType")),
SimpleParserValue::String(TokenPos(), new std::string("some_game_type"))
}, R"("closeForGameType" "some_game_type" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use kickPlayer", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("kickPlayer"))
}, R"("kickPlayer" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use getKickPlayerQuestion", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("getKickPlayerQuestion"))
}, R"("getKickPlayerQuestion" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use partyUpdateMissingMapPackDvar", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("partyUpdateMissingMapPackDvar"))
}, R"("partyUpdateMissingMapPackDvar" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use togglePlayerMute", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("togglePlayerMute"))
}, R"("togglePlayerMute" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use resolveError", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("resolveError"))
}, R"("resolveError" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use lerp scale", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("lerp")),
SimpleParserValue::Identifier(TokenPos(), new std::string("scale")),
SimpleParserValue::Identifier(TokenPos(), new std::string("from")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Identifier(TokenPos(), new std::string("to")),
SimpleParserValue::Integer(TokenPos(), 2),
SimpleParserValue::Identifier(TokenPos(), new std::string("over")),
SimpleParserValue::Integer(TokenPos(), 3),
}, R"("lerp" "scale" "from" "1" "to" "2" "over" "3" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use lerp alpha", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("lerp")),
SimpleParserValue::Identifier(TokenPos(), new std::string("alpha")),
SimpleParserValue::Identifier(TokenPos(), new std::string("from")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Identifier(TokenPos(), new std::string("to")),
SimpleParserValue::Integer(TokenPos(), 2),
SimpleParserValue::Identifier(TokenPos(), new std::string("over")),
SimpleParserValue::Integer(TokenPos(), 3),
}, R"("lerp" "alpha" "from" "1" "to" "2" "over" "3" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use lerp x", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("lerp")),
SimpleParserValue::Identifier(TokenPos(), new std::string("x")),
SimpleParserValue::Identifier(TokenPos(), new std::string("from")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Identifier(TokenPos(), new std::string("to")),
SimpleParserValue::Integer(TokenPos(), 2),
SimpleParserValue::Identifier(TokenPos(), new std::string("over")),
SimpleParserValue::Integer(TokenPos(), 3),
}, R"("lerp" "x" "from" "1" "to" "2" "over" "3" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure can use lerp y", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("lerp")),
SimpleParserValue::Identifier(TokenPos(), new std::string("y")),
SimpleParserValue::Identifier(TokenPos(), new std::string("from")),
SimpleParserValue::Integer(TokenPos(), 1),
SimpleParserValue::Identifier(TokenPos(), new std::string("to")),
SimpleParserValue::Integer(TokenPos(), 2),
SimpleParserValue::Identifier(TokenPos(), new std::string("over")),
SimpleParserValue::Integer(TokenPos(), 3),
}, R"("lerp" "y" "from" "1" "to" "2" "over" "3" ; )");
}
#pragma endregion
#pragma region Unit Tests for setLocalVar
TEST_CASE("EventHandlerSetScopeSequences: Ensure setLocalVarBool is script on static value", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setLocalVarBool")),
SimpleParserValue::Identifier(TokenPos(), new std::string("sample_var")),
SimpleParserValue::Integer(TokenPos(), 1339),
SimpleParserValue::Character(TokenPos(), '-'),
SimpleParserValue::Integer(TokenPos(), 2),
}, R"("setLocalVarBool" "sample_var" "1337" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure setLocalVarInt is script on static value", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setLocalVarInt")),
SimpleParserValue::Identifier(TokenPos(), new std::string("sample_var")),
SimpleParserValue::Integer(TokenPos(), 1339),
SimpleParserValue::Character(TokenPos(), '-'),
SimpleParserValue::Integer(TokenPos(), 2),
}, R"("setLocalVarInt" "sample_var" "1337" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure setLocalVarString is script on static value", "[parsing][sequence][menu]")
{
TestGenericScriptStatement(
{
SimpleParserValue::Identifier(TokenPos(), new std::string("setLocalVarString")),
SimpleParserValue::Identifier(TokenPos(), new std::string("sample_var")),
SimpleParserValue::String(TokenPos(), new std::string("Hello")),
SimpleParserValue::Character(TokenPos(), '+'),
SimpleParserValue::String(TokenPos(), new std::string(" ")),
SimpleParserValue::Character(TokenPos(), '+'),
SimpleParserValue::String(TokenPos(), new std::string("World")),
}, R"("setLocalVarString" "sample_var" "Hello World" ; )");
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure setLocalVarBool is setLocalVar handler on non-static value", "[parsing][sequence][menu]")
{
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
const TokenPos pos;
helper.Tokens({
SimpleParserValue::Identifier(TokenPos(), new std::string("setLocalVarBool")),
SimpleParserValue::Identifier(TokenPos(), new std::string("sample_var")),
SimpleParserValue::Identifier(TokenPos(), new std::string("milliseconds")),
SimpleParserValue::Character(TokenPos(), '('),
SimpleParserValue::Character(TokenPos(), ')'),
SimpleParserValue::Character(TokenPos(), '%'),
SimpleParserValue::Integer(TokenPos(), 2),
SimpleParserValue::Character(TokenPos(), ';'),
SimpleParserValue::EndOfFile(pos)
});
const auto result = helper.PerformTest();
REQUIRE(result);
REQUIRE(helper.m_consumed_token_count == 8);
REQUIRE(helper.m_event_handler_set->m_elements.size() == 1);
const auto* firstElement = helper.m_event_handler_set->m_elements[0].get();
REQUIRE(firstElement->GetType() == CommonEventHandlerElementType::SET_LOCAL_VAR);
const auto* setLocalVarElement = dynamic_cast<const CommonEventHandlerSetLocalVar*>(firstElement);
REQUIRE(setLocalVarElement != nullptr);
REQUIRE(setLocalVarElement->m_type == SetLocalVarType::BOOL);
REQUIRE(setLocalVarElement->m_var_name == "sample_var");
REQUIRE(setLocalVarElement->m_value);
REQUIRE(setLocalVarElement->m_value->IsStatic() == false);
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure setLocalVarInt is setLocalVar handler on non-static value", "[parsing][sequence][menu]")
{
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
const TokenPos pos;
helper.Tokens({
SimpleParserValue::Identifier(TokenPos(), new std::string("setLocalVarInt")),
SimpleParserValue::Identifier(TokenPos(), new std::string("sample_var")),
SimpleParserValue::Identifier(TokenPos(), new std::string("milliseconds")),
SimpleParserValue::Character(TokenPos(), '('),
SimpleParserValue::Character(TokenPos(), ')'),
SimpleParserValue::Character(TokenPos(), '*'),
SimpleParserValue::Integer(TokenPos(), 2),
SimpleParserValue::Character(TokenPos(), ';'),
SimpleParserValue::EndOfFile(pos)
});
const auto result = helper.PerformTest();
REQUIRE(result);
REQUIRE(helper.m_consumed_token_count == 8);
REQUIRE(helper.m_event_handler_set->m_elements.size() == 1);
const auto* firstElement = helper.m_event_handler_set->m_elements[0].get();
REQUIRE(firstElement->GetType() == CommonEventHandlerElementType::SET_LOCAL_VAR);
const auto* setLocalVarElement = dynamic_cast<const CommonEventHandlerSetLocalVar*>(firstElement);
REQUIRE(setLocalVarElement != nullptr);
REQUIRE(setLocalVarElement->m_type == SetLocalVarType::INT);
REQUIRE(setLocalVarElement->m_var_name == "sample_var");
REQUIRE(setLocalVarElement->m_value);
REQUIRE(setLocalVarElement->m_value->IsStatic() == false);
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure setLocalVarFloat is setLocalVar handler on non-static value", "[parsing][sequence][menu]")
{
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
const TokenPos pos;
helper.Tokens({
SimpleParserValue::Identifier(TokenPos(), new std::string("setLocalVarFloat")),
SimpleParserValue::Identifier(TokenPos(), new std::string("sample_var")),
SimpleParserValue::Identifier(TokenPos(), new std::string("milliseconds")),
SimpleParserValue::Character(TokenPos(), '('),
SimpleParserValue::Character(TokenPos(), ')'),
SimpleParserValue::Character(TokenPos(), '/'),
SimpleParserValue::Integer(TokenPos(), 2),
SimpleParserValue::Character(TokenPos(), ';'),
SimpleParserValue::EndOfFile(pos)
});
const auto result = helper.PerformTest();
REQUIRE(result);
REQUIRE(helper.m_consumed_token_count == 8);
REQUIRE(helper.m_event_handler_set->m_elements.size() == 1);
const auto* firstElement = helper.m_event_handler_set->m_elements[0].get();
REQUIRE(firstElement->GetType() == CommonEventHandlerElementType::SET_LOCAL_VAR);
const auto* setLocalVarElement = dynamic_cast<const CommonEventHandlerSetLocalVar*>(firstElement);
REQUIRE(setLocalVarElement != nullptr);
REQUIRE(setLocalVarElement->m_type == SetLocalVarType::FLOAT);
REQUIRE(setLocalVarElement->m_var_name == "sample_var");
REQUIRE(setLocalVarElement->m_value);
REQUIRE(setLocalVarElement->m_value->IsStatic() == false);
}
TEST_CASE("EventHandlerSetScopeSequences: Ensure setLocalVarString is setLocalVar handler on non-static value", "[parsing][sequence][menu]")
{
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
const TokenPos pos;
helper.Tokens({
SimpleParserValue::Identifier(TokenPos(), new std::string("setLocalVarString")),
SimpleParserValue::Identifier(TokenPos(), new std::string("sample_var")),
SimpleParserValue::Identifier(TokenPos(), new std::string("milliseconds")),
SimpleParserValue::Character(TokenPos(), '('),
SimpleParserValue::Character(TokenPos(), ')'),
SimpleParserValue::Character(TokenPos(), '+'),
SimpleParserValue::String(TokenPos(), new std::string(" Hello")),
SimpleParserValue::Character(TokenPos(), ';'),
SimpleParserValue::EndOfFile(pos)
});
const auto result = helper.PerformTest();
REQUIRE(result);
REQUIRE(helper.m_consumed_token_count == 8);
REQUIRE(helper.m_event_handler_set->m_elements.size() == 1);
const auto* firstElement = helper.m_event_handler_set->m_elements[0].get();
REQUIRE(firstElement->GetType() == CommonEventHandlerElementType::SET_LOCAL_VAR);
const auto* setLocalVarElement = dynamic_cast<const CommonEventHandlerSetLocalVar*>(firstElement);
REQUIRE(setLocalVarElement != nullptr);
REQUIRE(setLocalVarElement->m_type == SetLocalVarType::STRING);
REQUIRE(setLocalVarElement->m_var_name == "sample_var");
REQUIRE(setLocalVarElement->m_value);
REQUIRE(setLocalVarElement->m_value->IsStatic() == false);
}
#pragma endregion
#pragma region Unit Tests for If/ElseIf/Else/CloseBracket
TEST_CASE("EventHandlerSetScopeSequences: Closing block terminates EventHandlerSet", "[parsing][sequence][menu]") TEST_CASE("EventHandlerSetScopeSequences: Closing block terminates EventHandlerSet", "[parsing][sequence][menu]")
{ {
EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4); EventHandlerSetSequenceTestsHelper helper(FeatureLevel::IW4);
@ -626,4 +1417,6 @@ namespace test::parsing::menu::sequence::event_handler_set
REQUIRE(helper.m_state->m_current_nested_event_handler_set == helper.m_event_handler_set.get()); REQUIRE(helper.m_state->m_current_nested_event_handler_set == helper.m_event_handler_set.get());
REQUIRE(helper.m_state->m_condition_stack.empty()); REQUIRE(helper.m_state->m_condition_stack.empty());
} }
#pragma endregion
} }

View File

@ -24,6 +24,13 @@ public:
{ {
} }
MockLexer(std::vector<TokenType> tokens, TokenType eof)
: m_tokens(std::move(tokens)),
m_eof(std::move(eof)),
m_pop_count(0)
{
}
~MockLexer() override = default; ~MockLexer() override = default;
MockLexer(const MockLexer& other) = delete; MockLexer(const MockLexer& other) = delete;
MockLexer(MockLexer&& other) noexcept = default; MockLexer(MockLexer&& other) noexcept = default;