Skip to content

Commit

Permalink
Simplify subscript test
Browse files Browse the repository at this point in the history
  • Loading branch information
jteuber committed Feb 5, 2021
1 parent 8129b3e commit e1b5022
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions test/source/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,23 +286,12 @@ TEST_CASE("Documentation Example") {
}

TEST_CASE("Subscript Operators") {
ParserGenerator<std::string> program;
program.setSeparator(program["Whitespace"] << "[\t ]");

ParserGenerator<bool> program;
program["Word"] << "[a-z]+";
program["Yell"] << "[A-Z]+";
program["Number"] << "[0-9]+";
program["IntSubscript"] << "Word Yell? Number" >> [](auto e) { return e[1].string(); };
program["StringSubscriptOptional"] << "Number Yell? Word" >> [](auto e) {
if (auto expr = e["Yell"]) return expr->string();
return std::string();
};
program["Start"] << "IntSubscript | StringSubscriptOptional";

program["Start"] << "Word | Yell" >> [](auto e) { return bool(e["Yell"]); };
program.setStart(program["Start"]);

REQUIRE(program.run("ab 0") == "0");
REQUIRE(program.run("ab CD 1") == "CD");
REQUIRE(program.run("2 ef") == "");
REQUIRE(program.run("2 GH ij") == "GH");
REQUIRE(!program.run("hello"));
REQUIRE(program.run("HELLO"));
}

0 comments on commit e1b5022

Please sign in to comment.