Skip to content

Commit 08851a3

Browse files
authored
Fix setters to return correct boolean value (#727)
* Update set_protocol to return correct boolean value, and add tests * Update other cases to also return false
1 parent 59cc693 commit 08851a3

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/url.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,21 @@ ada_really_inline bool url::parse_scheme(const std::string_view input) {
340340
// If url's scheme is not a special scheme and buffer is a special scheme,
341341
// then return.
342342
if (is_special() != is_input_special) {
343-
return true;
343+
return false;
344344
}
345345

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

353353
// If url's scheme is "file" and its host is an empty host, then return.
354354
// An empty host is the empty string.
355355
if (type == ada::scheme::type::FILE && host.has_value() &&
356356
host.value().empty()) {
357-
return true;
357+
return false;
358358
}
359359
}
360360

src/url_aggregator.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ template <bool has_state_override>
3131
// If url's scheme is not a special scheme and buffer is a special scheme,
3232
// then return.
3333
if (is_special() != is_input_special) {
34-
return true;
34+
return false;
3535
}
3636

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

4444
// If url's scheme is "file" and its host is an empty host, then return.
4545
// An empty host is the empty string.
4646
if (type == ada::scheme::type::FILE &&
4747
components.host_start == components.host_end) {
48-
return true;
48+
return false;
4949
}
5050
}
5151

tests/basic_tests.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,28 @@ TYPED_TEST(basic_tests, readme2) {
104104

105105
TYPED_TEST(basic_tests, readme3) {
106106
auto url = ada::parse<TypeParam>("https://www.google.com");
107-
url->set_protocol("wss");
107+
ASSERT_EQ(url->set_protocol("wss"), true);
108108
ASSERT_EQ(url->get_protocol(), "wss:");
109109
ASSERT_EQ(url->get_href(), "wss://www.google.com/");
110110
SUCCEED();
111111
}
112112

113+
TYPED_TEST(basic_tests, set_protocol_should_return_false_sometimes) {
114+
auto url = ada::parse<TypeParam>("file:");
115+
ASSERT_EQ(url->set_protocol("https"), false);
116+
ASSERT_EQ(url->set_host("google.com"), true);
117+
ASSERT_EQ(url->get_href(), "file://google.com/");
118+
SUCCEED();
119+
}
120+
121+
TYPED_TEST(basic_tests, set_protocol_should_return_true_sometimes) {
122+
auto url = ada::parse<TypeParam>("file:");
123+
ASSERT_EQ(url->set_host("google.com"), true);
124+
ASSERT_EQ(url->set_protocol("https"), true);
125+
ASSERT_EQ(url->get_href(), "https://google.com/");
126+
SUCCEED();
127+
}
128+
113129
TYPED_TEST(basic_tests, readme4) {
114130
auto url = ada::parse<TypeParam>("https://www.google.com");
115131
url->set_host("github.com");

0 commit comments

Comments
 (0)