diff --git a/src/lib.rs b/src/lib.rs index 1308059..202b26d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,12 +171,14 @@ fn parse_meta_tags(s: Span) -> IResult> { } fn parse_meta(s: Span) -> IResult { - let (s, (_pos, title)) = - tuple((position, delimited(tag("#"), take_until("\n"), tag("\n"))))(s)?; + let (s, (_pos, title)) = tuple(( + position, + delimited(tag("#"), take_while1(|c| c != '#' && c != '\n'), tag("\n")), + ))(s)?; let optdesc = opt(tuple(( position, - delimited(tag("#"), take_until("\n"), tag("\n")), + delimited(tag("#"), take_while1(|c| c != '#' && c != '\n'), tag("\n")), )))(s)?; let mut desc: Option<&str> = None; @@ -387,6 +389,31 @@ mod tests { ); } + #[test] + fn test_meta() { + let buf1 = "# Title.\n"; + let buf2 = "#Foo\n# Desc\n"; + let buf3 = "#Foo\n# Desc\n## tag1\n"; + let buf4 = "#Foo\n## tag1\n"; + + assert_eq!( + parse_meta(buf1.into()).unwrap().1, + Metadata::new("Title.", None::) + ); + assert_eq!( + parse_meta(buf2.into()).unwrap().1, + Metadata::new("Foo", Some("Desc")) + ); + assert_eq!( + parse_meta(buf3.into()).unwrap().1, + Metadata::new("Foo", Some("Desc")).with_tags(vec![String::from("tag1")]) + ); + assert_eq!( + parse_meta(buf4.into()).unwrap().1, + Metadata::new("Foo", None::).with_tags(vec![String::from("tag1")]) + ); + } + #[test] fn test_client() { let buf1 = "[Client] louise\n\tjid: louise@localhost\n\tpassword: password\n";