gout

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

files_tests.c (1769B)


      1 #include "writer/gemini/files.h"
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 
      7 #include "fs_inmemory.h"
      8 #include "git/file.h"
      9 #include "git/repo.h"
     10 #include "test_utils.h"
     11 #include "utest.h"
     12 
     13 struct gemini_files {
     14   int dummy;
     15 };
     16 
     17 UTEST_F_SETUP(gemini_files) {
     18   inmemory_fs_clear();
     19 }
     20 
     21 UTEST_F_TEARDOWN(gemini_files) {}
     22 
     23 UTEST_F(gemini_files, basic) {
     24   GitRepo repo = {.short_name = "test-repo"};
     25   GeminiFiles* files = gemini_files_create(&repo, g_fs_inmemory);
     26   ASSERT_NE(NULL, files);
     27 
     28   GitFile f1 = {
     29       .type = kFileTypeFile,
     30       .mode = "-rw-r--r--",
     31       .display_path = "README.md",
     32       .repo_path = "README.md",
     33       .size_bytes = 100,
     34       .size_lines = 5,
     35   };
     36 
     37   gemini_files_begin(files);
     38   gemini_files_add_file(files, &f1);
     39   gemini_files_end(files);
     40   gemini_files_free(files);
     41 
     42   const char* buf = inmemory_fs_get_buffer("files.gmi");
     43   ASSERT_NE(NULL, buf);
     44   EXPECT_STR_SEQUENCE(buf, "=> file/README.md.gmi", "-rw-r--r--", "README.md",
     45                       "(5L)");
     46 }
     47 
     48 UTEST_F(gemini_files, percent_encoding) {
     49   GitRepo repo = {.short_name = "test-repo"};
     50   GeminiFiles* files = gemini_files_create(&repo, g_fs_inmemory);
     51 
     52   GitFile f1 = {
     53       .type = kFileTypeFile,
     54       .mode = "-rw-r--r--",
     55       .display_path = "path with spaces.txt",
     56       .repo_path = "path with spaces.txt",
     57       .size_bytes = 10,
     58       .size_lines = 1,
     59   };
     60 
     61   gemini_files_begin(files);
     62   gemini_files_add_file(files, &f1);
     63   gemini_files_end(files);
     64   gemini_files_free(files);
     65 
     66   const char* buf = inmemory_fs_get_buffer("files.gmi");
     67   ASSERT_NE(NULL, buf);
     68   /* "path with spaces.txt" -> "path%20with%20spaces.txt" */
     69   EXPECT_STR_SEQUENCE(buf, "=> file/path%20with%20spaces.txt.gmi",
     70                       "path with spaces.txt");
     71 }