diff --git a/test/uri/uri_resolve_from_test.cc b/test/uri/uri_resolve_from_test.cc index 4435cfa9b..badf5fdf3 100644 --- a/test/uri/uri_resolve_from_test.cc +++ b/test/uri/uri_resolve_from_test.cc @@ -41,3 +41,41 @@ 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" + +TEST(URI_resolve_from, rfc3986_resolve_with_relative_path) { + const sourcemeta::jsontoolkit::URI base{"s://h/a/c"}; + sourcemeta::jsontoolkit::URI relative_path{"../../b"}; + relative_path.resolve_from(base); + EXPECT_EQ(relative_path.recompose(), "s://h/b"); +} + +TEST(URI_resolve_from, rfc3986_resolve_with_empty) { + const sourcemeta::jsontoolkit::URI base{"s://h/a/c"}; + sourcemeta::jsontoolkit::URI empty{""}; + empty.resolve_from(base); + EXPECT_EQ(empty.recompose(), "s://h/a/c"); +} + +TEST(URI_resolve_from, rfc3986_resolve_with_query) { + const sourcemeta::jsontoolkit::URI base{"s://h/a/c"}; + sourcemeta::jsontoolkit::URI query{"?x=y"}; + query.resolve_from(base); + EXPECT_EQ(query.recompose(), "s://h/a/c?x=y"); +} + +TEST(URI_resolve_from, rfc3986_resolve_with_fragment) { + const sourcemeta::jsontoolkit::URI base{"s://h/a/c"}; + sourcemeta::jsontoolkit::URI fragment{"#x=y"}; + fragment.resolve_from(base); + EXPECT_EQ(fragment.recompose(), "s://h/a/c#x=y"); +} + +TEST(URI_resolve_from, rfc3986_resolve_with_absolute_path) { + const sourcemeta::jsontoolkit::URI base{"s://h/a/c"}; + sourcemeta::jsontoolkit::URI absolute_path{"/././x"}; + absolute_path.resolve_from(base); + EXPECT_EQ(absolute_path.recompose(), "s://h/x"); +}