use super::*;
fn tokens_of(input: &str) -> Vec<Token> {
let mut lexer = Lexer::new(input);
lexer
.tokenize()
.into_iter()
.map(|t| t.token)
.filter(|t| *t != Token::EOF)
.collect()
}
#[test]
fn single_char_between_single_quotes_is_a_character_literal() {
assert_eq!(tokens_of("'A'"), vec![Token::IntegerLiteral(65)]);
}
#[test]
fn possessive_single_apostrophe_form_lexes_identifier_then_s() {
assert_eq!(
tokens_of("'my nums's length"),
vec![
Token::Identifier("my nums".to_string()),
Token::Apostrophe,
Token::Identifier("s".to_string()),
Token::Size,
]
);
}
#[test]
fn possessive_doubled_apostrophe_form_lexes_identically() {
assert_eq!(
tokens_of("'my nums''s length"),
tokens_of("'my nums's length")
);
}
#[test]
fn underscore_prefix_is_preserved_in_identifier() {
assert_eq!(
tokens_of("_str_eq"),
vec![Token::Identifier("_str_eq".to_string())]
);
assert_eq!(
tokens_of("my_helper"),
vec![Token::Identifier("my_helper".to_string())]
);
}