rhai/tests/internal_fn.rs

33 lines
749 B
Rust
Raw Normal View History

extern crate rhai;
use rhai::Engine;
2017-11-03 17:58:51 +01:00
#[test]
fn test_internal_fn() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i64>("fn addme(a, b) { a+b } addme(3, 4)") {
assert_eq!(result, 7);
} else {
assert!(false);
}
if let Ok(result) = engine.eval::<i64>("fn bob() { return 4; 5 } bob()") {
assert_eq!(result, 4);
} else {
assert!(false);
}
}
#[test]
fn test_big_internal_fn() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i64>("fn mathme(a, b, c, d, e, f) { a - b * c + d * e - f \
} mathme(100, 5, 2, 9, 6, 32)") {
assert_eq!(result, 112);
} else {
assert!(false);
}
}