tests: Add tests for token-class functions
This commit is contained in:
parent
0661789d42
commit
b1621f2522
@ -419,7 +419,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
fn assert_has_type_and_range<'t, F>(input: &'t str, f: F, ty: Type, range: Range<usize>)
|
fn assert_has_type_and_range<'t, F>(input: &'t str, f: F, ty: Type, range: Range<usize>)
|
||||||
where F: FnOnce(&mut Lexer<'t>) -> Option<Token> {
|
where F: FnOnce(&mut Lexer<'t>) -> Option<Token> {
|
||||||
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!(ty, tok.ty());
|
||||||
assert_eq!(range, tok.range());
|
assert_eq!(range, tok.range());
|
||||||
}
|
}
|
||||||
@ -528,6 +529,14 @@ mod tests {
|
|||||||
assert_whole_input_is_token("123456789", Lexer::identifier, Type::Identifier);
|
assert_whole_input_is_token("123456789", Lexer::identifier, Type::Identifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 {
|
mod integer {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
@ -599,9 +608,19 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mod delimiter {
|
mod delimiter {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
#[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() {
|
fn l_brack() {
|
||||||
assert_whole_input_is_token("[", Lexer::l_brack, Type::LBrack);
|
assert_whole_input_is_token("[", Lexer::l_brack, Type::LBrack);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user