Skip to content

Commit

Permalink
Fix setters to return correct boolean value (#727)
Browse files Browse the repository at this point in the history
* Update set_protocol to return correct boolean value, and add tests

* Update other cases to also return false
  • Loading branch information
CarlosEduR authored Sep 2, 2024
1 parent 59cc693 commit 08851a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
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

0 comments on commit 08851a3

Please sign in to comment.