Add percent_encode_test to test percent

This commit is contained in:
Michael Tesař
2026-08-05 23:40:57 +02:00
parent 7e84194853
commit f7f95ad763

View File

@@ -304,7 +304,7 @@ client_sends_server_data :: proc(t: ^testing.T) {
r.length, r.err = net.recv_tcp(client, r.data[:])
return
}
thread_data := [2]Thread_Data{}
wg: sync.Wait_Group
@@ -313,7 +313,7 @@ client_sends_server_data :: proc(t: ^testing.T) {
thread_data[0].t = t
thread_data[0].wg = &wg
thread_data[0].tid = thread.create_and_start_with_data(&thread_data[0], tcp_server, context)
sync.wait_group_wait(&wg)
sync.wait_group_add(&wg, 2)
@@ -525,6 +525,31 @@ join_url_test :: proc(t: ^testing.T) {
}
}
@test
percent_encode_test :: proc(t: ^testing.T) {
test_cases := []struct{input, expected: string} {
// Bytes < 0x10 must be zero-padded to two hex digits
{"\n", "%0A"},
{"\t", "%09"},
{"\r", "%0D"},
{"a\nb", "a%0Ab"},
{"\x00", "%00"},
// Bytes >= 0x10
{" ", "%20"},
{"😃", "%F0%9F%98%83"},
// Unreserved characters pass through unescaped
{"AZaz09-_.~", "AZaz09-_.~"},
}
for test in test_cases {
encoded := net.percent_encode(test.input)
defer delete(encoded)
testing.expectf(t, encoded == test.expected, "Expected `net.percent_encode(%q)` to return %q, got %q", test.input, test.expected, encoded)
}
}
@test
test_udp_echo :: proc(t: ^testing.T) {
endpoint := net.Endpoint{address=net.IP4_Address{127, 0, 0, 1}, port=0}