Add a test for sexp with quoted atom containing parenthesis.

This commit is contained in:
Tom Alexander 2023-04-21 21:15:18 -04:00
parent 517e826f4e
commit 798eeee488
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -124,7 +124,7 @@ fn quoted_atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
let (remaining, _) = tag(r#"""#)(input)?; let (remaining, _) = tag(r#"""#)(input)?;
let (remaining, _) = escaped( let (remaining, _) = escaped(
take_till1(|c| match c { take_till1(|c| match c {
'\\' | '"' | ')' => true, '\\' | '"' => true,
_ => false, _ => false,
}), }),
'\\', '\\',
@ -215,4 +215,40 @@ mod tests {
r#""foo""# r#""foo""#
) )
} }
#[test]
fn quoted_containing_paren() {
let input = r#" (foo "b(a)r" baz ) "#;
let (remaining, parsed) = sexp_with_padding(input).expect("Parse the input");
assert_eq!(remaining, "");
assert!(match parsed {
Token::List(_) => true,
_ => false,
});
let children = match parsed {
Token::List(children) => children,
_ => panic!("Should be a list."),
};
assert_eq!(
match children.first() {
Some(Token::Atom(body)) => *body,
_ => panic!("First child should be an atom."),
},
r#"foo"#
);
assert_eq!(
match children.iter().nth(1) {
Some(Token::Atom(body)) => *body,
_ => panic!("Second child should be an atom."),
},
r#""b(a)r""#
);
assert_eq!(
match children.iter().nth(2) {
Some(Token::Atom(body)) => *body,
_ => panic!("Third child should be an atom."),
},
r#"baz"#
);
}
} }