[lexer] Add expression tests; add explicit_sign to identifier_initials
This commit is contained in:
parent
061868d2c2
commit
9f5165f0aa
2 changed files with 30 additions and 1 deletions
|
@ -33,7 +33,7 @@ impl Lexable for char {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_identifier_initial(&self) -> bool {
|
fn is_identifier_initial(&self) -> bool {
|
||||||
self.is_alphabetic() || self.is_special_initial()
|
self.is_alphabetic() || self.is_special_initial() || self.is_explicit_sign()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_identifier_subsequent(&self) -> bool {
|
fn is_identifier_subsequent(&self) -> bool {
|
||||||
|
|
29
lexer/tests/expressions.rs
Normal file
29
lexer/tests/expressions.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* lexer/tests/expressions.rs
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern crate sibillexer;
|
||||||
|
|
||||||
|
use sibillexer::{Lexer, Lex, Token};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn addition() {
|
||||||
|
let mut lex = Lexer::new("(+ 3 4)".chars());
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::LeftParen, "(", 0, 0))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Id, "+", 0, 1))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Num(3), "3", 0, 3))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Num(4), "4", 0, 5))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::RightParen, ")", 0, 6))));
|
||||||
|
assert_eq!(lex.next(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn subtraction() {
|
||||||
|
let mut lex = Lexer::new("(- 3 4)".chars());
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::LeftParen, "(", 0, 0))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Id, "-", 0, 1))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Num(3), "3", 0, 3))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Num(4), "4", 0, 5))));
|
||||||
|
assert_eq!(lex.next(), Some(Ok(Lex::new(Token::RightParen, ")", 0, 6))));
|
||||||
|
assert_eq!(lex.next(), None);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue