uri: add more test cases

This commit is contained in:
Danny Robson 2022-02-01 12:25:57 +10:00
parent 805ba5d1bf
commit 498da9491b
3 changed files with 36 additions and 2 deletions

View File

@ -32,7 +32,9 @@
pct_encoded = '%' xdigit xdigit; pct_encoded = '%' xdigit xdigit;
gen_delim = ":" | "/" | "?" | "#" | "[" | "]" | "@"; gen_delim = ":" | "/" | "?" | "#" | "[" | "]" | "@";
sub_delim = "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "="; sub_delim = "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "=";
pchar = unreserved | pct_encoded | sub_delim | ':' | '@'; # double quote is allowed here because it's quite common in real life and
# we don't have a great way to work around it here.
pchar = unreserved | pct_encoded | sub_delim | ':' | '@' | '"';
## Atoms ## Atoms
reg_name = (unreserved | pct_encoded | sub_delim)*; reg_name = (unreserved | pct_encoded | sub_delim)*;

View File

@ -339,12 +339,45 @@ test_resolve (cruft::TAP::logger &tap)
} }
///////////////////////////////////////////////////////////////////////////////
static
void
test_validity (cruft::TAP::logger &tap)
{
static char const *GOOD[] = {
"http://[2001:db8::7]/",
"http://[2001:db8::7]:80/",
"http://user@example.com:10/",
"http://user@example.com",
"http://example.com:443/",
"https://example.com:80/",
"http://example.com/foo?bar=qux#xyz",
"http://example.com/?bar=qux#xyz",
"http://example.com/#xyz",
"http://example.com/???",
"http://example.com/?#?",
"http://example.com/%22",
};
for (auto const &good: GOOD)
tap.expect_nothrow ([&] (void) { (void) cruft::uri (good); }, "parse: {}", good);
static char const *BAD[] = {
// "http://example.com/?foo=\"bar\"",
};
for (auto const &bad: BAD)
tap.expect_throw<std::exception> ([&] (void) { (void) cruft::uri (bad); }, "parse: {}", bad);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
int int
main (void) main (void)
{ {
cruft::TAP::logger tap; cruft::TAP::logger tap;
test_validity (tap);
test_parse (tap); test_parse (tap);
test_normalise (tap); test_normalise (tap);
test_rfc_resolve (tap); test_rfc_resolve (tap);

View File

@ -9,7 +9,6 @@
using cruft::uri; using cruft::uri;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <cruft/util/debug/assert.hpp> #include <cruft/util/debug/assert.hpp>
#include <cruft/util/debug/warn.hpp> #include <cruft/util/debug/warn.hpp>