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
|
@ -129,4 +129,25 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
||||||
pub fn lex(src: String) -> (Option<Vec<(Token, std::ops::Range<usize>)>>, Vec<Simple<char>>) {
|
pub fn lex(src: String) -> (Option<Vec<(Token, std::ops::Range<usize>)>>, Vec<Simple<char>>) {
|
||||||
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![]);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -228,4 +228,24 @@ 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