Use empty_scalar_with_anchor properly

This closes #27.
This commit is contained in:
Yuheng Chen 2016-07-28 17:36:25 +08:00
parent 0cff969990
commit 7783c68d5f
2 changed files with 11 additions and 3 deletions

View file

@ -58,8 +58,8 @@ impl Event {
Event::Scalar("~".to_owned(), TScalarStyle::Plain, 0, None)
}
fn empty_scalar_with_anchor(anchor: usize, tag: TokenType) -> Event {
Event::Scalar("".to_owned(), TScalarStyle::Plain, anchor, Some(tag))
fn empty_scalar_with_anchor(anchor: usize, tag: Option<TokenType>) -> Event {
Event::Scalar("".to_owned(), TScalarStyle::Plain, anchor, tag)
}
}
@ -453,7 +453,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
// ex 7.2, an empty scalar can follow a secondary tag
_ if tag.is_some() || anchor_id > 0 => {
self.pop_state();
Ok(Event::empty_scalar_with_anchor(anchor_id, tag.unwrap()))
Ok(Event::empty_scalar_with_anchor(anchor_id, tag))
},
_ => { Err(ScanError::new(tok.0, "while parsing a node, did not find expected node content")) }
}

View file

@ -404,6 +404,14 @@ a1: &DEFAULT
}
#[test]
fn test_github_27() {
// https://github.com/chyh1990/yaml-rust/issues/27
let s = "&a";
let out = YamlLoader::load_from_str(&s).unwrap();
let doc = &out[0];
assert_eq!(doc.as_str().unwrap(), "");
}
#[test]
fn test_plain_datatype() {