Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
making the test more robust
  • Loading branch information
lemire committed Dec 4, 2024
commit b339ac196a0c04f2df79c643519f3cedb4df3c48
70 changes: 45 additions & 25 deletions tests/wpt_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,34 +278,54 @@ TYPED_TEST(wpt_tests_typed, toascii_encoding) {
// tests.
// @see
// https://github.com/web-platform-tests/wpt/blob/master/url/toascii.window.js
auto current =
ada::parse<TypeParam>("https://" + std::string(input) + "/x");

if (expected_output.type() == ondemand::json_type::string) {
if(output.has_value()) {
std::string_view stringified_output = expected_output.get_string();
ASSERT_EQ(current->get_host(), stringified_output);
ASSERT_EQ(current->get_hostname(), stringified_output);
ASSERT_EQ(current->get_pathname(), "/x");
ASSERT_EQ(current->get_href(),
"https://" + std::string(stringified_output) + "/x");
} else if (expected_output.is_null()) {
ASSERT_FALSE(current.has_value());
}

// Test setters for host and hostname values.
auto setter = ada::parse<TypeParam>("https://x/x");
ASSERT_EQ(setter->set_host(input), !expected_output.is_null());
ASSERT_EQ(setter->set_hostname(input), !expected_output.is_null());
ASSERT_EQ(output.value(), stringified_output);

std::string url_string = "https://" + std::string(output.value()) + "/x";
auto current =
ada::parse<TypeParam>(url_string);

if (expected_output.type() == ondemand::json_type::string) {
std::string_view stringified_output = expected_output.get_string();
if(!current.has_value()) {
std::cerr << "The URL instance could not be created from '";
for(uint8_t c : url_string) {
if(c >= 32 && c <= 126) {
std::cerr << (char)c;
} else {
// non-printable characters
std::cerr << "\\x" << std::hex << (uint32_t)c;
}
}
std::cerr << "'" << std::endl;
}
ASSERT_TRUE(current.has_value());
ASSERT_EQ(current->get_host(), stringified_output);
ASSERT_EQ(current->get_hostname(), stringified_output);
ASSERT_EQ(current->get_pathname(), "/x");
ASSERT_EQ(current->get_href(),
"https://" + std::string(stringified_output) + "/x");
} else if (expected_output.is_null()) {
ASSERT_FALSE(current.has_value());
}

if (expected_output.type() == ondemand::json_type::string) {
std::string_view stringified_output = expected_output.get_string();
ASSERT_EQ(setter->get_host(), stringified_output);
ASSERT_EQ(setter->get_hostname(), stringified_output);
} else if (expected_output.is_null()) {
// host and hostname should not be updated if the input is invalid.
ASSERT_EQ(setter->get_host(), "x");
ASSERT_EQ(setter->get_hostname(), "x");
// Test setters for host and hostname values.
auto setter = ada::parse<TypeParam>("https://x/x");
ASSERT_EQ(setter->set_host(input), !expected_output.is_null());
ASSERT_EQ(setter->set_hostname(input), !expected_output.is_null());

if (expected_output.type() == ondemand::json_type::string) {
std::string_view stringified_output = expected_output.get_string();
ASSERT_EQ(setter->get_host(), stringified_output);
ASSERT_EQ(setter->get_hostname(), stringified_output);
} else if (expected_output.is_null()) {
// host and hostname should not be updated if the input is invalid.
ASSERT_EQ(setter->get_host(), "x");
ASSERT_EQ(setter->get_hostname(), "x");
}
}

}
}
} catch (simdjson::simdjson_error &error) {
Expand Down
Loading