Skip to content

Commit

Permalink
test(uri): add few RFC 3986 tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Gorez <[email protected]>
  • Loading branch information
tony-go committed Aug 14, 2024
1 parent 838570e commit 3b5c58a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/uri/uri_resolve_from_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,42 @@ TEST(URI_resolve_from_if_absolute, relative_base) {
relative.resolve_from_if_absolute(base);
EXPECT_EQ(relative.recompose(), "../baz");
}

// RFC 3986, inspired from
// https://cr.openjdk.org/~dfuchs/writeups/updating-uri/A Section "Resolutuon"
// TODO: find better names for each case

TEST(URI_resolve_from, rfc3986_1) {
const sourcemeta::jsontoolkit::URI base{"s://h/a/c"};
sourcemeta::jsontoolkit::URI relative{"../../b"};
relative.resolve_from(base);
EXPECT_EQ(relative.recompose(), "s://h/b");
}

TEST(URI_resolve_from, rfc3986_2) {
const sourcemeta::jsontoolkit::URI base{"s://h/a/c"};
sourcemeta::jsontoolkit::URI relative{""};
relative.resolve_from(base);
EXPECT_EQ(relative.recompose(), "s://h/a/c");
}

TEST(URI_resolve_from, rfc3986_3) {
const sourcemeta::jsontoolkit::URI base{"s://h/a/c"};
sourcemeta::jsontoolkit::URI relative{"?x=y"};
relative.resolve_from(base);
EXPECT_EQ(relative.recompose(), "s://h/a/c?x=y");
}

TEST(URI_resolve_from, rfc3986_4) {
const sourcemeta::jsontoolkit::URI base{"s://h/a/c"};
sourcemeta::jsontoolkit::URI relative{"#x=y"};
relative.resolve_from(base);
EXPECT_EQ(relative.recompose(), "s://h/a/c#x=y");
}

TEST(URI_resolve_from, rfc3986_5) {
const sourcemeta::jsontoolkit::URI base{"s://h/a/c"};
sourcemeta::jsontoolkit::URI relative{"/././x"};
relative.resolve_from(base);
EXPECT_EQ(relative.recompose(), "s://h/x");
}

0 comments on commit 3b5c58a

Please sign in to comment.