Skip to content

Commit 4e5b900

Browse files
authored
test: add tests for url::can_parse (#376)
1 parent 0125fc2 commit 4e5b900

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

include/ada/implementation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ extern template ada::result<url_aggregator> parse<url_aggregator>(
4444
* @see https://url.spec.whatwg.org/#dom-url-canparse
4545
* @return If URL can be parsed or not.
4646
*/
47-
bool can_parse(std::string_view input, std::string_view* base_input);
47+
bool can_parse(std::string_view input,
48+
const std::string_view* base_input = nullptr);
4849

4950
/**
5051
* Computes a href string from a file path.

src/implementation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::string href_from_file(std::string_view input) {
4646
return "file://" + path;
4747
}
4848

49-
bool can_parse(std::string_view input, std::string_view* base_input = nullptr) {
49+
bool can_parse(std::string_view input, const std::string_view* base_input) {
5050
ada::result<ada::url_aggregator> base;
5151
ada::url_aggregator* base_pointer = nullptr;
5252
if (base_input != nullptr) {

tests/basic_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,14 @@ TYPED_TEST(basic_tests, node_issue_47889) {
293293
ASSERT_EQ(url->get_pathname(), "b");
294294
SUCCEED();
295295
}
296+
297+
TEST(basic_tests, can_parse) {
298+
ASSERT_TRUE(ada::can_parse("https://www.yagiz.co"));
299+
std::string_view base = "https://yagiz.co";
300+
ASSERT_TRUE(ada::can_parse("/hello", &base));
301+
302+
std::string_view invalid_base = "!!!!!!!1";
303+
ASSERT_FALSE(ada::can_parse("/hello", &invalid_base));
304+
ASSERT_FALSE(ada::can_parse("!!!"));
305+
SUCCEED();
306+
}

0 commit comments

Comments
 (0)