mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Fix menu dvarStrList not working because of String chaining
This commit is contained in:
parent
f8c79d27d0
commit
d2262ebaec
@ -37,6 +37,11 @@ MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Text() const
|
||||
return MatcherFactoryWrapper(Or({StringChain(), Identifier()}));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::TextNoChain() const
|
||||
{
|
||||
return MatcherFactoryWrapper(Or({String(), Identifier()}));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Numeric() const
|
||||
{
|
||||
return MatcherFactoryWrapper(Or({FloatingPoint(), Integer()}));
|
||||
|
@ -20,6 +20,7 @@ namespace menu
|
||||
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> StringChain() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Text() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> TextNoChain() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Numeric() const;
|
||||
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> IntExpression() const;
|
||||
|
@ -362,9 +362,9 @@ namespace menu::item_scope_sequences
|
||||
create.KeywordIgnoreCase("dvarStrList").Capture(CAPTURE_FIRST_TOKEN),
|
||||
create.Char('{'),
|
||||
create.OptionalLoop(create.And({
|
||||
create.Text().Capture(CAPTURE_STEP_NAME),
|
||||
create.TextNoChain().Capture(CAPTURE_STEP_NAME),
|
||||
create.Optional(create.Char(';')),
|
||||
create.Text().Capture(CAPTURE_STEP_VALUE),
|
||||
create.TextNoChain().Capture(CAPTURE_STEP_VALUE),
|
||||
create.Optional(create.Char(';')),
|
||||
})),
|
||||
create.Char('}')
|
||||
|
@ -0,0 +1,91 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/Menu/Sequence/ItemScopeSequences.h"
|
||||
#include "Parsing/Mock/MockLexer.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
namespace test::parsing::menu::sequence::item
|
||||
{
|
||||
class ItemSequenceTestsHelper
|
||||
{
|
||||
public:
|
||||
std::vector<std::unique_ptr<MenuFileParser::sequence_t>> m_all_sequences;
|
||||
std::vector<MenuFileParser::sequence_t*> m_scope_sequences;
|
||||
std::unique_ptr<MenuFileParserState> m_state;
|
||||
std::unique_ptr<ILexer<SimpleParserValue>> m_lexer;
|
||||
|
||||
std::unique_ptr<CommonItemDef> m_item;
|
||||
|
||||
unsigned m_consumed_token_count;
|
||||
|
||||
explicit ItemSequenceTestsHelper(FeatureLevel featureLevel, const bool permissive)
|
||||
: m_state(std::make_unique<MenuFileParserState>(featureLevel, false)),
|
||||
m_item(std::make_unique<CommonItemDef>()),
|
||||
m_consumed_token_count(0u)
|
||||
{
|
||||
ItemScopeSequences scopeSequences(m_all_sequences, m_scope_sequences);
|
||||
scopeSequences.AddSequences(m_state->m_feature_level, permissive);
|
||||
|
||||
m_state->m_current_menu = m_state->m_menus.emplace_back(std::make_unique<CommonMenuDef>()).get();
|
||||
m_state->m_current_item = m_item.get();
|
||||
}
|
||||
|
||||
void Tokens(std::initializer_list<Movable<SimpleParserValue>> tokens)
|
||||
{
|
||||
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()
|
||||
{
|
||||
REQUIRE(m_lexer);
|
||||
|
||||
m_consumed_token_count = 0;
|
||||
for (const auto* sequence : m_scope_sequences)
|
||||
{
|
||||
const auto couldMatch = sequence->MatchSequence(m_lexer.get(), m_state.get(), m_consumed_token_count);
|
||||
if (couldMatch)
|
||||
{
|
||||
m_lexer->PopTokens(static_cast<int>(m_consumed_token_count));
|
||||
return couldMatch;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("ItemScopeSequences: Simple dvarStrList works", "[parsing][sequence][menu]")
|
||||
{
|
||||
ItemSequenceTestsHelper helper(FeatureLevel::IW4, false);
|
||||
const TokenPos pos;
|
||||
helper.Tokens({
|
||||
SimpleParserValue::Identifier(pos, new std::string("dvarStrList")),
|
||||
SimpleParserValue::Character(pos, '{'),
|
||||
SimpleParserValue::String(pos, new std::string("@MENU_AUTO")),
|
||||
SimpleParserValue::String(pos, new std::string("auto")),
|
||||
SimpleParserValue::String(pos, new std::string("@MENU_STANDARD_4_3")),
|
||||
SimpleParserValue::String(pos, new std::string("standard")),
|
||||
SimpleParserValue::String(pos, new std::string("@MENU_WIDE_16_10")),
|
||||
SimpleParserValue::String(pos, new std::string("wide 16:10")),
|
||||
SimpleParserValue::String(pos, new std::string("@MENU_WIDE_16_9")),
|
||||
SimpleParserValue::String(pos, new std::string("wide 16:9")),
|
||||
SimpleParserValue::Character(pos, '}'),
|
||||
SimpleParserValue::EndOfFile(pos)
|
||||
});
|
||||
|
||||
helper.m_item->m_feature_type = CommonItemFeatureType::MULTI_VALUE;
|
||||
helper.m_item->m_multi_value_features = std::make_unique<CommonItemFeaturesMultiValue>();
|
||||
|
||||
const auto result = helper.PerformTest();
|
||||
|
||||
REQUIRE(result);
|
||||
REQUIRE(helper.m_consumed_token_count == 11);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user