uri: add more test cases
This commit is contained in:
parent
805ba5d1bf
commit
498da9491b
@ -32,7 +32,9 @@
|
||||
pct_encoded = '%' xdigit xdigit;
|
||||
gen_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
|
||||
reg_name = (unreserved | pct_encoded | sub_delim)*;
|
||||
|
33
test/uri.cpp
33
test/uri.cpp
@ -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
|
||||
main (void)
|
||||
{
|
||||
cruft::TAP::logger tap;
|
||||
|
||||
test_validity (tap);
|
||||
test_parse (tap);
|
||||
test_normalise (tap);
|
||||
test_rfc_resolve (tap);
|
||||
|
Loading…
Reference in New Issue
Block a user