Skip to content

Commit

Permalink
Feat/support op associaty (#25)
Browse files Browse the repository at this point in the history
* feat: support operator associativity

* feat: update

* feat: update unit tests
  • Loading branch information
ashyanSpada authored Dec 18, 2023
1 parent 5f18357 commit e7b3af0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,18 @@ mod tests {
#[test]
fn test_register_infix_op() {
register_infix_op(
"---",
"right_minus",
100,
InfixOpType::CALC,
InfixOpAssociativity::RIGHT,
Arc::new(|left, right| Ok(Value::from(left.integer()? - right.integer()?))),
);
let input = "100---55---44";
let input = "100 right_minus 55 right_minus 44";
let ans = execute(input, create_context!());
match &ans {
Ok(_) => {}
Err(e) => print!("err is {}", e),
}
assert!(ans.is_ok());
assert_eq!(ans.unwrap(), Value::from(89));
}
Expand Down

0 comments on commit e7b3af0

Please sign in to comment.