mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
some test
This commit is contained in:
parent
cf65687337
commit
a42415a90a
|
@ -130,3 +130,24 @@ pub fn lex(src: String) -> (Option<Vec<(Token, std::ops::Range<usize>)>>, Vec<Si
|
||||||
let (tokens, lex_error) = lexer().parse_recovery(src.as_str());
|
let (tokens, lex_error) = lexer().parse_recovery(src.as_str());
|
||||||
return (tokens, lex_error);
|
return (tokens, lex_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lex_let_simple() {
|
||||||
|
let (tokens, err) = lex("let x: Int = 1;".to_string());
|
||||||
|
|
||||||
|
assert_eq!(tokens, Some(vec![
|
||||||
|
(Token::KwLet, 0..3),
|
||||||
|
(Token::Identifier("x".to_string()), 4..5),
|
||||||
|
(Token::Colon, 5..6),
|
||||||
|
(Token::Identifier("Int".to_string()), 7..10),
|
||||||
|
(Token::Assign, 11..12),
|
||||||
|
(Token::Int(1), 13..14),
|
||||||
|
(Token::SemiColon, 14..15),
|
||||||
|
]));
|
||||||
|
assert_eq!(err, vec![]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -229,3 +229,23 @@ pub fn parse(tokens: Vec<(Token, std::ops::Range<usize>)>, len: usize) -> (Optio
|
||||||
|
|
||||||
return (ast, parse_error)
|
return (ast, parse_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_simple() {
|
||||||
|
let (_, err) = parse(vec![
|
||||||
|
(Token::KwLet, 0..3),
|
||||||
|
(Token::Identifier("x".to_string()), 4..5),
|
||||||
|
(Token::Colon, 5..6),
|
||||||
|
(Token::Identifier("Int".to_string()), 7..10),
|
||||||
|
(Token::Assign, 11..12),
|
||||||
|
(Token::Int(1), 13..14),
|
||||||
|
(Token::SemiColon, 14..15),
|
||||||
|
], 15);
|
||||||
|
|
||||||
|
assert_eq!(err, vec![]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue