From 3b5c58a18a6823d173e9681b21c2b5867f197f99 Mon Sep 17 00:00:00 2001 From: Tony Gorez Date: Wed, 14 Aug 2024 13:14:53 +0200 Subject: [PATCH 1/2] test(uri): add few RFC 3986 tests Signed-off-by: Tony Gorez --- test/uri/uri_resolve_from_test.cc | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/uri/uri_resolve_from_test.cc b/test/uri/uri_resolve_from_test.cc index 4435cfa9b..cc0f2ac90 100644 --- a/test/uri/uri_resolve_from_test.cc +++ b/test/uri/uri_resolve_from_test.cc @@ -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"); +} From 519dd24dec5ef1030cb467c92ce36abebb59cedc Mon Sep 17 00:00:00 2001 From: Tony Gorez Date: Wed, 14 Aug 2024 13:24:40 +0200 Subject: [PATCH 2/2] test(uri): add better names for RFC tests Signed-off-by: Tony Gorez --- test/uri/uri_resolve_from_test.cc | 41 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/test/uri/uri_resolve_from_test.cc b/test/uri/uri_resolve_from_test.cc index cc0f2ac90..badf5fdf3 100644 --- a/test/uri/uri_resolve_from_test.cc +++ b/test/uri/uri_resolve_from_test.cc @@ -44,39 +44,38 @@ TEST(URI_resolve_from_if_absolute, relative_base) { // 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) { +TEST(URI_resolve_from, rfc3986_resolve_with_relative_path) { 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"); + sourcemeta::jsontoolkit::URI relative_path{"../../b"}; + relative_path.resolve_from(base); + EXPECT_EQ(relative_path.recompose(), "s://h/b"); } -TEST(URI_resolve_from, rfc3986_2) { +TEST(URI_resolve_from, rfc3986_resolve_with_empty) { 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"); + sourcemeta::jsontoolkit::URI empty{""}; + empty.resolve_from(base); + EXPECT_EQ(empty.recompose(), "s://h/a/c"); } -TEST(URI_resolve_from, rfc3986_3) { +TEST(URI_resolve_from, rfc3986_resolve_with_query) { 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"); + 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_4) { +TEST(URI_resolve_from, rfc3986_resolve_with_fragment) { 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"); + 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_5) { +TEST(URI_resolve_from, rfc3986_resolve_with_absolute_path) { 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"); + sourcemeta::jsontoolkit::URI absolute_path{"/././x"}; + absolute_path.resolve_from(base); + EXPECT_EQ(absolute_path.recompose(), "s://h/x"); }