Add a test for sexp with quoted atom containing parenthesis.
This commit is contained in:
		
							parent
							
								
									517e826f4e
								
							
						
					
					
						commit
						798eeee488
					
				| @ -124,7 +124,7 @@ fn quoted_atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> { | ||||
|     let (remaining, _) = tag(r#"""#)(input)?; | ||||
|     let (remaining, _) = escaped( | ||||
|         take_till1(|c| match c { | ||||
|             '\\' | '"' | ')' => true, | ||||
|             '\\' | '"' => true, | ||||
|             _ => false, | ||||
|         }), | ||||
|         '\\', | ||||
| @ -215,4 +215,40 @@ mod tests { | ||||
|             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"# | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander