Fix divide support

This commit is contained in:
jonathandturner 2016-03-03 11:32:02 -05:00
parent 1d12141f0b
commit b5075e6511
3 changed files with 10 additions and 2 deletions

View File

@ -25,8 +25,8 @@ fn main() {
if let Ok(mut f) = File::open(fname.clone()) {
let mut contents = String::new();
if let Ok(_) = f.read_to_string(&mut contents) {
match engine.eval(contents) {
Ok(_) => (),
Err(e) => {println!("Error: {:?}", e)}

View File

@ -695,7 +695,7 @@ fn test_number_literal() {
}
#[test]
fn test_addition() {
fn test_ops() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval("60 + 5".to_string()).unwrap().downcast::<i32>() {
@ -704,6 +704,13 @@ fn test_addition() {
else {
assert!(false);
}
if let Ok(result) = engine.eval("(1 + 2) * (6 - 4) / 2".to_string()).unwrap().downcast::<i32>() {
assert_eq!(*result, 3);
}
else {
assert!(false);
}
}
#[test]

View File

@ -341,6 +341,7 @@ fn get_precedence(token: &Token) -> i32 {
Token::NotEqualTo => 15,
Token::Plus => 20,
Token::Minus => 20,
Token::Divide => 40,
Token::Multiply => 40,
_ => -1
}