Skip to content

Commit

Permalink
Add parse_dec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Jul 30, 2018
1 parent 8023908 commit 6d1bd38
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version 181:

* Fix parse_dec algorithm
* Add parse_dec tests

--------------------------------------------------------------------------------

Expand Down
37 changes: 37 additions & 0 deletions test/beast/http/basic_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,42 @@ class basic_parser_test : public beast::unit_test::suite
BEAST_EXPECT(ec);
}

void
testIssue1211()
{
using base = detail::basic_parser_base;
auto const good =
[&](string_view s, unsigned long v0)
{
unsigned long v;
auto const result =
base::parse_dec(s.begin(), s.end(), v);
if(BEAST_EXPECTS(result, s))
BEAST_EXPECTS(v == v0, s);
};
auto const bad =
[&](string_view s)
{
unsigned long v;
auto const result =
base::parse_dec(s.begin(), s.end(), v);
BEAST_EXPECTS(! result, s);
};
good("0", 0);
good("00", 0);
good("001", 1);
good("255", 255);
good("65535", 65535);
good("65536", 65536);
good("4294967295", 4294967295);
bad ("");
bad (" ");
bad (" 0");
bad ("0 ");
bad ("-1");
bad ("4294967296");
}

//--------------------------------------------------------------------------

void
Expand All @@ -1237,6 +1273,7 @@ class basic_parser_test : public beast::unit_test::suite
testIssue692();
testFuzz();
testRegression1();
testIssue1211();
}
};

Expand Down

0 comments on commit 6d1bd38

Please sign in to comment.