gout

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

refs_tests.c (1130B)


      1 #include "writer/gemini/refs.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/reference.h"
     10 #include "git/repo.h"
     11 #include "test_utils.h"
     12 #include "utest.h"
     13 
     14 struct gemini_refs {
     15   int dummy;
     16 };
     17 
     18 UTEST_F_SETUP(gemini_refs) {
     19   inmemory_fs_clear();
     20 }
     21 
     22 UTEST_F_TEARDOWN(gemini_refs) {}
     23 
     24 UTEST_F(gemini_refs, branches) {
     25   GitRepo repo = {.short_name = "test-repo"};
     26   GeminiRefs* refs = gemini_refs_create(&repo, g_fs_inmemory);
     27   ASSERT_NE(NULL, refs);
     28 
     29   GitCommit commit = {
     30       .author_name = "User A",
     31       .author_time = 1702031400,
     32   };
     33   GitReference ref = {
     34       .type = kReftypeBranch,
     35       .shorthand = "main",
     36       .commit = &commit,
     37   };
     38 
     39   gemini_refs_begin(refs);
     40   gemini_refs_add_ref(refs, &ref);
     41   gemini_refs_end(refs);
     42   gemini_refs_free(refs);
     43 
     44   const char* buf = inmemory_fs_get_buffer("refs.gmi");
     45   ASSERT_NE(NULL, buf);
     46   EXPECT_STR_SEQUENCE(buf, "## Branches", "```", "Name", "Last commit date",
     47                       "Author", "main", "2023-12-08 10:30", "User A", "```");
     48   EXPECT_EQ(NULL, strstr(buf, "=> commit/"));
     49 }