aboutsummaryrefslogtreecommitdiff
path: root/tests/core
diff options
context:
space:
mode:
authorYoshihiro Tanaka <contact@cordea.jp>2023-05-14 11:10:53 +0900
committerYoshihiro Tanaka <contact@cordea.jp>2023-05-14 12:15:20 +0900
commit418a0132d033c7556cbd3db665affd6059daa6bf (patch)
treea282d4a5e266a2577b10c03d47c7794c68b3b8d2 /tests/core
parent8693a045bbba40c5614ff5912137540c91e61cb0 (diff)
Join URL queries with &
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/net/test_core_net.odin36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/core/net/test_core_net.odin b/tests/core/net/test_core_net.odin
index 00c29db95..510ac7c64 100644
--- a/tests/core/net/test_core_net.odin
+++ b/tests/core/net/test_core_net.odin
@@ -67,6 +67,8 @@ main :: proc() {
tcp_tests(t)
}
+ join_url_test(t)
+
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
print_tracking_allocator_report()
@@ -508,4 +510,36 @@ client_sends_server_data :: proc(t: ^testing.T) {
okay = received == CONTENT
msg = fmt.tprintf("Expected client to send \"{}\", got \"{}\"", CONTENT, received)
expect(t, okay, msg)
-} \ No newline at end of file
+}
+
+@test
+join_url_test :: proc(t: ^testing.T) {
+ URL_Join_Test :: struct {
+ scheme, host, path: string,
+ queries: map[string]string,
+ expected: string,
+ }
+ test_cases := []URL_Join_Test{
+ { "http", "example.com", "", {}, "http://example.com" },
+ { "https", "odin-lang.org", "", {}, "https://odin-lang.org" },
+ { "https", "odin-lang.org", "docs/", {}, "https://odin-lang.org/docs/" },
+ { "https", "odin-lang.org", "/docs/overview", {}, "https://odin-lang.org/docs/overview" },
+ { "http", "example.com", "", {"a" = "b"}, "http://example.com?a=b" },
+ { "http", "example.com", "", {"a" = ""}, "http://example.com?a" },
+ { "http", "example.com", "", {"a" = "b", "c" = "d"}, "http://example.com?a=b&c=d" },
+ { "http", "example.com", "", {"a" = "", "c" = "d"}, "http://example.com?a&c=d" },
+ { "http", "example.com", "example", {"a" = "", "b" = ""}, "http://example.com/example?a&b" },
+ }
+
+ for test in test_cases {
+ url := net.join_url(test.scheme, test.host, test.path, test.queries)
+ defer {
+ delete(test.queries)
+ delete(url)
+ }
+
+ okay := url == test.expected
+ msg := fmt.tprintf("Expected `net.join_url` to return %s, got %s", test.expected, url)
+ expect(t, okay, msg)
+ }
+}