From b1621f25225ff3b1a02b3383345f2945c5194e2b Mon Sep 17 00:00:00 2001 From: John Date: Thu, 28 Sep 2023 00:08:51 -0500 Subject: [PATCH] tests: Add tests for token-class functions --- libconlang/src/lib.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libconlang/src/lib.rs b/libconlang/src/lib.rs index 22b1bf9..09e5bd5 100644 --- a/libconlang/src/lib.rs +++ b/libconlang/src/lib.rs @@ -419,7 +419,8 @@ mod tests { } fn assert_has_type_and_range<'t, F>(input: &'t str, f: F, ty: Type, range: Range) where F: FnOnce(&mut Lexer<'t>) -> Option { - let tok = f(&mut Lexer::new(input)).unwrap(); + let tok = + f(&mut Lexer::new(input)).unwrap_or_else(|| panic!("Should be {ty:?}, {range:?}")); assert_eq!(ty, tok.ty()); assert_eq!(range, tok.range()); } @@ -528,7 +529,15 @@ mod tests { assert_whole_input_is_token("123456789", Lexer::identifier, Type::Identifier); } } - mod integer { + mod literal { + use super::*; + #[test] + fn literal_class() { + assert_whole_input_is_token("1_00000", Lexer::literal, Type::LitInteger); + assert_whole_input_is_token("1.00000", Lexer::literal, Type::LitFloat); + assert_whole_input_is_token("\"1.0\"", Lexer::literal, Type::LitString); + } + mod integer { use super::*; #[test] fn bare() { @@ -599,9 +608,19 @@ mod tests { ); } } + } mod delimiter { use super::*; #[test] + fn delimiter_class() { + assert_whole_input_is_token("[", Lexer::delimiter, Type::LBrack); + assert_whole_input_is_token("]", Lexer::delimiter, Type::RBrack); + assert_whole_input_is_token("{", Lexer::delimiter, Type::LCurly); + assert_whole_input_is_token("}", Lexer::delimiter, Type::RCurly); + assert_whole_input_is_token("(", Lexer::delimiter, Type::LParen); + assert_whole_input_is_token(")", Lexer::delimiter, Type::RParen); + } + #[test] fn l_brack() { assert_whole_input_is_token("[", Lexer::l_brack, Type::LBrack); }