From 2a8146daba93a046429c60552f368f7680bc5444 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 8 Jan 2025 13:24:48 -0500 Subject: [PATCH] add urlpattern::test() tests --- tests/wpt_urlpattern_tests.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/wpt_urlpattern_tests.cpp b/tests/wpt_urlpattern_tests.cpp index 89bea3a13..6b9263a85 100644 --- a/tests/wpt_urlpattern_tests.cpp +++ b/tests/wpt_urlpattern_tests.cpp @@ -494,6 +494,7 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) { auto [input_value, base_url] = parse_inputs_array(inputs); tl::expected, ada::errors> exec_result; + tl::expected test_result; std::string_view base_url_view; std::string_view* opt_base_url = nullptr; if (base_url) { @@ -504,10 +505,12 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) { auto str = std::get(input_value); ada_log("input_value is str=", str); exec_result = parse_result->exec(str, opt_base_url); + test_result = parse_result->test(str, opt_base_url); } else { ada_log("input_value is url_pattern_init"); auto obj = std::get(input_value); exec_result = parse_result->exec(obj, opt_base_url); + test_result = parse_result->test(obj, opt_base_url); } ondemand::value expected_match = main_object["expected_match"].value(); @@ -517,16 +520,24 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) { ASSERT_EQ(exec_result.has_value(), false) << "Expected error but exec() has_value= " << exec_result->has_value(); + ASSERT_FALSE(test_result) + << "Expected test() to throw, but it didn't"; } else if (expected_match.type() == ondemand::json_type::null) { ASSERT_EQ(exec_result.has_value(), true) << "Expected non failure but it throws an error"; ASSERT_EQ(exec_result->has_value(), false) << "Expected null value but exec() returned a value "; + ASSERT_FALSE(test_result.value()) + << "Expected false for test() but received true"; } else { ASSERT_EQ(exec_result.has_value(), true) << "Expect match to succeed but it throw an error"; ASSERT_EQ(exec_result->has_value(), true) << "Expect match to succeed but it returned a null value"; + ASSERT_TRUE(test_result) + << "Expected test() to not throw, but it did"; + ASSERT_TRUE(test_result.value()) + << "Expected true for test() but received false"; auto exec_result_obj = expected_match.get_object().value(); auto [expected_exec_result, has_inputs] = parse_exec_result(exec_result_obj);