Fix assert fail on empty document

This closes #20
This commit is contained in:
Yuheng Chen 2016-05-25 13:19:36 +08:00
parent 028176a4b6
commit a3ecc9f2d4
2 changed files with 9 additions and 2 deletions

View file

@ -124,8 +124,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
fn parse<R: EventReceiver>(&mut self, recv: &mut R)
-> ParseResult {
if self.scanner.stream_ended()
|| self.state == State::End {
if self.state == State::End {
return Ok(Event::StreamEnd);
}
let ev = try!(self.state_machine());

View file

@ -331,6 +331,14 @@ c: [1, 2]
assert!(doc["d"][0].is_badvalue());
}
#[test]
fn test_empty_doc() {
let s: String = "".to_owned();
YamlLoader::load_from_str(&s).unwrap();
let s: String = "---".to_owned();
assert_eq!(YamlLoader::load_from_str(&s).unwrap()[0], Yaml::Null);
}
#[test]
fn test_parser() {
let s: String = "