mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Allow any order of query strings in net.join_url tests.
This commit is contained in:
@@ -516,25 +516,61 @@ client_sends_server_data :: proc(t: ^testing.T) {
|
|||||||
URL_Test :: struct {
|
URL_Test :: struct {
|
||||||
scheme, host, path: string,
|
scheme, host, path: string,
|
||||||
queries: map[string]string,
|
queries: map[string]string,
|
||||||
url: string,
|
url: []string,
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
split_url_test :: proc(t: ^testing.T) {
|
split_url_test :: proc(t: ^testing.T) {
|
||||||
test_cases := []URL_Test{
|
test_cases := []URL_Test{
|
||||||
{ "http", "example.com", "/", {}, "http://example.com" },
|
{
|
||||||
{ "https", "odin-lang.org", "/", {}, "https://odin-lang.org" },
|
"http", "example.com", "/",
|
||||||
{ "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"},
|
||||||
{ "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" },
|
"https", "odin-lang.org", "/",
|
||||||
{ "http", "example.com", "/", {"a" = "", "c" = "d"}, "http://example.com?a&c=d" },
|
{},
|
||||||
{ "http", "example.com", "/example", {"a" = "", "b" = ""}, "http://example.com/example?a&b" },
|
{"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 {
|
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 {
|
defer {
|
||||||
delete(queries)
|
delete(queries)
|
||||||
delete(test.queries)
|
delete(test.queries)
|
||||||
@@ -560,15 +596,51 @@ split_url_test :: proc(t: ^testing.T) {
|
|||||||
@test
|
@test
|
||||||
join_url_test :: proc(t: ^testing.T) {
|
join_url_test :: proc(t: ^testing.T) {
|
||||||
test_cases := []URL_Test{
|
test_cases := []URL_Test{
|
||||||
{ "http", "example.com", "", {}, "http://example.com" },
|
{
|
||||||
{ "https", "odin-lang.org", "", {}, "https://odin-lang.org" },
|
"http", "example.com", "/",
|
||||||
{ "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/"},
|
||||||
{ "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" },
|
"https", "odin-lang.org", "/",
|
||||||
{ "http", "example.com", "", {"a" = "", "c" = "d"}, "http://example.com?a&c=d" },
|
{},
|
||||||
{ "http", "example.com", "example", {"a" = "", "b" = ""}, "http://example.com/example?a&b" },
|
{"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 {
|
for test in test_cases {
|
||||||
@@ -577,9 +649,11 @@ join_url_test :: proc(t: ^testing.T) {
|
|||||||
delete(url)
|
delete(url)
|
||||||
delete(test.queries)
|
delete(test.queries)
|
||||||
}
|
}
|
||||||
|
pass := false
|
||||||
okay := url == test.url
|
for test_url in test.url {
|
||||||
msg := fmt.tprintf("Expected `net.join_url` to return %s, got %s", test.url, url)
|
pass |= url == test_url
|
||||||
expect(t, okay, msg)
|
}
|
||||||
|
msg := fmt.tprintf("Expected `net.join_url` to return one of %s, got %s", test.url, url)
|
||||||
|
expect(t, pass, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user