summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-01-28 23:06:08 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-02-03 12:55:54 +0100
commitebe5f39bfbb64921d5d31e0a6e49287356a5e6e2 (patch)
tree67f72466337eb422af4a850e4eb4f48e0da330a0 /test
parent8d4967d3a187dd66cf14b070a9db63f8ea21b21f (diff)
patterns: Allow bare words only in arguments
This changes the syntax from approximately expr = unary unary = '!'? primary primary = pattern | short-pattern | word | quoted-word pattern = '?' name [ '(' expr [',' expr]* ')' ] short-pattern = ~ name | ~name expr to: primary = pattern | short-pattern argument = word | quoted-word | expr pattern = '?' name [ '(' argument [',' argument]* ')' ] short-pattern = ~ name | ~name argument
Diffstat (limited to 'test')
-rw-r--r--test/libapt/pattern_test.cc31
1 files changed, 24 insertions, 7 deletions
diff --git a/test/libapt/pattern_test.cc b/test/libapt/pattern_test.cc
index 39959cd31..7fc6a1f8f 100644
--- a/test/libapt/pattern_test.cc
+++ b/test/libapt/pattern_test.cc
@@ -16,19 +16,25 @@ using namespace APT::Internal;
TEST(TreeParserTest, ParseWord)
{
- auto node = PatternTreeParser("word").parseTop();
- auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(node.get());
+ auto node = PatternTreeParser("?word(word)").parseTop();
+ auto patternNode = dynamic_cast<PatternTreeParser::PatternNode *>(node.get());
+
+ ASSERT_EQ(patternNode->arguments.size(), 1u);
+ auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(patternNode->arguments[0].get());
- EXPECT_EQ(node.get(), wordNode);
+ EXPECT_EQ(patternNode->arguments[0].get(), wordNode);
EXPECT_EQ(wordNode->word, "word");
}
TEST(TreeParserTest, ParseQuotedWord)
{
- auto node = PatternTreeParser("\"a word\"").parseTop();
- auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(node.get());
+ auto node = PatternTreeParser("?word(\"a word\")").parseTop();
+ auto patternNode = dynamic_cast<PatternTreeParser::PatternNode *>(node.get());
+
+ ASSERT_EQ(patternNode->arguments.size(), 1u);
+ auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(patternNode->arguments[0].get());
- EXPECT_EQ(node.get(), wordNode);
+ EXPECT_EQ(patternNode->arguments[0].get(), wordNode);
EXPECT_EQ(wordNode->word, "a word");
}
@@ -158,5 +164,16 @@ TEST(TreeParserTest, ParseShortPattern)
EXPECT_PATTERN_EQ_ATOMIC("~U", "?upgradable");
EXPECT_PATTERN_EQ("~Vverstr", "?version(verstr)");
EXPECT_PATTERN_EQ_ATOMIC("~v", "?virtual");
- EXPECT_PATTERN_EQ("!foo", "?not(foo)");
+ EXPECT_PATTERN_EQ("!?foo", "?not(?foo)");
+
+ caught = false;
+ try
+ {
+ PatternTreeParser("!x").parseTop();
+ }
+ catch (PatternTreeParser::Error &e)
+ {
+ caught = true;
+ };
+ EXPECT_TRUE(caught) << "!X should have thrown an exception";
}