From 4de7d379d6872c0733fcb9890c7af8040659720c Mon Sep 17 00:00:00 2001 From: Brandon Forehand Date: Sun, 11 Feb 2018 19:20:19 -0800 Subject: [PATCH 1/2] Add explicit test for wildcard. --- test/test-agent.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test-agent.cpp b/test/test-agent.cpp index 888c657..509cd72 100644 --- a/test/test-agent.cpp +++ b/test/test-agent.cpp @@ -60,6 +60,17 @@ TEST(AgentTest, DisallowNone) EXPECT_TRUE(agent.allowed("/anything")); } +TEST(AgentTest, MiddleWildcard) +{ + Rep::Agent agent = Rep::Agent("a.com").disallow("/test*foo"); + EXPECT_FALSE(agent.allowed("/testfoo")); + EXPECT_FALSE(agent.allowed("/testafoo")); + EXPECT_FALSE(agent.allowed("/testaasdffoo")); + EXPECT_FALSE(agent.allowed("/test/foo")); + EXPECT_TRUE(agent.allowed("/testfo")); + EXPECT_TRUE(agent.allowed("/estfoo")); +} + TEST(AgentTest, EscapedRule) { Rep::Agent agent = Rep::Agent("a.com").disallow("/a%3cd.html"); From 208dbf497d1c4bde3034ebeca6a3d0aafa06ee9c Mon Sep 17 00:00:00 2001 From: Brandon Forehand Date: Sun, 11 Feb 2018 19:39:44 -0800 Subject: [PATCH 2/2] Add leading wildcard tests for Directive. --- test/test-directive.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test-directive.cpp b/test/test-directive.cpp index f94b24d..3de471e 100644 --- a/test/test-directive.cpp +++ b/test/test-directive.cpp @@ -70,6 +70,33 @@ TEST(DirectiveTest, WildcardTest) } } +TEST(DirectiveTest, LeadingWildcard) +{ + std::vector examples = { + "/test", + "/a/test", + "/ab/test", + "/abc/test", + }; + std::string directive("*/test"); + Rep::Directive parsed(directive, true); + for (auto example : examples) + { + EXPECT_TRUE(parsed.match(example)) << + example << " didn't match " << directive; + } + + std::vector antiexamples = { + "/tes", + "/est", + }; + for (auto example : antiexamples) + { + EXPECT_FALSE(parsed.match(example)) << + example << " matched " << directive; + } +} + TEST(DirectiveTest, MultipleWildcardTest) { std::vector examples = {