Fix divide support
This commit is contained in:
parent
1d12141f0b
commit
b5075e6511
@ -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)}
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user