Adding additional lexer unit tests

This commit is contained in:
fosdick.io
2024-02-14 11:45:21 -07:00
parent 8fc4d587e0
commit 08f1e4a214
2 changed files with 84 additions and 21 deletions

View File

@@ -4,7 +4,7 @@ use crate::language::get_language;
use crate::locale::get_locale;
use crate::expressions::{
lexer::{Lexer, LexerMode},
lexer::{Lexer, LexerError, LexerMode},
token::TokenType::*,
token::{Error, OpCompare, OpProduct, OpSum},
types::ParsedReference,
@@ -411,6 +411,20 @@ fn test_name_r1c1p() {
assert_eq!(lx.next_token(), EOF);
}
#[test]
fn test_reference_r1c1_error() {
let mut lx = new_lexer("$A$4", false);
lx.mode = LexerMode::R1C1;
assert_eq!(
lx.next_token(),
Illegal(LexerError {
position: 1,
message: "Cannot parse A1 reference in R1C1 mode".to_string(),
})
);
assert_eq!(lx.next_token(), EOF);
}
#[test]
fn test_name_wrong_ref() {
let mut lx = new_lexer("Sheet1!2", false);
@@ -563,13 +577,13 @@ fn test_range() {
column: 1,
row: 1,
absolute_column: false,
absolute_row: false
absolute_row: false,
},
right: ParsedReference {
column: 2,
row: 3,
absolute_column: false,
absolute_row: false
absolute_row: false,
},
}
);
@@ -629,6 +643,22 @@ fn test_ampersand() {
assert_eq!(lx.next_token(), EOF);
}
#[test]
fn test_comma() {
// Used for testing locales where the comma is not a decimal separator
let mut lx = new_lexer("12,34", false);
assert_eq!(lx.next_token(), Number(12.0));
assert_eq!(lx.next_token(), Comma);
assert_eq!(lx.next_token(), Number(34.0));
assert_eq!(lx.next_token(), EOF);
// Used for testing locales where the comma is the decimal separator
let mut lx = new_lexer("12,34", false);
lx.locale.numbers.symbols.decimal = ",".to_string();
assert_eq!(lx.next_token(), Number(12.34));
assert_eq!(lx.next_token(), EOF);
}
#[test]
fn test_semicolon() {
let mut lx = new_lexer("FALSE;", false);