From 9ed860383ed6d19d4620e078b31f584a00c871ac Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 31 Jan 2024 00:58:05 -0800 Subject: [PATCH] test --- src/test/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/mod.rs b/src/test/mod.rs index 6204ef4..045f18f 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -3,10 +3,24 @@ mod sexp; use super::*; #[test] -fn parsing() { +fn basic_parsing() { let (parsed, rest) = literal("a").parse("a yolo").unwrap(); assert_eq!(parsed, "a"); assert_eq!(rest, " yolo"); + + fn bare_function_parser(input: &str) -> ParseResult<&str, i32, String> { + match input.chars().next() { + Some('0') => Ok((0, &input[1..])), + Some('1') => Ok((1, &input[1..])), + _ => Err(("lol a parse error".to_string(), input)), + } + } + + assert_eq!(bare_function_parser.parse("0foo"), Ok((0, "foo"))); + assert_eq!( + bare_function_parser.parse("xfoo"), + Err(("lol a parse error".to_string(), "xfoo")) + ); } #[test]