gout

A static git page generator
git clone https://git.bracken.jp/gout.git
Log | Files | Refs | README | LICENSE

commit 3a5781e8fa75436b0932a283aeb9e331ce5df9d8
parent ffae3154d0d0ea6b550ac7a07d4ba90f2acb9d11
Author: Chris Bracken <chris@bracken.jp>
Date:   Thu, 24 Jul 2025 13:48:52 -0700

Add tests for print_percent_encoded

Diffstat:
Mformat_tests.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+), 0 deletions(-)

diff --git a/format_tests.c b/format_tests.c @@ -93,3 +93,59 @@ UTEST(print_time_short, Basic) { free(buf); } + +UTEST(print_percent_encoded, NoEncoding) { + char* buf = NULL; + size_t size = 0; + FILE* out = open_memstream(&buf, &size); + ASSERT_NE(NULL, out); + + print_percent_encoded(out, "abcdef-1234/.,"); + fclose(out); + + EXPECT_STREQ("abcdef-1234/.,", buf); + + free(buf); +} + +UTEST(print_percent_encoded, SimpleEncoding) { + char* buf = NULL; + size_t size = 0; + FILE* out = open_memstream(&buf, &size); + ASSERT_NE(NULL, out); + + print_percent_encoded(out, "hello world"); + fclose(out); + + EXPECT_STREQ("hello%20world", buf); + + free(buf); +} + +UTEST(print_percent_encoded, ReservedChars) { + char* buf = NULL; + size_t size = 0; + FILE* out = open_memstream(&buf, &size); + ASSERT_NE(NULL, out); + + print_percent_encoded(out, " \"%[]:?@"); + fclose(out); + + EXPECT_STREQ("%20%22%25%5B%5D%3A%3F%40", buf); + + free(buf); +} + +UTEST(print_percent_encoded, EmptyString) { + char* buf = NULL; + size_t size = 0; + FILE* out = open_memstream(&buf, &size); + ASSERT_NE(NULL, out); + + print_percent_encoded(out, ""); + fclose(out); + + EXPECT_STREQ("", buf); + + free(buf); +}