negative tests
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 10 Jun 2025 20:26:30 +0000 (13:26 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 10 Jun 2025 20:26:30 +0000 (13:26 -0700)
rust/pspp/src/sys/test.rs
rust/pspp/src/sys/testdata/duplicate_variable_name.expected [new file with mode: 0644]
rust/pspp/src/sys/testdata/duplicate_variable_name.sack [new file with mode: 0644]
rust/pspp/src/sys/testdata/invalid_label_indicator.expected [new file with mode: 0644]
rust/pspp/src/sys/testdata/invalid_label_indicator.sack [new file with mode: 0644]
rust/pspp/src/sys/testdata/invalid_missing_indicator.expected [new file with mode: 0644]
rust/pspp/src/sys/testdata/invalid_missing_indicator.sack [new file with mode: 0644]
rust/pspp/src/sys/testdata/invalid_missing_indicator2.expected [new file with mode: 0644]
rust/pspp/src/sys/testdata/invalid_missing_indicator2.sack [new file with mode: 0644]

index 03cb14eda7dd97e0be665504dfd5fd5894a15fbf..978c10df6348115c8795a1e48367de9de64107e9 100644 (file)
@@ -142,6 +142,30 @@ fn invalid_variable_name() {
     test_sysfile("invalid_variable_name");
 }
 
+#[test]
+fn invalid_label_indicator() {
+    test_sysfile("invalid_label_indicator");
+}
+
+#[test]
+fn invalid_missing_indicator() {
+    test_sysfile("invalid_missing_indicator");
+}
+
+#[test]
+fn invalid_missing_indicator2() {
+    test_sysfile("invalid_missing_indicator2");
+}
+
+/// Duplicate variable name handling negative test.
+///
+/// SPSS-generated system file can contain duplicate variable names (see bug
+/// #41475).
+#[test]
+fn duplicate_variable_name() {
+    test_sysfile("duplicate_variable_name");
+}
+
 fn test_sysfile(name: &str) {
     let input_filename = Path::new(env!("CARGO_MANIFEST_DIR"))
         .join("src/sys/testdata")
diff --git a/rust/pspp/src/sys/testdata/duplicate_variable_name.expected b/rust/pspp/src/sys/testdata/duplicate_variable_name.expected
new file mode 100644 (file)
index 0000000..ac64a47
--- /dev/null
@@ -0,0 +1,21 @@
+Renaming variable with duplicate name VAR1 to VAR001.
+
+╭──────────────────────┬────────────────────────╮
+│       Created        │    01-JAN-2011 20:53:52│
+├──────────────────────┼────────────────────────┤
+│Writer Product        │PSPP synthetic test file│
+├──────────────────────┼────────────────────────┤
+│       Compression    │SAV                     │
+│       Number of Cases│Unknown                 │
+╰──────────────────────┴────────────────────────╯
+
+╭─────────┬─╮
+│Variables│2│
+╰─────────┴─╯
+
+╭──────┬────────┬─────┬─────────────────┬─────┬─────┬─────────┬────────────┬────────────┬──────────────╮
+│      │Position│Label│Measurement Level│ Role│Width│Alignment│Print Format│Write Format│Missing Values│
+├──────┼────────┼─────┼─────────────────┼─────┼─────┼─────────┼────────────┼────────────┼──────────────┤
+│var1  │       1│     │                 │Input│    8│Right    │F8.0        │F8.0        │              │
+│var001│       2│     │                 │Input│    8│Right    │F8.0        │F8.0        │              │
+╰──────┴────────┴─────┴─────────────────┴─────┴─────┴─────────┴────────────┴────────────┴──────────────╯
diff --git a/rust/pspp/src/sys/testdata/duplicate_variable_name.sack b/rust/pspp/src/sys/testdata/duplicate_variable_name.sack
new file mode 100644 (file)
index 0000000..8b086e5
--- /dev/null
@@ -0,0 +1,13 @@
+# File header.
+"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
+2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;
+
+# Numeric variables.
+2; 0; 0; 0; 0x050800 *2; s8 "VAR1";
+2; 0; 0; 0; 0x050800 *2; s8 "VAR1";
+
+# Character encoding record.
+7; 20; 1; 12; "windows-1252";
+
+# End of dictionary.
+999; 0;
diff --git a/rust/pspp/src/sys/testdata/invalid_label_indicator.expected b/rust/pspp/src/sys/testdata/invalid_label_indicator.expected
new file mode 100644 (file)
index 0000000..7acd2b5
--- /dev/null
@@ -0,0 +1 @@
+In variable record starting at offset 0xb4, variable label code 2 at offset 0xb8 is not 0 or 1.
diff --git a/rust/pspp/src/sys/testdata/invalid_label_indicator.sack b/rust/pspp/src/sys/testdata/invalid_label_indicator.sack
new file mode 100644 (file)
index 0000000..372b45f
--- /dev/null
@@ -0,0 +1,12 @@
+# File header.
+"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
+2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;
+
+# Numeric variable.
+2; 0; >>2<<; 0; 0x050800 *2; s8 "VAR1";
+
+# Character encoding record.
+7; 20; 1; 12; "windows-1252";
+
+# End of dictionary.
+999; 0;
diff --git a/rust/pspp/src/sys/testdata/invalid_missing_indicator.expected b/rust/pspp/src/sys/testdata/invalid_missing_indicator.expected
new file mode 100644 (file)
index 0000000..6e19fb2
--- /dev/null
@@ -0,0 +1 @@
+At offset 0xb4, missing value code (-1) is not -3, -2, 0, 1, 2, or 3.
diff --git a/rust/pspp/src/sys/testdata/invalid_missing_indicator.sack b/rust/pspp/src/sys/testdata/invalid_missing_indicator.sack
new file mode 100644 (file)
index 0000000..29ee25a
--- /dev/null
@@ -0,0 +1,12 @@
+# File header.
+"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
+2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;
+
+# Numeric variable.
+2; 0; 0; >>-1<<; 0x050800 *2; s8 "VAR1";
+
+# Character encoding record.
+7; 20; 1; 12; "windows-1252";
+
+# End of dictionary.
+999; 0;
diff --git a/rust/pspp/src/sys/testdata/invalid_missing_indicator2.expected b/rust/pspp/src/sys/testdata/invalid_missing_indicator2.expected
new file mode 100644 (file)
index 0000000..a1f7d8e
--- /dev/null
@@ -0,0 +1 @@
+At offset 0xb4, missing value code (4) is not -3, -2, 0, 1, 2, or 3.
diff --git a/rust/pspp/src/sys/testdata/invalid_missing_indicator2.sack b/rust/pspp/src/sys/testdata/invalid_missing_indicator2.sack
new file mode 100644 (file)
index 0000000..b42ee63
--- /dev/null
@@ -0,0 +1,12 @@
+# File header.
+"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
+2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;
+
+# String variable.
+2; 8; 0; >>4<<; 0x010800 *2; s8 "VAR1";
+
+# Character encoding record.
+7; 20; 1; 12; "windows-1252";
+
+# End of dictionary.
+999; 0;