Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setters to return correct boolean value #727

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,21 @@ ada_really_inline bool url::parse_scheme(const std::string_view input) {
// If url's scheme is not a special scheme and buffer is a special scheme,
// then return.
if (is_special() != is_input_special) {
return true;
return false;
}

// If url includes credentials or has a non-null port, and buffer is
// "file", then return.
if ((has_credentials() || port.has_value()) &&
parsed_type == ada::scheme::type::FILE) {
return true;
return false;
}

// If url's scheme is "file" and its host is an empty host, then return.
// An empty host is the empty string.
if (type == ada::scheme::type::FILE && host.has_value() &&
host.value().empty()) {
return true;
return false;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/url_aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ template <bool has_state_override>
// If url's scheme is not a special scheme and buffer is a special scheme,
// then return.
if (is_special() != is_input_special) {
return true;
return false;
}

// If url includes credentials or has a non-null port, and buffer is
// "file", then return.
if ((has_credentials() || components.port != url_components::omitted) &&
parsed_type == ada::scheme::type::FILE) {
return true;
return false;
}

// If url's scheme is "file" and its host is an empty host, then return.
// An empty host is the empty string.
if (type == ada::scheme::type::FILE &&
components.host_start == components.host_end) {
return true;
return false;
}
}

Expand Down
18 changes: 17 additions & 1 deletion tests/basic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,28 @@ TYPED_TEST(basic_tests, readme2) {

TYPED_TEST(basic_tests, readme3) {
auto url = ada::parse<TypeParam>("https://www.google.com");
url->set_protocol("wss");
ASSERT_EQ(url->set_protocol("wss"), true);
ASSERT_EQ(url->get_protocol(), "wss:");
ASSERT_EQ(url->get_href(), "wss://www.google.com/");
SUCCEED();
}

TYPED_TEST(basic_tests, set_protocol_should_return_false_sometimes) {
auto url = ada::parse<TypeParam>("file:");
ASSERT_EQ(url->set_protocol("https"), false);
ASSERT_EQ(url->set_host("google.com"), true);
ASSERT_EQ(url->get_href(), "file://google.com/");
SUCCEED();
}

TYPED_TEST(basic_tests, set_protocol_should_return_true_sometimes) {
auto url = ada::parse<TypeParam>("file:");
ASSERT_EQ(url->set_host("google.com"), true);
ASSERT_EQ(url->set_protocol("https"), true);
ASSERT_EQ(url->get_href(), "https://google.com/");
SUCCEED();
}

TYPED_TEST(basic_tests, readme4) {
auto url = ada::parse<TypeParam>("https://www.google.com");
url->set_host("github.com");
Expand Down
Loading