| 7 | #include "fl/stl/url.h" |
| 8 | |
| 9 | FL_TEST_FILE(FL_FILEPATH) { |
| 10 | |
| 11 | using namespace fl; |
| 12 | |
| 13 | FL_TEST_CASE("Url - basic http") { |
| 14 | url u("http://example.com/path"); |
| 15 | FL_CHECK(u.isValid()); |
| 16 | FL_CHECK(u.scheme() == "http"); |
| 17 | FL_CHECK(u.host() == "example.com"); |
| 18 | FL_CHECK(u.path() == "/path"); |
| 19 | FL_CHECK(u.port() == 80); |
| 20 | FL_CHECK(u.port_str().empty()); |
| 21 | FL_CHECK(u.query().empty()); |
| 22 | FL_CHECK(u.fragment().empty()); |
| 23 | FL_CHECK(u.userinfo().empty()); |
| 24 | } |
| 25 | |
| 26 | FL_TEST_CASE("Url - full URL with all components") { |
| 27 | url u("https://user:pass@api.example.com:8080/foo/bar?key=val&a=b#section"); |
| 28 | FL_CHECK(u.isValid()); |
| 29 | FL_CHECK(u.scheme() == "https"); |
| 30 | FL_CHECK(u.userinfo() == "user:pass"); |
| 31 | FL_CHECK(u.host() == "api.example.com"); |
| 32 | FL_CHECK(u.port() == 8080); |
| 33 | FL_CHECK(u.port_str() == "8080"); |
| 34 | FL_CHECK(u.path() == "/foo/bar"); |
| 35 | FL_CHECK(u.query() == "key=val&a=b"); |
| 36 | FL_CHECK(u.fragment() == "section"); |
| 37 | FL_CHECK(u.authority() == "user:pass@api.example.com:8080"); |
| 38 | } |
| 39 | |
| 40 | FL_TEST_CASE("Url - default ports") { |
| 41 | url http("http://h.com/"); |
| 42 | FL_CHECK(http.port() == 80); |
| 43 | |
| 44 | url https("https://h.com/"); |
| 45 | FL_CHECK(https.port() == 443); |
| 46 | |
| 47 | url ws("ws://h.com/"); |
| 48 | FL_CHECK(ws.port() == 80); |
| 49 | |
| 50 | url wss("wss://h.com/"); |
| 51 | FL_CHECK(wss.port() == 443); |
| 52 | |
| 53 | url ftp("ftp://h.com/"); |
| 54 | FL_CHECK(ftp.port() == 21); |
| 55 | } |
| 56 | |
| 57 | FL_TEST_CASE("Url - missing components") { |
| 58 | // No path |
| 59 | url u1("http://example.com"); |
| 60 | FL_CHECK(u1.isValid()); |
| 61 | FL_CHECK(u1.host() == "example.com"); |
| 62 | FL_CHECK(u1.path().empty()); |
| 63 | |
| 64 | // No query/fragment |
| 65 | url u2("http://example.com/p"); |
| 66 | FL_CHECK(u2.query().empty()); |
nothing calls this directly
no test coverage detected