Skip to content

Commit

Permalink
feat[lexer]: Add test for identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
watcol committed Nov 23, 2021
1 parent b2e66b9 commit 6fbc84b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ peg::parser! { grammar lexer() for str {
/ "@" { Symbol::At }
/ expected!("symbols")

// TODO: Add test
rule ident() -> String = ident_bare() / ident_raw() / expected!("identifier")
rule ident_bare() -> String
= s:$(['a'..='z'|'A'..='Z'] ['a'..='z'|'A'..='Z'|'0'..='9'|'_']*) { s.to_string() }
Expand Down Expand Up @@ -184,6 +183,29 @@ mod tests {
)
}

#[test]
fn idents() {
let code = indoc::indoc! {"
f00_B4r ${\\\\{All\\u{00A0}characters\\
\\ncan be used.\\}}
"};
assert_eq!(
lex(code, 0),
Ok(vec![vec![
PosToken {
file_id: 0,
pos: 0..7,
token: Token::Ident(String::from("f00_B4r")),
},
PosToken {
file_id: 0,
pos: 8..53,
token: Token::Ident(String::from("\\{All\u{A0}characters\ncan be used.}"))
}
]])
)
}

#[test]
fn symbols() {
let code = "= + - * / % ** == != < > <= >= ! & | ^ << >> ( ) { } [ ] , . : _ @";
Expand Down

0 comments on commit 6fbc84b

Please sign in to comment.