diff options
| author | gingerBill <bill@gingerbill.org> | 2023-10-02 20:59:49 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-10-02 20:59:49 +0100 |
| commit | 2cca00505601f0b0e76719d366a037cdb4cf794c (patch) | |
| tree | 64268ab5ad8c54d5dbd594c1582584c4465a5827 | |
| parent | d27109640e6c6d86419d2a419a2d5ec3a0cfd1d9 (diff) | |
| parent | 1287e8c7349162e60e49234c36b952d14bc93a91 (diff) | |
Merge branch 'master' of https://github.com/odin-lang/Odindev-2023-10
| -rw-r--r-- | core/fmt/fmt.odin | 4 | ||||
| -rw-r--r-- | tests/core/net/test_core_net.odin | 127 |
2 files changed, 105 insertions, 26 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index c2240c275..1f52fdea9 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -152,9 +152,9 @@ aprintln :: proc(args: ..any, sep := " ") -> string { // // Returns: A formatted string. The returned string must be freed accordingly. // -aprintf :: proc(fmt: string, args: ..any) -> string { +aprintf :: proc(fmt: string, args: ..any, allocator := context.allocator) -> string { str: strings.Builder - strings.builder_init(&str) + strings.builder_init(&str, allocator) sbprintf(&str, fmt, ..args) return strings.to_string(str) } diff --git a/tests/core/net/test_core_net.odin b/tests/core/net/test_core_net.odin index 14e1cbb17..ab5f2e117 100644 --- a/tests/core/net/test_core_net.odin +++ b/tests/core/net/test_core_net.odin @@ -17,6 +17,7 @@ import "core:net" import "core:strconv" import "core:time" import "core:thread" +import "core:os" _, _ :: time, thread @@ -73,6 +74,10 @@ main :: proc() { fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count) print_tracking_allocator_report() + + if TEST_fail > 0 { + os.exit(1) + } } @test @@ -516,25 +521,61 @@ client_sends_server_data :: proc(t: ^testing.T) { URL_Test :: struct { scheme, host, path: string, queries: map[string]string, - url: string, + url: []string, } @test split_url_test :: proc(t: ^testing.T) { test_cases := []URL_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" }, + { + "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 { - scheme, host, path, queries := net.split_url(test.url) + scheme, host, path, queries := net.split_url(test.url[0]) defer { delete(queries) delete(test.queries) @@ -560,15 +601,51 @@ split_url_test :: proc(t: ^testing.T) { @test join_url_test :: proc(t: ^testing.T) { test_cases := []URL_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" }, + { + "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/?c=d&a=b"}, + }, + { + "http", "example.com", "/", + {"a" = "", "c" = "d"}, + {"http://example.com/?a&c=d", "http://example.com/?c=d&a"}, + }, + { + "http", "example.com", "/example", + {"a" = "", "b" = ""}, + {"http://example.com/example?a&b", "http://example.com/example?b&a"}, + }, } for test in test_cases { @@ -577,9 +654,11 @@ join_url_test :: proc(t: ^testing.T) { delete(url) delete(test.queries) } - - okay := url == test.url - msg := fmt.tprintf("Expected `net.join_url` to return %s, got %s", test.url, url) - expect(t, okay, msg) + pass := false + for test_url in test.url { + pass |= url == test_url + } + msg := fmt.tprintf("Expected `net.join_url` to return one of %s, got %s", test.url, url) + expect(t, pass, msg) } } |