gout

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

commit 0e5d6d353ab4998e720ee76eb7c37cc10c941cf5
parent 3e3a7690b515a054ca79df9e2c17e8c71a72470d
Author: Chris Bracken <chris@bracken.jp>
Date:   Thu, 24 Jul 2025 13:37:40 -0700

Add tests for print_time

Adds unit tests for formatting times with positive, zero, and negative
UTC offsets.

Diffstat:
MBUILD.gn | 1+
Aformat_tests.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/BUILD.gn b/BUILD.gn @@ -56,6 +56,7 @@ executable("gitout_tests") { testonly = true sources = [ + "format_tests.c", "gitout_tests.c", "gitout_tests_main.c", "utils_tests.c", diff --git a/format_tests.c b/format_tests.c @@ -0,0 +1,61 @@ +#include "format.h" + +#include <stdlib.h> +#include <stdio.h> +#include <time.h> + +#include "utest.h" + +UTEST(print_time, PositiveOffset) { + char* buf = NULL; + size_t size = 0; + FILE* out = open_memstream(&buf, &size); + ASSERT_NE(NULL, out); + + /* Test time: 2023-12-08 10:30:00 UTC */ + time_t test_time = 1702031400; + int timezone_offset = 540; /* +09:00 */ + + print_time(out, test_time, timezone_offset); + fclose(out); + + EXPECT_STREQ("Fri, 8 Dec 2023 19:30:00 +0900", buf); + + free(buf); +} + +UTEST(print_time, NegativeOffset) { + char* buf = NULL; + size_t size = 0; + FILE* out = open_memstream(&buf, &size); + ASSERT_NE(NULL, out); + + /* Test time: 2023-12-08 10:30:00 UTC */ + time_t test_time = 1702031400; + int timezone_offset = -300; /* -05:00 */ + + print_time(out, test_time, timezone_offset); + fclose(out); + + EXPECT_STREQ("Fri, 8 Dec 2023 05:30:00 -0500", buf); + + free(buf); +} + +UTEST(print_time, ZeroOffset) { + char* buf = NULL; + size_t size = 0; + FILE* out = open_memstream(&buf, &size); + ASSERT_NE(NULL, out); + + /* Test time: 2023-12-08 10:30:00 UTC */ + time_t test_time = 1702031400; + int timezone_offset = 0; /* UTC */ + + print_time(out, test_time, timezone_offset); + fclose(out); + + EXPECT_STREQ("Fri, 8 Dec 2023 10:30:00 +0000", buf); + + free(buf); +}