Skip to content

Commit

Permalink
Merge pull request #31 from seomoz/add-crawl-delay-to-str
Browse files Browse the repository at this point in the history
Add Crawl-Delay to string representation of Agent.
  • Loading branch information
b4hand authored Nov 17, 2017
2 parents 7046f17 + dc98f75 commit 8abadd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/agent.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <algorithm>
#include <iomanip>
#include <sstream>

#include "url.h"
Expand Down Expand Up @@ -89,6 +90,10 @@ namespace Rep
std::string Agent::str() const
{
std::stringstream out;
if (delay_ > 0)
{
out << "Crawl-Delay: " << std::setprecision(3) << delay_ << ' ';
}
out << '[';
const auto& d = directives();
auto begin = d.begin();
Expand Down
9 changes: 9 additions & 0 deletions test/test-agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,12 @@ TEST(AgentTest, Str)
agent.allow("/bar");
EXPECT_EQ("[Directive(Disallow: /foo), Directive(Allow: /bar)]", agent.str());
}

TEST(AgentTest, StrWithDelay)
{
Rep::Agent agent("a.com");
agent.delay(1.0);
agent.disallow("/foo");
agent.allow("/bar");
EXPECT_EQ("Crawl-Delay: 1 [Directive(Disallow: /foo), Directive(Allow: /bar)]", agent.str());
}

0 comments on commit 8abadd8

Please sign in to comment.