Automatically infer variables' measurement level from format and data.
[pspp] / tests / data / sys-file.at
index 85ccfd8b495fb464030fd0e437f93fd853eca719..7b2e2084446ff3a7f193fd654572a0c7630d5ad9 100644 (file)
@@ -1,9 +1,28 @@
+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([system files])
 
 # Also tests that long variable names are preserved by SAVE and GET.
 AT_SETUP([write and read numeric data])
 AT_KEYWORDS([SAVE GET system file])
-AT_DATA([sysfile.sps], [dnl
+for variant in 'UNCOMPRESSED $FL2' 'ZCOMPRESSED $FL3'; do
+    set $variant
+    compression=$1 magic=$2
+    cat >sysfile.sps <<EOF
 DATA LIST LIST NOTABLE / variable001 * variable002 * variable003 * variable004 * .
 BEGIN DATA.
     1.00     1.00    1.0     2.00
@@ -16,14 +35,14 @@ BEGIN DATA.
     2.00     2.00    2.0     3.00
 END DATA.
 
-SAVE /OUTFILE='foo.sav'.
+SAVE/$compression /OUTFILE='foo.sav'.
 
 GET /FILE='foo.sav'.
 
 LIST.
-])
-AT_CHECK([pspp -o pspp.csv sysfile.sps])
-AT_CHECK([cat pspp.csv], [0], [dnl
+EOF
+    AT_CHECK([pspp -o pspp.csv sysfile.sps])
+    AT_CHECK([cat pspp.csv], [0], [dnl
 Table: Data List
 variable001,variable002,variable003,variable004
 1.00,1.00,1.00,2.00
@@ -35,6 +54,59 @@ variable001,variable002,variable003,variable004
 2.00,2.00,1.00,1.00
 2.00,2.00,2.00,3.00
 ])
+    AT_CHECK_UNQUOTED([dd if=foo.sav bs=1 count=4; echo], [0], [$magic
+], [ignore])
+done
+AT_CLEANUP
+
+AT_SETUP([write and read long string value labels and missing values])
+AT_KEYWORDS([SAVE GET system file])
+for variant in 'UNCOMPRESSED $FL2' 'ZCOMPRESSED $FL3'; do
+    set $variant
+    compression=$1 magic=$2
+    cat >sysfile.sps <<EOF
+DATA LIST LIST NOTABLE/s1 s2 s3 (a9).
+BEGIN DATA
+a b c
+END DATA.
+
+VALUE LABELS
+    /s1 'abc' 'First value label'
+       'abcdefgh' 'Second value label'
+       'abcdefghi' 'Third value label'
+    /s2 '0' 'Fourth value label'
+       '01234567' 'Fifth value label'
+       '012345678' 'Sixth value label'.
+
+MISSING VALUES
+     s1 ('0')
+    /s2 ('12' '123')
+    /s3 ('1234' '12345' '12345678').
+
+SAVE/$compression /OUTFILE='foo.sav'.
+GET /FILE='foo.sav'.
+DISPLAY DICTIONARY.
+EOF
+    AT_CHECK([pspp -o pspp.csv sysfile.sps])
+    AT_CHECK([cat pspp.csv], [0], [dnl
+Table: Variables
+Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
+s1,1,Nominal,Input,9,Left,A9,A9,"""0       """
+s2,2,Nominal,Input,9,Left,A9,A9,"""12      ""; ""123     """
+s3,3,Nominal,Input,9,Left,A9,A9,"""1234    ""; ""12345   ""; ""12345678"""
+
+Table: Value Labels
+Variable Value,,Label
+s1,abc,First value label
+,abcdefgh,Second value label
+,abcdefghi,Third value label
+s2,0,Fourth value label
+,01234567,Fifth value label
+,012345678,Sixth value label
+])
+    AT_CHECK_UNQUOTED([dd if=foo.sav bs=1 count=4; echo], [0], [$magic
+], [ignore])
+done
 AT_CLEANUP
 
 AT_SETUP([write and read compressed files])
@@ -195,21 +267,22 @@ LIST.
 ])
 AT_CHECK([pspp -o pspp.csv get.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-Variable,Label,,Position
-cont,continents of the world,,1
-size,sq km,,2
-pop,population,,3
-count,number of countries,,4
+Table: Variables
+Name,Position,Label
+cont,1,continents of the world
+size,2,sq km
+pop,3,population
+count,4,number of countries
 
 Table: Data List
 cont,size,pop,count
-Asia                            ,44579000,3.7E+009,44.00
-Africa                          ,30065000,7.8E+008,53.00
-North America                   ,24256000,4.8E+008,23.00
-South America                   ,17819000,3.4E+008,12.00
-Antarctica                      ,13209000,.00,.00
-Europe                          ,9938000,7.3E+008,46.00
-Australia/Oceania               ,7687000,31000000,14.00
+Asia,44579000,3.7E+009,44.00
+Africa,30065000,7.8E+008,53.00
+North America,24256000,4.8E+008,23.00
+South America,17819000,3.4E+008,12.00
+Antarctica,13209000,.00,.00
+Europe,9938000,7.3E+008,46.00
+Australia/Oceania,7687000,31000000,14.00
 ])
 AT_CLEANUP
 
@@ -257,29 +330,18 @@ AT_BANNER([system files -- very long strings])
 AT_SETUP([read very long strings written by SPSS 13])
 AT_CHECK([cp $top_srcdir/tests/data/v13.sav .])
 AT_DATA([sys-file.sps], [dnl
-GET FILE='v13.sav'.
+GET FILE='v13.sav' ENCODING='utf-8'.
 DISPLAY VARIABLES.
 LIST.
 ])
 AT_CHECK([pspp -o pspp.csv sys-file.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-Variable,Description,,Position
-N,Format: F8.2,,1
-,Measure: Scale,,
-,Display Alignment: Right,,
-,Display Width: 10,,
-A255,Format: A255,,2
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 32,,
-A258,Format: A258,,3
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 32,,
-A2000,Format: A2000,,4
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 32,,
+Table: Variables
+Name,Position,Print Format,Write Format
+N,1,F8.2,F8.2
+A255,2,A255,A255
+A258,3,A258,A258
+A2000,4,A2000,A2000
 
 Table: Data List
 N,A255,A258,A2000
@@ -291,29 +353,18 @@ AT_CLEANUP
 AT_SETUP([read very long strings written by SPSS 14])
 AT_CHECK([cp $top_srcdir/tests/data/v14.sav .])
 AT_DATA([sys-file.sps], [dnl
-GET FILE='v14.sav'.
+GET FILE='v14.sav' ENCODING='utf-8'.
 DISPLAY VARIABLES.
 LIST.
 ])
 AT_CHECK([pspp -o pspp.csv sys-file.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-Variable,Description,,Position
-vl255,Format: A255,,1
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 26,,
-vl256,Format: A256,,2
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 26,,
-vl1335,Format: A1335,,3
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 26,,
-vl2000,Format: A2000,,4
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 26,,
+Table: Variables
+Name,Position,Print Format,Write Format
+vl255,1,A255,A255
+vl256,2,A256,A256
+vl1335,3,A1335,A1335
+vl2000,4,A2000,A2000
 
 Table: Data List
 vl255,vl256,vl1335,vl2000
@@ -335,9 +386,9 @@ m4_define([VLS_WRITE],
    vls_gen_data
    AT_DATA([save.sps], [dnl
 DATA LIST FIXED NOTABLE FILE='data.txt'
-    /a 2-11 (a) 
-     b (a256) 
-     c (a200) 
+    /a 2-11 (a)
+     b (a256)
+     c (a200)
      d (a32767).
 
 SAVE OUTFILE='foo.sav' /$1.
@@ -349,7 +400,7 @@ GET FILE='foo.sav'.
 DISPLAY VARIABLES.
 
 PRINT OUTFILE='out.txt'
-       /a (a10) b (a256) c (a200) 
+       /a (a10) b (a256) c (a200)
        d (a32767)
        .
 
@@ -357,23 +408,12 @@ EXECUTE.
 ])
    AT_CHECK([pspp -o pspp.csv get.sps])
    AT_CHECK([cat pspp.csv], [0], [dnl
-Variable,Description,,Position
-a,Format: A10,,1
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 10,,
-b,Format: A256,,2
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 32,,
-c,Format: A200,,3
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 32,,
-d,Format: A32767,,4
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 32,,
+Table: Variables
+Name,Position,Print Format,Write Format
+a,1,A10,A10
+b,2,A256,A256
+c,3,A200,A200
+d,4,A32767,A32767
 ])
    AT_CLEANUP])
 
@@ -415,42 +455,33 @@ GET FILE='foo.sav'.
 DISPLAY FILE LABEL.
 DISPLAY DOCUMENTS.
 DISPLAY DICTIONARY.
+DISPLAY ATTRIBUTES.
 ])
 AT_CHECK([pspp -o pspp.csv get.sps])
 AT_CHECK([[sed 's/(Entered [^)]*)/(Entered <date>)/' pspp.csv]], [0], [dnl
-File label: clientèle confrère cortège crèche
-
-Documents in the active dataset:
-
-DOCUMENT coördinate smörgåsbord
+Table: File Label
+Label,clientèle confrère cortège crèche
 
+Table: Documents
+"DOCUMENT coördinate smörgåsbord
 épée séance soufflé soirée
-
 jalapeño vicuña.
-
-(Entered <date>)
-
-Variable,Description,,Position
-àéîöçxyzabc,Format: F8.2,,1
-,Measure: Scale,,
-,Display Alignment: Right,,
-,Display Width: 8,,
-,1.00,éclair élan,
-,Custom attributes:,,
-,Atatürk,Düsseldorf Gewürztraminer,
-roué,Provençal soupçon,,2
-,Format: A9,,
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 9,,
-,abcdefghi,sauté précis,
-croûton,Format: A1000,,3
-,Measure: Nominal,,
-,Display Alignment: Left,,
-,Display Width: 32,,
-
-Table: Custom data file attributes.
-Attribute,Value
-Furtwängler,kindergärtner
+   (Entered <date>)"
+
+Table: Variables
+Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format
+àéîöçxyzabc,1,,Nominal,Input,8,Right,F8.2,F8.2
+roué,2,Provençal soupçon,Nominal,Input,9,Left,A9,A9
+croûton,3,,Nominal,Input,32,Left,A1000,A1000
+
+Table: Value Labels
+Variable Value,,Label
+àéîöçxyzabc,1.00,éclair élan
+Provençal soupçon,abcdefghi,sauté précis
+
+Table: Variable and Dataset Attributes
+Variable and Name,,Value
+(dataset),Furtwängler,kindergärtner
+àéîöçxyzabc,Atatürk,Düsseldorf Gewürztraminer
 ])
 AT_CLEANUP