From 6f47dc69b62d67eddd1bc2c3ace82be41b38b7e6 Mon Sep 17 00:00:00 2001 From: Araozu Date: Sat, 4 May 2024 18:34:44 -0500 Subject: [PATCH] More tests --- src/syntax/binding.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/syntax/binding.rs b/src/syntax/binding.rs index 7586fcb..66a3ce4 100644 --- a/src/syntax/binding.rs +++ b/src/syntax/binding.rs @@ -313,4 +313,35 @@ mod tests { _ => panic!("Error expected"), } } + + #[test] + fn should_error_when_equal_op_is_missing() { + let tokens = get_tokens(&String::from("val identifier ")).unwrap(); + let binding = try_parse(&tokens, 0); + + match binding { + Err(ParsingError::Err(error)) => { + assert_eq!(4, error.error_start); + assert_eq!(14, error.error_end); + assert_eq!("There should be an equal sign `=` after the identifier", error.reason); + } + _ => panic!("Error expected"), + } + } + + #[test] + fn should_error_when_exp_is_empty() { + let tokens = get_tokens(&String::from("val identifier = ")).unwrap(); + let binding = try_parse(&tokens, 0); + + match binding { + Err(ParsingError::Err(error)) => { + assert_eq!(15, error.error_start); + assert_eq!(16, error.error_end); + assert_eq!("Expected an expression after the equal `=` operator", error.reason); + } + _ => panic!("Error expected"), + } + + } }