From 44558c3056cc06cd42c2e566b8094e4ff781bdc3 Mon Sep 17 00:00:00 2001 From: vityaman Date: Tue, 30 Jul 2024 11:02:57 +0300 Subject: [PATCH] #132 Refactor test a little Signed-off-by: vityaman --- ports/cpp/test/cpp14/Cpp14Test.cpp | 49 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/ports/cpp/test/cpp14/Cpp14Test.cpp b/ports/cpp/test/cpp14/Cpp14Test.cpp index 7fa4823..835ad40 100644 --- a/ports/cpp/test/cpp14/Cpp14Test.cpp +++ b/ports/cpp/test/cpp14/Cpp14Test.cpp @@ -196,6 +196,23 @@ TEST(CPP14Parser, SimpleExample) { // NOLINT: complexity CPP14Parser::RulePrimaryexpression, }; + const auto classnameStack = [&] { + auto stack = idexpressionStack; + stack.pop_back(); + stack.emplace_back(CPP14Parser::RuleSimpletypespecifier); + stack.emplace_back(CPP14Parser::RuleNestednamespecifier); + stack.emplace_back(CPP14Parser::RuleTypename); + return stack; + }(); + + const auto namespacenameStack = [&] { + auto stack = idexpressionStack; + stack.pop_back(); + stack.emplace_back(CPP14Parser::RuleSimpletypespecifier); + stack.emplace_back(CPP14Parser::RuleNestednamespecifier); + return stack; + }(); + EXPECT_THAT( Keys(candidates.rules), UnorderedElementsAre( @@ -210,30 +227,14 @@ TEST(CPP14Parser, SimpleExample) { // NOLINT: complexity ElementsAreArray(idexpressionStack) ); - EXPECT_THAT(candidates.rules[CPP14Parser::RuleClassname].ruleList, ElementsAreArray([&] { - auto stack = idexpressionStack; - stack.pop_back(); - for (auto rule : { - CPP14Parser::RuleSimpletypespecifier, - CPP14Parser::RuleNestednamespecifier, - CPP14Parser::RuleTypename, - }) { - stack.emplace_back(rule); - } - return stack; - }())); - - EXPECT_THAT(candidates.rules[CPP14Parser::RuleNamespacename].ruleList, ElementsAreArray([&] { - auto stack = idexpressionStack; - stack.pop_back(); - for (auto rule : { - CPP14Parser::RuleSimpletypespecifier, - CPP14Parser::RuleNestednamespecifier, - }) { - stack.emplace_back(rule); - } - return stack; - }())); + EXPECT_THAT( + candidates.rules[CPP14Parser::RuleClassname].ruleList, ElementsAreArray(classnameStack) + ); + + EXPECT_THAT( + candidates.rules[CPP14Parser::RuleNamespacename].ruleList, + ElementsAreArray(namespacenameStack) + ); } { // 2) Within the method body.