ladybird/Tests/LibURL/TestURLPattern.cpp
2026-05-28 09:27:41 +02:00

30 lines
1.2 KiB
C++

/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <LibURL/RustIntegration.h>
TEST_CASE(url_pattern_matches_named_groups)
{
auto pattern = MUST(URL::RustIntegration::URLPattern::create("https://example.com/:category/:id"_string));
auto result = MUST(pattern.match("https://example.com/books/42"_string, {}));
VERIFY(result.has_value());
EXPECT_EQ(result->protocol.input, "https"_string);
EXPECT_EQ(result->pathname.input, "/books/42"_string);
EXPECT_EQ(result->pathname.groups.get("category"sv).value(), (Variant<String, Empty> { "books"_string }));
EXPECT_EQ(result->pathname.groups.get("id"sv).value(), (Variant<String, Empty> { "42"_string }));
}
TEST_CASE(url_pattern_ignore_case_matching)
{
auto pattern = MUST(URL::RustIntegration::URLPattern::create("https://example.com/:value"_string, {}, URL::FFI::IgnoreCase::Yes));
auto result = MUST(pattern.match("https://example.com/CaseSensitive"_string, {}));
VERIFY(result.has_value());
EXPECT_EQ(result->pathname.groups.get("value"sv).value(), (Variant<String, Empty> { "CaseSensitive"_string }));
}