From f7f95ad76306f57282bcb6ceb42b3b576c71350a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Tesa=C5=99?= Date: Wed, 5 Aug 2026 23:40:57 +0200 Subject: [PATCH] Add percent_encode_test to test percent --- tests/core/net/test_core_net.odin | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/core/net/test_core_net.odin b/tests/core/net/test_core_net.odin index fbca15bb1..6a6111a29 100644 --- a/tests/core/net/test_core_net.odin +++ b/tests/core/net/test_core_net.odin @@ -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}