#[error("{0}")]
InvalidRole(InvalidRole),
+ #[error("File header claims {expected} variable positions but {actual} were read from file.")]
+ WrongVariablePositions { actual: usize, expected: usize },
+
#[error("Details TBD (cooked)")]
TBD,
}
// XXX warn for weird integer format
// XXX warn for weird floating-point format, etc.
+ if let Some(nominal_case_size) = headers.header.nominal_case_size {
+ let n_vars = headers.variable.len();
+ if n_vars != nominal_case_size as usize
+ && headers
+ .integer_info
+ .as_ref()
+ .is_none_or(|info| info.version.0 != 13)
+ {
+ warn(Error::WrongVariablePositions {
+ actual: n_vars,
+ expected: nominal_case_size as usize,
+ });
+ }
+ }
+
let mut decoder = Decoder {
encoding,
n_generated_names: 0,
let layout_code = endian.parse(layout_code);
let nominal_case_size: u32 = endian.parse(read_bytes(r)?);
- let nominal_case_size =
- (nominal_case_size <= i32::MAX as u32 / 16).then_some(nominal_case_size);
+ let nominal_case_size = (1..i32::MAX as u32 / 16)
+ .contains(&nominal_case_size)
+ .then_some(nominal_case_size);
let compression_code: u32 = endian.parse(read_bytes(r)?);
let compression = match (magic, compression_code) {
test_sysfile("misplaced_type_4_record");
}
+#[test]
+fn bad_record_type() {
+ test_sysfile("bad_record_type");
+}
+
+#[test]
+fn wrong_variable_positions() {
+ test_sysfile("wrong_variable_positions");
+}
+
fn test_sysfile(name: &str) {
let input_filename = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("src/sys/testdata")
--- /dev/null
+At offset 0xd4, unrecognized record type 8.
--- /dev/null
+# File header.
+"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
+2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;
+
+# Numeric variable.
+2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
+
+# Type 8 record (not a valid type).
+>>8<<;
--- /dev/null
+File header claims 2 variable positions but 1 were read from file.
+
+╭──────────────────────┬────────────────────────╮
+│ Created │ 01-JAN-2011 20:53:52│
+├──────────────────────┼────────────────────────┤
+│Writer Product │PSPP synthetic test file│
+├──────────────────────┼────────────────────────┤
+│ Compression │SAV │
+│ Number of Cases│Unknown │
+╰──────────────────────┴────────────────────────╯
+
+╭─────────┬─╮
+│Variables│1│
+╰─────────┴─╯
+
+╭────┬────────┬─────┬─────────────────┬─────┬─────┬─────────┬────────────┬────────────┬──────────────╮
+│ │Position│Label│Measurement Level│ Role│Width│Alignment│Print Format│Write Format│Missing Values│
+├────┼────────┼─────┼─────────────────┼─────┼─────┼─────────┼────────────┼────────────┼──────────────┤
+│num1│ 1│ │ │Input│ 8│Right │F8.0 │F8.0 │ │
+╰────┴────────┴─────┴─────────────────┴─────┴─────┴─────────┴────────────┴────────────┴──────────────╯
--- /dev/null
+# 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; 0; 0x050800 *2; s8 "NUM1";
+
+# Character encoding record.
+7; 20; 1; 12; "windows-1252";
+
+# End of dictionary.
+999; 0;