start writing tests
[pspp] / src / language / stats / ctables.c
index 69c505c48624ec5ad096b09c67a1ed88a53ceb71..e043105ccb6d58f288179d7c0d0ddb5bd00c0f87 100644 (file)
@@ -4719,7 +4719,12 @@ ctables_check_label_position (struct ctables_table *t, enum pivot_axis_type a)
     return true;
 
   const struct ctables_nest *n0 = &stack->nests[0];
-  assert (n0->n > 0);
+  if (n0->n == 0)
+    {
+      assert (stack->n == 1);
+      return true;
+    }
+
   const struct variable *v0 = n0->vars[n0->n - 1];
   struct ctables_categories *c0 = t->categories[var_get_dict_index (v0)];
   t->clabels_example = v0;
@@ -4896,6 +4901,10 @@ ctables_prepare_table (struct ctables_table *t)
         struct ctables_nest *nest = xmalloc (sizeof *nest);
         *nest = (struct ctables_nest) { .n = 0 };
         t->stacks[a] = (struct ctables_stack) { .nests = nest, .n = 1 };
+
+        /* There's no point in moving labels away from an axis that has no
+           labels, so avoid dealing with the special cases around that. */
+        t->label_axis[a] = a;
       }
 
   struct ctables_stack *stack = &t->stacks[t->summary_axis];
@@ -6246,7 +6255,7 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds)
           if (!ct->e_weight)
             goto error;
         }
-      else if (lex_match_id (lexer, " HIDESMALLCOUNTS"))
+      else if (lex_match_id (lexer, "HIDESMALLCOUNTS"))
         {
           if (lex_match_id (lexer, "COUNT"))
             {
@@ -6443,46 +6452,45 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds)
             }
           else if (lex_match_id (lexer, "CLABELS"))
             {
-              while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
+              if (lex_match_id (lexer, "AUTO"))
                 {
-                  if (lex_match_id (lexer, "AUTO"))
-                    {
-                      t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_ROW;
-                      t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_COLUMN;
-                    }
-                  else if (lex_match_id (lexer, "ROWLABELS"))
-                    {
-                      lex_match (lexer, T_EQUALS);
-                      if (lex_match_id (lexer, "OPPOSITE"))
-                        t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_COLUMN;
-                      else if (lex_match_id (lexer, "LAYER"))
-                        t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_LAYER;
-                      else
-                        {
-                          lex_error_expecting (lexer, "OPPOSITE", "LAYER");
-                          goto error;
-                        }
-                    }
-                  else if (lex_match_id (lexer, "COLLABELS"))
+                  t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_ROW;
+                  t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_COLUMN;
+                }
+              else if (lex_match_id (lexer, "ROWLABELS"))
+                {
+                  lex_match (lexer, T_EQUALS);
+                  t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_COLUMN;
+                  if (lex_match_id (lexer, "OPPOSITE"))
+                    t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_COLUMN;
+                  else if (lex_match_id (lexer, "LAYER"))
+                    t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_LAYER;
+                  else
                     {
-                      lex_match (lexer, T_EQUALS);
-                      if (lex_match_id (lexer, "OPPOSITE"))
-                        t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_ROW;
-                      else if (lex_match_id (lexer, "LAYER"))
-                        t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_LAYER;
-                      else
-                        {
-                          lex_error_expecting (lexer, "OPPOSITE", "LAYER");
-                          goto error;
-                        }
+                      lex_error_expecting (lexer, "OPPOSITE", "LAYER");
+                      goto error;
                     }
+                }
+              else if (lex_match_id (lexer, "COLLABELS"))
+                {
+                  lex_match (lexer, T_EQUALS);
+                  t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_ROW;
+                  if (lex_match_id (lexer, "OPPOSITE"))
+                    t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_ROW;
+                  else if (lex_match_id (lexer, "LAYER"))
+                    t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_LAYER;
                   else
                     {
-                      lex_error_expecting (lexer, "AUTO", "ROWLABELS",
-                                           "COLLABELS");
+                      lex_error_expecting (lexer, "OPPOSITE", "LAYER");
                       goto error;
                     }
                 }
+              else
+                {
+                  lex_error_expecting (lexer, "AUTO", "ROWLABELS",
+                                       "COLLABELS");
+                  goto error;
+                }
             }
           else if (lex_match_id (lexer, "CRITERIA"))
             {