Skip to content

Commit

Permalink
Merge pull request #35 from seomoz/wildcard-tests
Browse files Browse the repository at this point in the history
More wildcard tests
  • Loading branch information
b4hand committed Feb 12, 2018
2 parents 713577a + 208dbf4 commit a2f304e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/test-agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
27 changes: 27 additions & 0 deletions test/test-directive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ TEST(DirectiveTest, WildcardTest)
}
}

TEST(DirectiveTest, LeadingWildcard)
{
std::vector<std::string> 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<std::string> antiexamples = {
"/tes",
"/est",
};
for (auto example : antiexamples)
{
EXPECT_FALSE(parsed.match(example)) <<
example << " matched " << directive;
}
}

TEST(DirectiveTest, MultipleWildcardTest)
{
std::vector<std::string> examples = {
Expand Down

0 comments on commit a2f304e

Please sign in to comment.