log_tests.c (1366B)
1 #include "writer/gemini/log.h" 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 #include "fs_inmemory.h" 8 #include "git/commit.h" 9 #include "git/repo.h" 10 #include "test_utils.h" 11 #include "utest.h" 12 13 struct gemini_log { 14 int dummy; 15 }; 16 17 UTEST_F_SETUP(gemini_log) { 18 inmemory_fs_clear(); 19 } 20 21 UTEST_F_TEARDOWN(gemini_log) {} 22 23 UTEST_F(gemini_log, begin) { 24 GitRepo repo = {.short_name = "test-repo"}; 25 GeminiLog* log = gemini_log_create(&repo, g_fs_inmemory); 26 ASSERT_NE(NULL, log); 27 gemini_log_begin(log); 28 gemini_log_free(log); 29 30 const char* buf = inmemory_fs_get_buffer("log.gmi"); 31 ASSERT_NE(NULL, buf); 32 EXPECT_STR_SEQUENCE(buf, "# Log - test-repo"); 33 } 34 35 UTEST_F(gemini_log, add_commit) { 36 GitRepo repo = {.short_name = "test-repo"}; 37 GeminiLog* log = gemini_log_create(&repo, g_fs_inmemory); 38 ASSERT_NE(NULL, log); 39 40 GitCommit commit = { 41 .oid = "abc1234", 42 .summary = "Fix bug", 43 .author_name = "User", 44 .author_time = 1702031400, 45 }; 46 47 gemini_log_begin(log); 48 gemini_log_add_commit(log, &commit); 49 gemini_log_end(log); 50 gemini_log_free(log); 51 52 const char* buf = inmemory_fs_get_buffer("log.gmi"); 53 ASSERT_NE(NULL, buf); 54 /* Gemini format: => commit/abc1234.gmi 2023-12-08 10:30 Fix bug [User] */ 55 EXPECT_STR_SEQUENCE(buf, "=> commit/abc1234.gmi", "2023-12-08 10:30", 56 "Fix bug", "[User]"); 57 }