returning ScanError instead of running unreachable!()

fixes #23
This commit is contained in:
Hendrik Sollich 2016-06-21 21:50:27 +02:00 committed by Yuheng Chen
parent 77b90df939
commit 27e11273c1
2 changed files with 8 additions and 1 deletions

View file

@ -949,7 +949,7 @@ impl<T: Iterator<Item=char>> Scanner<T> {
self.roll_indent(mark.col, None, TokenType::BlockSequenceStart, mark); self.roll_indent(mark.col, None, TokenType::BlockSequenceStart, mark);
} else { } else {
// - * only allowed in block // - * only allowed in block
unreachable!(); return Err(ScanError::new(self.mark, r#""-" is only valid inside a block"#))
} }
try!(self.remove_simple_key()); try!(self.remove_simple_key());
self.allow_simple_key(); self.allow_simple_key();

View file

@ -469,4 +469,11 @@ a1: &DEFAULT
assert!(doc[25][0].as_bool().unwrap()); assert!(doc[25][0].as_bool().unwrap());
assert!(!doc[25][1].as_bool().unwrap()); assert!(!doc[25][1].as_bool().unwrap());
} }
#[test]
fn test_bad_hypen() {
// See: https://github.com/chyh1990/yaml-rust/issues/23
let s = "{-";
assert!(YamlLoader::load_from_str(&s).is_err());
}
} }