#include #include #include #include Void::Testing::Test url_parse_https_defaults_port() { const auto u = Void::Net::Url::parse("https://example.com/path?q=1"); Void::Testing::expect(u.has_value()); Void::Testing::expect_eq(u->scheme, std::string{"https"}); Void::Testing::expect_eq(u->host, std::string{"example.com"}); Void::Testing::expect_eq(u->port, std::string{"443"}); Void::Testing::expect(u->is_tls); Void::Testing::expect_eq(u->path, std::string{"/path"}); Void::Testing::expect_eq(u->query, std::string{"q=1"}); Void::Testing::expect_eq(u->target, std::string{"/path?q=1"}); } Void::Testing::Test url_parse_http_explicit_port() { const auto u = Void::Net::Url::parse("http://localhost:8080/x"); Void::Testing::expect(u.has_value()); Void::Testing::expect_eq(u->port, std::string{"8080"}); Void::Testing::expect(!u->is_tls); Void::Testing::expect_eq(u->target, std::string{"/x"}); } Void::Testing::Test url_parse_root_path_defaults() { const auto u = Void::Net::Url::parse("http://example.com"); Void::Testing::expect(u.has_value()); Void::Testing::expect_eq(u->path, std::string{"/"}); Void::Testing::expect_eq(u->target, std::string{"/"}); Void::Testing::expect_eq(u->port, std::string{"80"}); } Void::Testing::Test url_parse_preserves_encoded_query() { const auto u = Void::Net::Url::parse("https://h/s?q=a%20b&x=1"); Void::Testing::expect(u.has_value()); Void::Testing::expect_eq(u->query, std::string{"q=a%20b&x=1"}); } Void::Testing::Test url_parse_rejects_garbage() { Void::Testing::expect(!Void::Net::Url::parse("ht tp://bad url").has_value()); }