gout

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

refs_tests.c (2300B)


      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 }
     50 
     51 UTEST_F(gemini_refs, interleaved) {
     52   GitRepo repo = {.short_name = "test-repo"};
     53   GeminiRefs* refs = gemini_refs_create(&repo, g_fs_inmemory);
     54   ASSERT_NE(NULL, refs);
     55 
     56   GitCommit commit1 = {.author_name = "User 1", .author_time = 1000};
     57   GitReference branch1 = {
     58       .type = kReftypeBranch, .shorthand = "main", .commit = &commit1};
     59 
     60   GitCommit commit2 = {.author_name = "User 2", .author_time = 2000};
     61   GitReference tag = {
     62       .type = kReftypeTag, .shorthand = "v1", .commit = &commit2};
     63 
     64   GitCommit commit3 = {.author_name = "User 3", .author_time = 3000};
     65   GitReference branch2 = {
     66       .type = kReftypeBranch, .shorthand = "dev", .commit = &commit3};
     67 
     68   gemini_refs_begin(refs);
     69   gemini_refs_add_ref(refs, &branch1);
     70   gemini_refs_add_ref(refs, &tag);
     71   gemini_refs_add_ref(refs, &branch2);
     72   gemini_refs_end(refs);
     73   gemini_refs_free(refs);
     74 
     75   const char* buf = inmemory_fs_get_buffer("refs.gmi");
     76   ASSERT_NE(NULL, buf);
     77 
     78   // Expect all branches to be grouped under "Branches", and all tags under
     79   // "Tags", without duplicate "Branches" headers or formatting errors.
     80   EXPECT_STR_SEQUENCE(buf, "## Branches", "main", "dev", "## Tags", "v1");
     81 }