another test
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 19 Jun 2025 20:44:32 +0000 (13:44 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 19 Jun 2025 20:44:32 +0000 (13:44 -0700)
rust/pspp/src/sys/raw.rs
rust/pspp/src/sys/test.rs
rust/pspp/src/sys/testdata/multiple_response_sets_missing_space_after_c.expected [new file with mode: 0644]
rust/pspp/src/sys/testdata/multiple_response_sets_missing_space_after_c.sack [new file with mode: 0644]

index 2d10d651aee004892058dcd013187e5ce26693d3..de528388b6d0191175308d93e116cb824a819798 100644 (file)
@@ -223,8 +223,8 @@ pub enum Warning {
     #[error("Invalid multiple response type")]
     InvalidMultipleResponseType,
 
-    #[error("Syntax error in multiple response record")]
-    MultipleResponseSyntaxError,
+    #[error("Syntax error in multiple response record ({0})")]
+    MultipleResponseSyntaxError(&'static str),
 
     #[error("Syntax error parsing counted string (missing trailing space)")]
     CountedStringMissingSpace,
@@ -2217,13 +2217,15 @@ where
 impl MultipleResponseSet<RawString, RawString> {
     fn parse(input: &[u8]) -> Result<(Self, &[u8]), Warning> {
         let Some(equals) = input.iter().position(|&b| b == b'=') else {
-            return Err(Warning::MultipleResponseSyntaxError);
+            return Err(Warning::MultipleResponseSyntaxError("missing `=`"));
         };
         let (name, input) = input.split_at(equals);
         let input = input.strip_prefix(b"=").unwrap();
         let (mr_type, input) = MultipleResponseType::parse(input)?;
         let Some(input) = input.strip_prefix(b" ") else {
-            return Err(Warning::MultipleResponseSyntaxError);
+            return Err(Warning::MultipleResponseSyntaxError(
+                "missing space after multiple response type",
+            ));
         };
         let (label, mut input) = parse_counted_string(input)?;
         let mut vars = Vec::new();
@@ -2231,7 +2233,9 @@ impl MultipleResponseSet<RawString, RawString> {
             match input.split_first() {
                 Some((b' ', rest)) => {
                     let Some(length) = rest.iter().position(|b| b" \n".contains(b)) else {
-                        return Err(Warning::MultipleResponseSyntaxError);
+                        return Err(Warning::MultipleResponseSyntaxError(
+                            "missing variable name delimiter",
+                        ));
                     };
                     let (var, rest) = rest.split_at(length);
                     if !var.is_empty() {
@@ -2239,7 +2243,11 @@ impl MultipleResponseSet<RawString, RawString> {
                     }
                     input = rest;
                 }
-                _ => return Err(Warning::MultipleResponseSyntaxError),
+                _ => {
+                    return Err(Warning::MultipleResponseSyntaxError(
+                        "missing space preceding variable name",
+                    ))
+                }
             }
         }
         while input.first() == Some(&b'\n') {
index 93ed921471069fb62864df19104c4efa3b6ed18e..b449d059998bc59b6cc69463984bc3cb44b95836 100644 (file)
@@ -237,6 +237,11 @@ fn multiple_response_sets_bad_name() {
     test_sysfile("multiple_response_sets_bad_name");
 }
 
+#[test]
+fn multiple_response_sets_missing_space_after_c() {
+    test_sysfile("multiple_response_sets_missing_space_after_c");
+}
+
 /// Duplicate variable name handling negative test.
 ///
 /// SPSS-generated system file can contain duplicate variable names (see bug
diff --git a/rust/pspp/src/sys/testdata/multiple_response_sets_missing_space_after_c.expected b/rust/pspp/src/sys/testdata/multiple_response_sets_missing_space_after_c.expected
new file mode 100644 (file)
index 0000000..4fcc82f
--- /dev/null
@@ -0,0 +1,20 @@
+Syntax error in multiple response record (missing space after multiple response type)
+
+╭──────────────────────┬────────────────────────╮
+│       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        │              │
+╰────┴────────┴─────┴─────────────────┴─────┴─────┴─────────┴────────────┴────────────┴──────────────╯
diff --git a/rust/pspp/src/sys/testdata/multiple_response_sets_missing_space_after_c.sack b/rust/pspp/src/sys/testdata/multiple_response_sets_missing_space_after_c.sack
new file mode 100644 (file)
index 0000000..cfe7420
--- /dev/null
@@ -0,0 +1,14 @@
+# 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, no label or missing values.
+2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
+
+# Multiple response sets.
+7; 7; 1; COUNT("$a=Cx");
+
+# Character encoding record.
+7; 20; 1; 12; "windows-1252";
+
+999; 0;