struct display_command
{
struct matrix_state *state;
- bool dictionary;
- bool status;
}
display;
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;
}
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