diff --git a/src/parser/tokenizer.rs b/src/parser/tokenizer.rs index a86c754..e818134 100644 --- a/src/parser/tokenizer.rs +++ b/src/parser/tokenizer.rs @@ -36,14 +36,7 @@ pub fn tokenize(query: &str) -> Result, String> { ')' => tokens.push(Token::CloseParenthesis()), 'a'..='z' | 'A'..='Z' => { if is_last_number == true { - let mut tmp_token = None; - if is_pop_needed { - tmp_token = tokens.pop(); - } tokens.push(check_number(my_string, i)?); - if let Some(tok) = tmp_token { - tokens.push(tok); - } is_last_number = false; my_string = String::new(); } @@ -55,17 +48,10 @@ pub fn tokenize(query: &str) -> Result, String> { }, '0'..='9' | '.' => { if is_last_variable == true { - let mut tmp_token = None; - if is_pop_needed { - tmp_token = tokens.pop(); - } match my_string.as_str() { "i" => tokens.push(Token::ImaginaryUnit()), _ => tokens.push(Token::Variable(my_string)), } - if let Some(tok) = tmp_token { - tokens.push(tok); - } is_last_variable = false; my_string = String::new(); } @@ -297,4 +283,11 @@ mod tests { let query = "324*43224+243_+234=234"; tokenize(query).unwrap(); } + + #[test] + fn bug_pop_not_needed_between_variables_and_numbers() { + let query = "5(7i)"; + let result: Vec = vec![Token::Number(String::from("5")), Token::OpenParenthesis(), Token::Number(String::from("7")), Token::ImaginaryUnit(), Token::CloseParenthesis()]; + assert_eq!(tokenize(query).unwrap(), result); + } }