From 13e7b33beb80d2d386c0625f851eb51c2fc41593 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 10 Jun 2025 13:26:30 -0700 Subject: [PATCH] negative tests --- rust/pspp/src/sys/test.rs | 24 +++++++++++++++++++ .../testdata/duplicate_variable_name.expected | 21 ++++++++++++++++ .../sys/testdata/duplicate_variable_name.sack | 13 ++++++++++ .../testdata/invalid_label_indicator.expected | 1 + .../sys/testdata/invalid_label_indicator.sack | 12 ++++++++++ .../invalid_missing_indicator.expected | 1 + .../testdata/invalid_missing_indicator.sack | 12 ++++++++++ .../invalid_missing_indicator2.expected | 1 + .../testdata/invalid_missing_indicator2.sack | 12 ++++++++++ 9 files changed, 97 insertions(+) create mode 100644 rust/pspp/src/sys/testdata/duplicate_variable_name.expected create mode 100644 rust/pspp/src/sys/testdata/duplicate_variable_name.sack create mode 100644 rust/pspp/src/sys/testdata/invalid_label_indicator.expected create mode 100644 rust/pspp/src/sys/testdata/invalid_label_indicator.sack create mode 100644 rust/pspp/src/sys/testdata/invalid_missing_indicator.expected create mode 100644 rust/pspp/src/sys/testdata/invalid_missing_indicator.sack create mode 100644 rust/pspp/src/sys/testdata/invalid_missing_indicator2.expected create mode 100644 rust/pspp/src/sys/testdata/invalid_missing_indicator2.sack diff --git a/rust/pspp/src/sys/test.rs b/rust/pspp/src/sys/test.rs index 03cb14eda7..978c10df63 100644 --- a/rust/pspp/src/sys/test.rs +++ b/rust/pspp/src/sys/test.rs @@ -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 index 0000000000..ac64a478c3 --- /dev/null +++ b/rust/pspp/src/sys/testdata/duplicate_variable_name.expected @@ -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 index 0000000000..8b086e5488 --- /dev/null +++ b/rust/pspp/src/sys/testdata/duplicate_variable_name.sack @@ -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 index 0000000000..7acd2b5989 --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_label_indicator.expected @@ -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 index 0000000000..372b45f6f2 --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_label_indicator.sack @@ -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 index 0000000000..6e19fb2f8c --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_missing_indicator.expected @@ -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 index 0000000000..29ee25ae0b --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_missing_indicator.sack @@ -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 index 0000000000..a1f7d8e99d --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_missing_indicator2.expected @@ -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 index 0000000000..b42ee63aaf --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_missing_indicator2.sack @@ -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; -- 2.30.2