Add tests
This commit is contained in:
parent
a7417e8a99
commit
774f1d65ca
@ -467,4 +467,12 @@ mod indentation_tests {
|
||||
|
||||
assert_eq!(TokenType::Comment, tokens[0].token_type);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_emit_error_on_incorrect_indentation() {
|
||||
let input = String::from("1\n 2\n 3");
|
||||
let tokens = get_tokens(&input);
|
||||
|
||||
assert!(tokens.is_err());
|
||||
}
|
||||
}
|
||||
|
@ -436,4 +436,36 @@ mod tests {
|
||||
panic!("Expected some value")
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_scan_invalid_scientific_notation() {
|
||||
let input = str_to_vec("1e");
|
||||
let start_pos = 0;
|
||||
|
||||
match scan(&input, start_pos) {
|
||||
LexResult::Err(reason) => {
|
||||
assert_eq!(
|
||||
"The characters after 'e' are not + or -, or are not followed by a number",
|
||||
reason.reason
|
||||
)
|
||||
}
|
||||
_ => panic!("Expected an error"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_scan_invalid_scientific_notation_2() {
|
||||
let input = str_to_vec("1e+f");
|
||||
let start_pos = 0;
|
||||
|
||||
match scan(&input, start_pos) {
|
||||
LexResult::Err(reason) => {
|
||||
assert_eq!(
|
||||
"The characters after 'e' are not + or -, or are not followed by a number",
|
||||
reason.reason
|
||||
)
|
||||
}
|
||||
_ => panic!("Expected an error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,4 +179,45 @@ mod tests {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_scan_non_escape_characters_preceded_by_bsls() {
|
||||
let input = str_to_vec("\"Sample\\atext\"");
|
||||
let start_pos = 1;
|
||||
if let LexResult::Some(token, next) = scan(&input, start_pos) {
|
||||
assert_eq!(14, next);
|
||||
assert_eq!(TokenType::String, token.token_type);
|
||||
assert_eq!("\"Sample\\atext\"", token.value);
|
||||
assert_eq!(0, token.position);
|
||||
} else {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shouldnt_panic_when_encountering_eof_after_bsls() {
|
||||
let input = str_to_vec("\"Sample\\");
|
||||
let start_pos = 1;
|
||||
let result = scan(&input, start_pos);
|
||||
|
||||
match result {
|
||||
LexResult::Err(reason) => {
|
||||
assert_eq!("Incomplete string found", reason.reason)
|
||||
},
|
||||
_ => panic!("expected an error")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_scan_an_unfinished_string() {
|
||||
let input = str_to_vec("\"Hello, world!");
|
||||
let result = scan(&input, 1);
|
||||
|
||||
match result {
|
||||
LexResult::Err(reason) => {
|
||||
assert_eq!("Incomplete string found", reason.reason)
|
||||
},
|
||||
_ => panic!("expected an error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user