pivot-table: Add more tests for pivot table rendering.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Jan 2021 23:07:39 +0000 (15:07 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Jan 2021 23:08:02 +0000 (15:08 -0800)
tests/output/pivot-table-test.c
tests/output/pivot-table.at

index 41ff52445cc66753e7b2f8248fcbfabc4a388574..60053e9ba8a6234850543e52daf14e2c54e23082 100644 (file)
@@ -51,12 +51,9 @@ static char *box;
 /* -o, --output: Base name for output files. */
 static const char *output_base = "render";
 
-/* --dump: Print table dump to stdout? */
-static bool dump;
-
 static const char *parse_options (int argc, char **argv);
 static void usage (void) NO_RETURN;
-static struct pivot_table *read_table (struct lexer *);
+static void read_table (struct lexer *);
 static void output_msg (const struct msg *, void *);
 
 int
@@ -89,10 +86,7 @@ main (int argc, char **argv)
       if (lex_match (lexer, T_STOP))
         break;
 
-      struct pivot_table *pt = read_table (lexer);
-      if (dump)
-        pivot_table_dump (pt, 0);
-      pivot_table_submit (pt);
+      read_table (lexer);
     }
 
   lex_destroy (lexer);
@@ -146,7 +140,12 @@ configure_drivers (int width, int length UNUSED, int min_break)
   register_driver (&options, "%s.pdf", output_base);
 #endif
 
+  string_map_insert (&options, "box", "unicode");
   register_driver (&options, "%s.txt", output_base);
+
+  string_map_insert (&options, "box", "ascii");
+  register_driver (&options, "%s-ascii.txt", output_base);
+
   register_driver (&options, "%s.csv", output_base);
   register_driver (&options, "%s.odt", output_base);
   register_driver (&options, "%s.spv", output_base);
@@ -172,7 +171,6 @@ parse_options (int argc, char **argv)
         OPT_EMPHASIS,
         OPT_BOX,
         OPT_TABLE_LOOK,
-        OPT_DUMP,
         OPT_HELP
       };
       static const struct option options[] =
@@ -184,7 +182,6 @@ parse_options (int argc, char **argv)
           {"box", required_argument, NULL, OPT_BOX},
           {"output", required_argument, NULL, 'o'},
           {"table-look", required_argument, NULL, OPT_TABLE_LOOK},
-          {"dump", no_argument, NULL, OPT_DUMP},
           {"help", no_argument, NULL, OPT_HELP},
           {NULL, 0, NULL, 0},
         };
@@ -230,10 +227,6 @@ parse_options (int argc, char **argv)
           }
           break;
 
-        case OPT_DUMP:
-          dump = true;
-          break;
-
         case OPT_HELP:
           usage ();
 
@@ -1129,13 +1122,16 @@ read_current_layer (struct lexer *lexer, struct pivot_table *table)
     }
 }
 
-static struct pivot_table *
+static void
 read_table (struct lexer *lexer)
 {
+  bool displayed = false;
+
   struct pivot_table *pt = pivot_table_create ("Default Title");
   while (lex_match (lexer, T_SLASH))
     {
       assert (!pivot_table_is_shared (pt));
+      displayed = false;
 
       if (lex_match_id (lexer, "ROW"))
         read_dimension (lexer, pt, PIVOT_AXIS_ROW,
@@ -1212,6 +1208,7 @@ read_table (struct lexer *lexer)
         {
           pivot_table_submit (pivot_table_ref (pt));
           pt = pivot_table_unshare (pt);
+          displayed = true;
         }
       else
         {
@@ -1220,8 +1217,12 @@ read_table (struct lexer *lexer)
         }
     }
 
+  if (!displayed)
+    pivot_table_submit (pt);
+  else
+    pivot_table_unshare (pt);
+
   force_match (lexer, T_ENDCMD);
-  return pt;
 }
 
 static void
index 4540274b777f1fb23850e5c18fb82329b6bc071f..bc66c828f421d639031b75ee8cb243ad7d834f7a 100644 (file)
@@ -400,3 +400,142 @@ b: b3
 ╰──┴──┴──╯
 ])
 AT_CLEANUP
+
+AT_SETUP([pivot table title and caption])
+AT_DATA([pivot.txt], [[
+/col "a"("a1", "a2")
+/row "b"("b1", "b2")
+/cell[all, all]
+/title "Title + Caption" /caption "Title + Caption" /display
+/title "Title Only" /caption "(Not Shown)" /show title=yes caption=no /display
+/title "(Not Shown)" /caption "Caption Only" /show title=no caption=yes /display
+/title "(Not Shown)" /caption "(Not Shown)" /show title=no caption=no
+]])
+AT_CHECK([pivot-table-test --table-look $srcdir/output/look.stt pivot.txt --box unicode], [0], [dnl
+Title + Caption
+╭──┬──┬──╮
+│  │a1│a2│
+├──┼──┼──┤
+│b1│ 0│ 1│
+│b2│ 2│ 3│
+╰──┴──┴──╯
+Title + Caption
+
+Title Only
+╭──┬──┬──╮
+│  │a1│a2│
+├──┼──┼──┤
+│b1│ 0│ 1│
+│b2│ 2│ 3│
+╰──┴──┴──╯
+
+╭──┬──┬──╮
+│  │a1│a2│
+├──┼──┼──┤
+│b1│ 0│ 1│
+│b2│ 2│ 3│
+╰──┴──┴──╯
+Caption Only
+
+╭──┬──┬──╮
+│  │a1│a2│
+├──┼──┼──┤
+│b1│ 0│ 1│
+│b2│ 2│ 3│
+╰──┴──┴──╯
+])
+AT_CLEANUP
+
+AT_SETUP([pivot table with no dimensions])
+AT_DATA([pivot.txt], [[
+/title "No Dimensions"
+]])
+AT_CHECK([pivot-table-test --table-look $srcdir/output/look.stt pivot.txt --box unicode], [0], [dnl
+No Dimensions
+╭╮
+╰╯
+])
+AT_CLEANUP
+
+AT_SETUP([pivot table with empty dimensions])
+AT_DATA([pivot.txt], [[
+/col "a"()
+/look empty=show
+/title "One Empty Dimension" /display
+/title "Two Empty Dimensions" /row "b"*() /display
+/title "Three Dimensions, Two Empty" /row "c"("c1", "c2")
+]])
+AT_CHECK([pivot-table-test --table-look $srcdir/output/look.stt pivot.txt --box unicode], [0], [dnl
+One Empty Dimension
+
+Two Empty Dimensions
+
+Three Dimensions, Two Empty
+])
+AT_CLEANUP
+
+AT_SETUP([pivot table with empty groups])
+AT_DATA([pivot.txt], [[
+/col "a"("a1", "a2"(), "a3")
+/row "b"("b1"(), "b2", "b3")
+/cell[all,all]
+/look empty=show
+/display
+]])
+AT_CHECK([pivot-table-test --table-look $srcdir/output/look.stt pivot.txt --box unicode], [0], [dnl
+Default Title
+╭──┬──┬──╮
+│  │a1│a3│
+├──┼──┼──┤
+│b2│ 0│ 1│
+│b3│ 2│ 3│
+╰──┴──┴──╯
+])
+AT_CLEANUP
+
+AT_SETUP([pivot table - category and dimension borders])
+AT_DATA([pivot.txt], [[
+/col "a"("a1", "ag1"("a2", "a3"))
+/col "b"("bg1"("b1", "b2"), "b3")
+/row "c"("c1", "cg1"("c2", "c3"))
+/row "d"("dg1"("d1", "d2"), "d3")
+/cell[all, all, all, all]
+/border "*" (none)
+/border "dim-row-horz" (solid "blue")
+       "cat-row-horz" (dashed "red")
+       "dim-row-vert" (solid "blue")
+       "cat-row-vert" (dashed "red")
+       "dim-col-horz" (solid "blue")
+       "cat-col-horz" (dashed "red")
+       "dim-col-vert" (solid "blue")
+       "cat-col-vert" (dashed "red")
+/title "Category and Dimension Borders"
+]])
+AT_CHECK([pivot-table-test --table-look $srcdir/output/look.stt pivot.txt --box unicode], [0], [dnl
+Category and Dimension Borders
+                     bg1       │
+             ╶╌╌╌╌╌╌╌╌┬╌╌╌╌╌╌╌╌┤
+                 b1   │   b2   │   b3
+             ╶──┬─────┼──┬─────┼──┬─────
+                │ ag1 │  │ ag1 │  │ ag1
+                ├╌╌┬╌╌┤  ├╌╌┬╌╌┤  ├╌╌┬╌╌
+              a1│a2┊a3│a1│a2┊a3│a1│a2┊a3
+dg1┊d1│c1      0│ 1┊ 2│ 3│ 4┊ 5│ 6│ 7┊ 8
+   ┊  ├───┬─────┼──┼──┼──┼──┼──┼──┼──┼──
+   ┊  │cg1┊c2  9│10┊11│12│13┊14│15│16┊17
+   ┊  │   ├╌╌╌╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌
+   ┊  │   ┊c3 18│19┊20│21│22┊23│24│25┊26
+   ├──┼───┴─────┼──┼──┼──┼──┼──┼──┼──┼──
+   ┊d2│c1     27│28┊29│30│31┊32│33│34┊35
+   ┊  ├───┬─────┼──┼──┼──┼──┼──┼──┼──┼──
+   ┊  │cg1┊c2 36│37┊38│39│40┊41│42│43┊44
+   ┊  │   ├╌╌╌╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌
+   ┊  │   ┊c3 45│46┊47│48│49┊50│51│52┊53
+───┴──┼───┴─────┼──┼──┼──┼──┼──┼──┼──┼──
+d3    │c1     54│55┊56│57│58┊59│60│61┊62
+      ├───┬─────┼──┼──┼──┼──┼──┼──┼──┼──
+      │cg1┊c2 63│64┊65│66│67┊68│69│70┊71
+      │   ├╌╌╌╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌
+      │   ┊c3 72│73┊74│75│76┊77│78│79┊80
+])
+AT_CLEANUP