Add parsing function and test
parent
8a5b6ed2a9
commit
ef7bbae025
@ -1,3 +1,4 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
.idea
|
||||
.idea
|
||||
test-files
|
@ -1,13 +1,34 @@
|
||||
#[macro_use] extern crate maplit;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate maplit;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
pub mod elements;
|
||||
pub mod tokenizer;
|
||||
mod tokens;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tokenizer::Tokenizer;
|
||||
use crate::tokens::{Grouping, Misc, Operation, Relation, Text, Token};
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
let expression = "sum_(i=1)^n";
|
||||
let mut tokenizer = Tokenizer::new(expression.to_string());
|
||||
let tokens = tokenizer.parse();
|
||||
assert_eq!(
|
||||
tokens,
|
||||
vec![
|
||||
Token::Operation(Operation::Sum),
|
||||
Token::Misc(Misc::Sub),
|
||||
Token::Grouping(Grouping::RParen),
|
||||
Token::Text(Text::Plain("i".to_string())),
|
||||
Token::Relation(Relation::Eq),
|
||||
Token::Text(Text::Plain("1".to_string())),
|
||||
Token::Grouping(Grouping::LParen),
|
||||
Token::Misc(Misc::Pow),
|
||||
Token::Text(Text::Plain("n".to_string()))
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue