Ensure metadata title and desc aren't tags
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
015a6c97e3
commit
5293048580
1 changed files with 30 additions and 3 deletions
33
src/lib.rs
33
src/lib.rs
|
@ -171,12 +171,14 @@ fn parse_meta_tags(s: Span) -> IResult<Span, Vec<String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_meta(s: Span) -> IResult<Span, Metadata> {
|
fn parse_meta(s: Span) -> IResult<Span, Metadata> {
|
||||||
let (s, (_pos, title)) =
|
let (s, (_pos, title)) = tuple((
|
||||||
tuple((position, delimited(tag("#"), take_until("\n"), tag("\n"))))(s)?;
|
position,
|
||||||
|
delimited(tag("#"), take_while1(|c| c != '#' && c != '\n'), tag("\n")),
|
||||||
|
))(s)?;
|
||||||
|
|
||||||
let optdesc = opt(tuple((
|
let optdesc = opt(tuple((
|
||||||
position,
|
position,
|
||||||
delimited(tag("#"), take_until("\n"), tag("\n")),
|
delimited(tag("#"), take_while1(|c| c != '#' && c != '\n'), tag("\n")),
|
||||||
)))(s)?;
|
)))(s)?;
|
||||||
|
|
||||||
let mut desc: Option<&str> = None;
|
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::<String>)
|
||||||
|
);
|
||||||
|
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::<String>).with_tags(vec![String::from("tag1")])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_client() {
|
fn test_client() {
|
||||||
let buf1 = "[Client] louise\n\tjid: louise@localhost\n\tpassword: password\n";
|
let buf1 = "[Client] louise\n\tjid: louise@localhost\n\tpassword: password\n";
|
||||||
|
|
Loading…
Reference in a new issue