gout

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

refs_tests.c (2553B)


      1 #include "writer/gopher/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 gopher_refs {
     15   int dummy;
     16 };
     17 
     18 UTEST_F_SETUP(gopher_refs) {
     19   inmemory_fs_clear();
     20 }
     21 
     22 UTEST_F_TEARDOWN(gopher_refs) {}
     23 
     24 UTEST_F(gopher_refs, branches) {
     25   GitRepo repo = {.short_name = "test-repo"};
     26   GopherRefs* refs = gopher_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   gopher_refs_begin(refs);
     40   gopher_refs_add_ref(refs, &ref);
     41   gopher_refs_end(refs);
     42   gopher_refs_free(refs);
     43 
     44   const char* buf = inmemory_fs_get_buffer("refs.gph");
     45   ASSERT_NE(NULL, buf);
     46   EXPECT_STR_SEQUENCE(buf, "Branches", "Name", "Last commit date", "Author",
     47                       "main", "2023-12-08 10:30", "User A");
     48 }
     49 
     50 UTEST_F(gopher_refs, tags) {
     51   GitRepo repo = {.short_name = "test-repo"};
     52   GopherRefs* refs = gopher_refs_create(&repo, g_fs_inmemory);
     53   ASSERT_NE(NULL, refs);
     54 
     55   GitCommit commit = {
     56       .author_name = "User B",
     57       .author_time = 1702035000,
     58   };
     59   GitReference ref = {
     60       .type = kReftypeTag,
     61       .shorthand = "v1.0",
     62       .commit = &commit,
     63   };
     64 
     65   gopher_refs_begin(refs);
     66   gopher_refs_add_ref(refs, &ref);
     67   gopher_refs_end(refs);
     68   gopher_refs_free(refs);
     69 
     70   const char* buf = inmemory_fs_get_buffer("refs.gph");
     71   ASSERT_NE(NULL, buf);
     72   EXPECT_STR_SEQUENCE(buf, "Tags", "Name", "Last commit date", "Author", "v1.0",
     73                       "2023-12-08 11:30", "User B");
     74 }
     75 
     76 UTEST_F(gopher_refs, both) {
     77   GitRepo repo = {.short_name = "test-repo"};
     78   GopherRefs* refs = gopher_refs_create(&repo, g_fs_inmemory);
     79   ASSERT_NE(NULL, refs);
     80 
     81   GitCommit commit1 = {.author_name = "User 1", .author_time = 1000};
     82   GitReference branch = {
     83       .type = kReftypeBranch, .shorthand = "main", .commit = &commit1};
     84 
     85   GitCommit commit2 = {.author_name = "User 2", .author_time = 2000};
     86   GitReference tag = {
     87       .type = kReftypeTag, .shorthand = "v1", .commit = &commit2};
     88 
     89   gopher_refs_begin(refs);
     90   gopher_refs_add_ref(refs, &branch);
     91   gopher_refs_add_ref(refs, &tag);
     92   gopher_refs_end(refs);
     93   gopher_refs_free(refs);
     94 
     95   const char* buf = inmemory_fs_get_buffer("refs.gph");
     96   ASSERT_NE(NULL, buf);
     97   EXPECT_STR_SEQUENCE(buf, "Branches", "main", "Tags", "v1");
     98 }