Browse Source

Fix tests

Isaac Woods 5 years ago
parent
commit
eb6661d1de
3 changed files with 11 additions and 18 deletions
  1. 2 2
      aml_parser/src/lib.rs
  2. 8 13
      aml_parser/src/name_object.rs
  3. 1 3
      aml_parser/src/parser.rs

+ 2 - 2
aml_parser/src/lib.rs

@@ -67,8 +67,8 @@ pub enum AmlError {
     InvalidStringConstant,
     InvalidRegionSpace(u8),
     /// Error produced when none of the parsers in a `choice!` could parse the next part of the
-    /// stream. Contains the next two bytes to make debugging missing extended opcodes easier.
-    NoParsersCouldParse([u8; 2]),
+    /// stream.
+    NoParsersCouldParse,
 }
 
 #[derive(Debug)]

+ 8 - 13
aml_parser/src/name_object.rs

@@ -225,26 +225,21 @@ mod tests {
     fn test_name_path() {
         let mut context = AmlContext::new();
 
-        check_err!(name_path().parse(&[], &mut context), AmlError::UnexpectedEndOfStream, &[]);
-        check_ok!(name_path().parse(&[0x00], &mut context), String::from(""), &[]);
-        check_ok!(name_path().parse(&[0x00, 0x00], &mut context), String::from(""), &[0x00]);
-        // TODO: this failure is actually a symptom of `choice!` not working quite correctly. When
-        // the dual_name_path parser fails (this is one, but is too short), it carries on and then
-        // returns a confusing error: `UnexpectedByte(0x2e)`. Not sure how the best way to go about
-        // fixing that is.
-        //
-        // For now, we know about this corner case, so altering the unit-test for now.
+        check_err!(name_path().parse(&[], &mut context), AmlError::NoParsersCouldParse, &[]);
+        check_ok!(name_path().parse(&[0x00], &mut context), alloc::vec![], &[]);
+        check_ok!(name_path().parse(&[0x00, 0x00], &mut context), alloc::vec![], &[0x00]);
         check_err!(
             name_path().parse(&[0x2e, b'A'], &mut context),
-            AmlError::UnexpectedByte(0x2e),
-            // TODO: this is the correct error
-            // AmlError::UnexpectedEndOfStream,
+            AmlError::NoParsersCouldParse,
             &[0x2e, b'A']
         );
         check_ok!(
             name_path()
                 .parse(&[0x2e, b'A', b'B', b'C', b'D', b'E', b'_', b'F', b'G'], &mut context),
-            String::from("ABCDE_FG"),
+            alloc::vec![
+                NameComponent::Segment(NameSeg([b'A', b'B', b'C', b'D'])),
+                NameComponent::Segment(NameSeg([b'E', b'_', b'F', b'G']))
+            ],
             &[]
         );
     }

+ 1 - 3
aml_parser/src/parser.rs

@@ -399,9 +399,7 @@ pub(crate) fn emit_no_parsers_could_parse<'a, 'c, R>() -> impl Parser<'a, 'c, R>
 where
     'c: 'a,
 {
-    |input: &'a [u8], context| {
-        Err((input, context, AmlError::NoParsersCouldParse([input[0], input[1]])))
-    }
+    |input: &'a [u8], context| Err((input, context, AmlError::NoParsersCouldParse))
 }
 
 /// Takes a number of parsers, and tries to apply each one to the input in order. Returns the