aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lex.rs6
-rw-r--r--src/main.rs5
2 files changed, 11 insertions, 0 deletions
diff --git a/src/lex.rs b/src/lex.rs
index 1c686a1..da542d5 100644
--- a/src/lex.rs
+++ b/src/lex.rs
@@ -143,6 +143,12 @@ pub fn lexer(input: &str, prev_ans: Option<f64>) -> Result<Vec<Token>, CalcError
143 &char_vec[..char_vec.chars().count()-1] 143 &char_vec[..char_vec.chars().count()-1]
144 ))); 144 )));
145 } 145 }
146 } else if CONSTANTS.get(&char_vec[..]).is_some() {
147 result.push(CONSTANTS.get(&char_vec[..]).unwrap().clone());
148 result.push(OPERATORS.get(&'*').unwrap().clone());
149 char_vec.clear();
150 num_vec.push(letter);
151 last_char_is_op = false;
146 } else { 152 } else {
147 return Err(CalcError::Syntax(format!( 153 return Err(CalcError::Syntax(format!(
148 "Unexpected character '{}'", 154 "Unexpected character '{}'",
diff --git a/src/main.rs b/src/main.rs
index 75c33bb..f5e5c59 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -259,4 +259,9 @@ mod tests {
259 let evaled = eval_math_expression("9 + _ ", Some(0f64)).unwrap(); 259 let evaled = eval_math_expression("9 + _ ", Some(0f64)).unwrap();
260 assert_eq!(9., evaled); 260 assert_eq!(9., evaled);
261 } 261 }
262 #[test]
263 fn eval_const_multiplication() {
264 let evaled = eval_math_expression("e2", None).unwrap();
265 assert_eq!(5.4365636569, evaled);
266 }
262} 267}