From aa663c3e57076c0b0285c199fcdbcfd40b8b5dd3 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 18 Nov 2021 19:55:47 -0800 Subject: [PATCH] RELEASE tests --- src/language/stats/matrix.c | 24 ++--------- tests/language/stats/matrix.at | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/src/language/stats/matrix.c b/src/language/stats/matrix.c index f79a1f8a09..e7d3ae8e27 100644 --- a/src/language/stats/matrix.c +++ b/src/language/stats/matrix.c @@ -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; } diff --git a/tests/language/stats/matrix.at b/tests/language/stats/matrix.at index 06b93749a5..d8998f6e87 100644 --- a/tests/language/stats/matrix.at +++ b/tests/language/stats/matrix.at @@ -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 -- 2.30.2