gout

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

delta_tests.c (994B)


      1 #include "git/delta.h"
      2 
      3 #include <stdlib.h>
      4 #include <string.h>
      5 
      6 #include "utest.h"
      7 
      8 // Ensure graph is scaled to the maximum width when linecount exceeds max_width.
      9 UTEST(delta, GraphScalingDoesNotExceedMaxWidth) {
     10   GitDelta delta = {
     11       .addcount = 50,
     12       .delcount = 50,
     13   };
     14   size_t max_width = 10;
     15   char* added = gitdelta_added_graph(&delta, max_width);
     16   char* deleted = gitdelta_deleted_graph(&delta, max_width);
     17   size_t total_len = strlen(added) + strlen(deleted);
     18   EXPECT_LE(total_len, max_width);
     19 
     20   free(added);
     21   free(deleted);
     22 }
     23 
     24 // For small changes where sum < max_width, we expect exact line counts.
     25 UTEST(delta, GraphScalingSmallChanges) {
     26   GitDelta delta = {
     27       .addcount = 1,
     28       .delcount = 1,
     29   };
     30   size_t max_width = 80;
     31   char* added = gitdelta_added_graph(&delta, max_width);
     32   char* deleted = gitdelta_deleted_graph(&delta, max_width);
     33   EXPECT_EQ((size_t)1, strlen(added));
     34   EXPECT_EQ((size_t)1, strlen(deleted));
     35 
     36   free(added);
     37   free(deleted);
     38 }