Skip to content

Commit 22d862f

Browse files
authored
Add some more URN parsing tests (#1915)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 5335a2f commit 22d862f

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/uri/uri_parse_test.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,40 @@ TEST(URI_parse, syntax_error_5) {
3636
sourcemeta::core::URIParseError);
3737
}
3838

39+
TEST(URI_parse, urn_with_slash) {
40+
// RFC 8141 explicitly allows "/" in URN NSS
41+
sourcemeta::core::URI uri{"urn:example:foo/bar/baz"};
42+
EXPECT_EQ(uri.scheme().value(), "urn");
43+
EXPECT_EQ(uri.path().value(), "example:foo/bar/baz");
44+
EXPECT_EQ(uri.recompose(), "urn:example:foo/bar/baz");
45+
}
46+
47+
TEST(URI_parse, urn_with_numeric_path) {
48+
// Example from RFC 8141
49+
sourcemeta::core::URI uri{"urn:example:1/406/47452/2"};
50+
EXPECT_EQ(uri.scheme().value(), "urn");
51+
EXPECT_EQ(uri.path().value(), "example:1/406/47452/2");
52+
EXPECT_EQ(uri.recompose(), "urn:example:1/406/47452/2");
53+
}
54+
55+
TEST(URI_parse, urn_with_query) {
56+
// RFC 8141 allows query components in URNs
57+
sourcemeta::core::URI uri{"urn:example:foo?+bar"};
58+
EXPECT_EQ(uri.scheme().value(), "urn");
59+
EXPECT_EQ(uri.path().value(), "example:foo");
60+
EXPECT_EQ(uri.query().value(), "+bar");
61+
EXPECT_EQ(uri.recompose(), "urn:example:foo?+bar");
62+
}
63+
64+
TEST(URI_parse, urn_with_fragment) {
65+
// RFC 8141 allows fragments in URNs
66+
sourcemeta::core::URI uri{"urn:example:foo#bar"};
67+
EXPECT_EQ(uri.scheme().value(), "urn");
68+
EXPECT_EQ(uri.path().value(), "example:foo");
69+
EXPECT_EQ(uri.fragment().value(), "bar");
70+
EXPECT_EQ(uri.recompose(), "urn:example:foo#bar");
71+
}
72+
3973
TEST(URI_parse, syntax_error_percent_at_end) {
4074
EXPECT_THROW(sourcemeta::core::URI uri{"https://www.example.com#/foo%"},
4175
sourcemeta::core::URIParseError);

0 commit comments

Comments
 (0)