Move all command implementations into a single 'commands' directory.
[pspp] / tests / language / commands / missing-values.at
diff --git a/tests/language/commands/missing-values.at b/tests/language/commands/missing-values.at
new file mode 100644 (file)
index 0000000..541a4ca
--- /dev/null
@@ -0,0 +1,240 @@
+dnl PSPP - a program for statistical analysis.
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl
+dnl This program is free software: you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation, either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
+dnl
+AT_BANNER([MISSING VALUES])
+
+AT_SETUP([MISSING VALUES valid cases])
+AT_DATA([missing-values.sps], [dnl
+DATA LIST NOTABLE/str1 1-5 (A) str2 6-8 (A) date1 9-19 (DATE) num1 20-25
+                  longstr 26-36 (A).
+
+* Numeric missing values.
+MISSING VALUES date1 num1 (1).
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES date1 num1 (1, 2).
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES date1 num1 (1, 2, 3).
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES date1 num1 (9999998, 9999984, 3).
+DISPLAY DICTIONARY date1 num1.
+
+* Numeric missing values using the first variable's format.
+MISSING VALUES num1 date1 ('1').
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES num1 date1 ('1', '2').
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES num1 date1 ('1', '2', '3').
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES date1 num1 ('06-AUG-05').
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES date1 num1 ('06-AUG-05', '01-OCT-78').
+DISPLAY DICTIONARY date1 num1.
+MISSING VALUES date1 num1 ('06-AUG-05', '01-OCT-78', '14-FEB-81').
+DISPLAY DICTIONARY date1 num1.
+
+* Ranges of numeric missing values.
+MISSING VALUES num1 (1 THRU 2).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (LO THRU 2).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (LOWEST THRU 2).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (1 THRU HI).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (1 THRU HIGHEST).
+DISPLAY DICTIONARY num1.
+
+* A range of numeric missing values, plus an individual value.
+MISSING VALUES num1 (1 THRU 2, 3).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (LO THRU 2, 3).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (LOWEST THRU 2, 3).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (1 THRU HI, -1).
+DISPLAY DICTIONARY num1.
+MISSING VALUES num1 (1 THRU HIGHEST, -1).
+DISPLAY DICTIONARY num1.
+
+* String missing values.
+MISSING VALUES str1 str2 longstr ('abc  ','def').
+DISPLAY DICTIONARY str1 str2 longstr.
+
+* May mix variable types when clearing missing values.
+MISSING VALUES ALL ().
+MISSING VALUES num1 (1).
+DISPLAY DICTIONARY
+])
+AT_CHECK([pspp -o pspp.csv missing-values.sps])
+AT_CHECK([cat pspp.csv | sed '/^Table/d
+/^Name/d
+s/^\([[a-z0-9]]*\),.*,\([[^,]]*\)$/\1: \2/'], [0], [dnl
+date1: 1
+num1: 1
+
+date1: 1; 2
+num1: 1; 2
+
+date1: 1; 2; 3
+num1: 1; 2; 3
+
+date1: 9999998; 9999984; 3
+num1: 9999998; 9999984; 3
+
+date1: 1
+num1: 1
+
+date1: 1; 2
+num1: 1; 2
+
+date1: 1; 2; 3
+num1: 1; 2; 3
+
+date1: 13342665600
+num1: 13342665600
+
+date1: 13342665600; 12495427200
+num1: 13342665600; 12495427200
+
+date1: 13342665600; 12495427200; 12570336000
+num1: 13342665600; 12495427200; 12570336000
+
+num1: 1 THRU 2
+
+num1: LOWEST THRU 2
+
+num1: LOWEST THRU 2
+
+num1: 1 THRU HIGHEST
+
+num1: 1 THRU HIGHEST
+
+num1: 1 THRU 2; 3
+
+num1: LOWEST THRU 2; 3
+
+num1: LOWEST THRU 2; 3
+
+num1: 1 THRU HIGHEST; -1
+
+num1: 1 THRU HIGHEST; -1
+
+str1: """abc  ""; ""def  """
+str2: """abc""; ""def"""
+longstr: """abc     ""; ""def     """
+
+str1: @&t@
+str2: @&t@
+date1: @&t@
+num1: 1
+longstr: @&t@
+])
+AT_CLEANUP
+
+AT_SETUP([MISSING VALUES invalid cases])
+AT_DATA([missing-values.sps], [dnl
+DATA LIST NOTABLE/str1 1-5 (A) str2 6-8 (A) date1 9-19 (DATE) num1 20-25
+                  longstr 26-36 (A).
+
+* Too long for str2.
+MISSING VALUES str1 str2 longstr ('abcde').
+
+* Long string missing value longer than 8 bytes.
+MISSING VALUES longstr ('abcdefghijk').
+
+* No string ranges.
+MISSING VALUES str1 ('a' THRU 'z').
+
+* Mixing string and numeric variables.
+MISSING VALUES str1 num1 ('123').
+
+* Too many values.
+MISSING VALUES num1 (1, 2, 3, 4).
+MISSING VALUES num1 (1 THRU 2, 3 THRU 4).
+MISSING VALUES num1 (1, 2 THRU 3, 4).
+MISSING VALUES str1 ('abc', 'def', 'ghi', 'jkl').
+
+* Bad range.
+MISSING VALUES num1 (2 THRU 1).
+])
+AT_CHECK([pspp -O format=csv missing-values.sps], [1], [dnl
+"missing-values.sps:5.35-5.41: error: MISSING VALUES: Missing values are too long to assign to variable str2 with width 3.
+    5 | MISSING VALUES str1 str2 longstr ('abcde').
+      |                                   ^~~~~~~"
+
+"missing-values.sps:8.25-8.37: error: MISSING VALUES: Truncating missing value to maximum acceptable length (8 bytes).
+    8 | MISSING VALUES longstr ('abcdefghijk').
+      |                         ^~~~~~~~~~~~~"
+
+"missing-values.sps:11.26-11.29: error: MISSING VALUES: Syntax error expecting string.
+   11 | MISSING VALUES str1 ('a' THRU 'z').
+      |                          ^~~~"
+
+"missing-values.sps:14.27-14.31: error: MISSING VALUES: Cannot assign string missing values to numeric variable num1.
+   14 | MISSING VALUES str1 num1 ('123').
+      |                           ^~~~~"
+
+"missing-values.sps:17.22-17.31: error: MISSING VALUES: Too many numeric missing values.  At most three individual values or one value and one range are allowed.
+   17 | MISSING VALUES num1 (1, 2, 3, 4).
+      |                      ^~~~~~~~~~"
+
+"missing-values.sps:18.22-18.39: error: MISSING VALUES: Too many numeric missing values.  At most three individual values or one value and one range are allowed.
+   18 | MISSING VALUES num1 (1 THRU 2, 3 THRU 4).
+      |                      ^~~~~~~~~~~~~~~~~~"
+
+"missing-values.sps:19.22-19.35: error: MISSING VALUES: Too many numeric missing values.  At most three individual values or one value and one range are allowed.
+   19 | MISSING VALUES num1 (1, 2 THRU 3, 4).
+      |                      ^~~~~~~~~~~~~~"
+
+"missing-values.sps:20.22-20.47: error: MISSING VALUES: Too many string missing values.  At most three individual values are allowed.
+   20 | MISSING VALUES str1 ('abc', 'def', 'ghi', 'jkl').
+      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~"
+
+"missing-values.sps:23.22-23.29: warning: MISSING VALUES: The high end of the range (1) is below the low end (2).  The range will be treated as if reversed.
+   23 | MISSING VALUES num1 (2 THRU 1).
+      |                      ^~~~~~~~"
+])
+AT_CLEANUP
+
+AT_SETUP([MISSING VALUES syntax errors])
+AT_DATA([missing-values.sps], [dnl
+DATA LIST LIST NOTABLE/n1 to n10 (F8.2) s1 to s10 (A8).
+MISSING VALUES **.
+MISSING VALUES n1 **.
+MISSING VALUES s1 (1).
+MISSING VALUES n1 (1**).
+])
+AT_DATA([insert.sps], [dnl
+INSERT FILE='missing-values.sps' ERROR=IGNORE.
+])
+AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
+"missing-values.sps:2.16-2.17: error: MISSING VALUES: Syntax error expecting variable name.
+    2 | MISSING VALUES **.
+      |                ^~"
+
+"missing-values.sps:3.19-3.20: error: MISSING VALUES: Syntax error expecting `@{:@'.
+    3 | MISSING VALUES n1 **.
+      |                   ^~"
+
+"missing-values.sps:4.20: error: MISSING VALUES: Syntax error expecting string.
+    4 | MISSING VALUES s1 (1).
+      |                    ^"
+
+"missing-values.sps:5.21-5.22: error: MISSING VALUES: Syntax error expecting number.
+    5 | MISSING VALUES n1 (1**).
+      |                     ^~"
+])
+AT_CLEANUP
\ No newline at end of file