RELEASE tests
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 19 Nov 2021 03:55:47 +0000 (19:55 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 19 Nov 2021 03:55:47 +0000 (19:55 -0800)
src/language/stats/matrix.c
tests/language/stats/matrix.at

index f79a1f8a094675a89b96b2c404818b6ec2fcc8c0..e7d3ae8e27f380facbf3a0105d029b287a940fb4 100644 (file)
@@ -3401,8 +3401,6 @@ struct matrix_cmd
         struct display_command
           {
             struct matrix_state *state;
-            bool dictionary;
-            bool status;
           }
         display;
 
@@ -4253,32 +4251,18 @@ matrix_parse_break (struct matrix_state *s)
 static struct matrix_cmd *
 matrix_parse_display (struct matrix_state *s)
 {
-  bool dictionary = false;
-  bool status = false;
-  while (lex_token (s->lexer) == T_ID)
+  while (lex_token (s->lexer) != T_ENDCMD)
     {
-      if (lex_match_id (s->lexer, "DICTIONARY"))
-        dictionary = true;
-      else if (lex_match_id (s->lexer, "STATUS"))
-        status = true;
-      else
+      if (!lex_match_id (s->lexer, "DICTIONARY")
+          && !lex_match_id (s->lexer, "STATUS"))
         {
           lex_error_expecting (s->lexer, "DICTIONARY", "STATUS");
           return NULL;
         }
     }
-  if (!dictionary && !status)
-    dictionary = status = true;
 
   struct matrix_cmd *cmd = xmalloc (sizeof *cmd);
-  *cmd = (struct matrix_cmd) {
-    .type = MCMD_DISPLAY,
-    .display = {
-      .state = s,
-      .dictionary = dictionary,
-      .status = status,
-    }
-  };
+  *cmd = (struct matrix_cmd) { .type = MCMD_DISPLAY, .display = { s } };
   return cmd;
 }
 
index 06b93749a59724b08949f9a0cfe97c79416533c2..d8998f6e87dfd8dddcd5048c7ad07609c9186092 100644 (file)
@@ -3989,4 +3989,82 @@ matrix.sps:55: error: MSAVE: Variable name VARNAME_ is reserved.
 
 matrix.sps:56: error: MSAVE: Variable name ROWTYPE_ is reserved.
 ])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - DISPLAY])
+AT_DATA([matrix-template.sps], [dnl
+MATRIX.
+COMPUTE a={1,2,3}.
+COMPUTE b={1;2;3}.
+COMPUTE c={T(b),a}.
+COMPUTE d={T(a),b}.
+command.
+END MATRIX.
+])
+for command in 'DISPLAY' 'DISPLAY DICTIONARY' 'DISPLAY STATUS'; do
+    sed "s/command/$command/" < matrix-template.sps > matrix.sps
+    AT_CHECK([pspp matrix.sps -O format=csv], [0], [dnl
+Table: Matrix Variables
+,Dimension,,Size (kB)
+,Rows,Columns,
+a,1,3,0
+b,3,1,0
+c,1,6,0
+d,3,2,0
+])
+done
+AT_CLEANUP
+
+AT_SETUP([MATRIX - DISPLAY - negative])
+AT_DATA([matrix.sps], [dnl
+MATRIX.
+DISPLAY !.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:2.9: error: DISPLAY: Syntax error at `!': expecting DICTIONARY or
+STATUS.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - RELEASE])
+AT_DATA([matrix.sps], [dnl
+MATRIX.
+COMPUTE x=1.
+PRINT x.
+RELEASE X.
+PRINT x.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+x
+  1
+
+matrix.sps:5: error: MATRIX: Uninitialized variable x used in expression.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - RELEASE - negative])
+AT_DATA([matrix.sps], [dnl
+MATRIX.
+RELEASE !.
+RELEASE x.
+COMPUTE x=1.
+RELEASE x, !.
+COMPUTE x=1.
+RELEASE x y.
+COMPUTE x=1.
+RELEASE x.
+RELEASE x.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:2.9: error: RELEASE: Syntax error at `!': expecting end of command.
+
+matrix.sps:3.9: error: RELEASE: Syntax error at `x': Variable name expected.
+
+matrix.sps:5.12: error: RELEASE: Syntax error at `!': expecting end of command.
+
+matrix.sps:7.11: error: RELEASE: Syntax error at `y': expecting end of command.
+])
 AT_CLEANUP
\ No newline at end of file