MATRIX MGET negative tests
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 18 Nov 2021 01:34:20 +0000 (17:34 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 18 Nov 2021 01:34:20 +0000 (17:34 -0800)
src/language/stats/matrix.c
tests/language/stats/matrix.at

index a9690a42f101a04b112fb65f0976b8922da55812..ed43412a32075b6668f49f701372652e5e8c850e 100644 (file)
@@ -5731,7 +5731,7 @@ matrix_open_casereader (const char *command_name,
     {
       if (dict_get_var_cnt (dataset_dict (dataset)) == 0)
         {
-          msg (ME, _("The %s command cannot read empty active file."),
+          msg (ME, _("The %s command cannot read an empty active file."),
                command_name);
           return false;
         }
@@ -6179,6 +6179,7 @@ matrix_parse_mget (struct matrix_state *s)
 
   struct mget_command *mget = &cmd->mget;
 
+  lex_match (s->lexer, T_SLASH);
   while (lex_token (s->lexer) != T_ENDCMD)
     {
       if (lex_match_id (s->lexer, "FILE"))
@@ -6307,13 +6308,22 @@ matrix_mget_commit_var (struct ccase **rows, size_t n_rows,
                                     rowtype.string, rowtype.length))
     goto exit;
 
+  const char *prefix = (ss_equals_case (rowtype, ss_cstr ("COV")) ? "CV"
+                        : ss_equals_case (rowtype, ss_cstr ("CORR")) ? "CR"
+                        : ss_equals_case (rowtype, ss_cstr ("MEAN")) ? "MN"
+                        : ss_equals_case (rowtype, ss_cstr ("STDDEV")) ? "SD"
+                        : ss_equals_case (rowtype, ss_cstr ("N")) ? "NC"
+                        : ss_equals_case (rowtype, ss_cstr ("COUNT")) ? "CN"
+                        : NULL);
+  if (!prefix)
+    {
+      msg (SE, _("Matrix data file contains unknown ROWTYPE_ \"%.*s\"."),
+           (int) rowtype.length, rowtype.string);
+      goto exit;
+    }
+
   struct string name = DS_EMPTY_INITIALIZER;
-  ds_put_cstr (&name, (ss_equals_case (rowtype, ss_cstr ("COV")) ? "CV"
-                       : ss_equals_case (rowtype, ss_cstr ("CORR")) ? "CR"
-                       : ss_equals_case (rowtype, ss_cstr ("MEAN")) ? "MN"
-                       : ss_equals_case (rowtype, ss_cstr ("STDDEV")) ? "SD"
-                       : ss_equals_case (rowtype, ss_cstr ("N")) ? "NC"
-                       : "CN"));
+  ds_put_cstr (&name, prefix);
   if (!pooled)
     ds_put_format (&name, "F%zu", fi);
   if (si > 0)
index b8e3edaad349b462ba5ebba143d01495b64eb976..46925189652117f714274d1e09b429bf96acd9e7 100644 (file)
@@ -325,7 +325,7 @@ matrix.sps:17: error: MATRIX: Matrix row index must be scalar or vector, not a
 
 matrix.sps:18: error: MATRIX: Matrix column index must be scalar or vector, not
 a 2×2 matrix.
+
 x
   1  2  3
   4  5  6
@@ -2413,7 +2413,7 @@ END LOOP.
 
 LOOP i={} TO 5.
 END LOOP.
-        
+
 LOOP i=5 TO {}.
 END LOOP.
 
@@ -3093,7 +3093,7 @@ matrix.sps:24: warning: MATRIX: d is not a numeric variable.
 
 matrix.sps:25: error: MATRIX: GET: Variable d is not numeric.
 
-error: GET cannot read empty active file.
+error: The GET command cannot read an empty active file.
 ])
 AT_CLEANUP
 
@@ -3517,7 +3517,7 @@ SAVE OUTFILE='matrix.sav'.
 ])
 AT_DATA([matrix2.sps], [dnl
 MATRIX.
-MGET FILE='matrix.sav'/TYPE=CORR.
+MGET/FILE='matrix.sav'/TYPE=CORR.
 PRINT CR/FORMAT=F3.1.
 END MATRIX.
 ])
@@ -3536,3 +3536,187 @@ CR
 ])
 AT_CLEANUP
 
+AT_SETUP([MATRIX - MGET - negative - parsing])
+AT_DATA([matrix.sps], [dnl
+MATRIX.
+MGET !.
+MGET FILE=!.
+MGET ENCODING=!.
+MGET TYPE=!.
+MGET TYPE=CORR !.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:2.6: error: MGET: Syntax error at `!': expecting FILE or TYPE.
+
+matrix.sps:3.11: error: MGET: Syntax error at `!': expecting a file name or
+handle name.
+
+matrix.sps:4.15: error: MGET: Syntax error at `!': expecting string.
+
+matrix.sps:5.11: error: MGET: Syntax error at `!': expecting COV, CORR, MEAN,
+STDDEV, N, or COUNT.
+
+matrix.sps:6.16: error: MGET: Syntax error at `!': expecting COV, CORR, MEAN,
+STDDEV, N, or COUNT.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - missing VARNAME_ and ROWTYPE_])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /x.
+BEGIN DATA.
+1
+END DATA.
+
+MATRIX.
+MGET.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:7: error: MATRIX: Matrix data file lacks ROWTYPE_ variable.
+
+matrix.sps:7: error: MATRIX: Matrix data file lacks VARNAME_ variable.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - wrong format for VARNAME_ and ROWTYPE_])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /VARNAME_ * ROWTYPE_ (A7).
+BEGIN DATA.
+1 asdf
+END DATA.
+
+MATRIX.
+MGET.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:7: error: MATRIX: ROWTYPE_ variable in matrix data file must be 8-
+byte string, but it has width 7.
+
+matrix.sps:7: error: MATRIX: VARNAME_ variable in matrix data file must be 8-
+byte string, but it has width 0.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - wrong order for VARNAME_ and ROWTYPE_])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /VARNAME_ ROWTYPE_ (A8).
+BEGIN DATA.
+asdf jkl;
+END DATA.
+
+MATRIX.
+MGET.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:7: error: MATRIX: ROWTYPE_ must precede VARNAME_ in matrix data
+file.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - no continuous variables])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /ROWTYPE_ VARNAME_ (A8).
+BEGIN DATA.
+asdf jkl;
+END DATA.
+
+MATRIX.
+MGET.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:7: error: MATRIX: Matrix data file contains no continuous variables.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - unexpected string variables])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /ROWTYPE_ VARNAME_ cvar1 (A8).
+BEGIN DATA.
+asdf jkl; zxcv
+END DATA.
+
+MATRIX.
+MGET.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:7: error: MATRIX: Matrix data file contains unexpected string
+variable cvar1.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - unknown ROWTYPE_])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /ROWTYPE_ VARNAME_ (A8) cvar1.
+BEGIN DATA.
+asdf jkl; 1
+END DATA.
+
+MATRIX.
+MGET.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps -O format=csv], [1], [dnl
+"matrix.sps:7: error: MATRIX: Matrix data file contains unknown ROWTYPE_ ""asdf""."
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - duplicate matrix variable name])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /ROWTYPE_ VARNAME_ (A8) cvar1.
+BEGIN DATA.
+corr jkl; 1
+END DATA.
+
+MATRIX.
+MGET.
+MGET.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps -O format=csv], [0], [dnl
+Table: Matrix Variables Created by MGET
+,Dimensions,
+,Rows,Columns
+CR,1,1
+
+matrix.sps:8: warning: MATRIX: Matrix data file contains variable with existing name CR.
+])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - MGET - missing values in input])
+AT_DATA([matrix.sps], [dnl
+DATA LIST LIST NOTABLE /s1 * ROWTYPE_ VARNAME_ (A8) cvar1 cvar2.
+BEGIN DATA.
+1 n "" 1 .
+2 n "" . .
+END DATA.
+
+MATRIX.
+MGET.
+PRINT ncs1/FORMAT=F5.
+PRINT ncs2/FORMAT=F5.
+END MATRIX.
+])
+AT_CHECK([pspp matrix.sps -O format=csv], [1], [dnl
+"matrix.sps:8: error: MATRIX: Matrix data file variable NCS1 contains a missing value, which was treated as zero."
+
+"matrix.sps:8: error: MATRIX: Matrix data file variable NCS2 contains 2 missing values, which were treated as zero."
+
+Table: Matrix Variables Created by MGET
+,Split Values,Dimensions,
+,s1,Rows,Columns
+NCS1,1.00,1,2
+NCS2,2.00,1,2
+
+ncs1
+1     0
+
+ncs2
+0     0
+])
+AT_CLEANUP