Refactor tests.

This commit is contained in:
Stephen Chung
2020-03-02 22:11:56 +08:00
parent ed8d2ac20f
commit 0707fad1ca
27 changed files with 338 additions and 317 deletions

View File

@@ -1,16 +1,17 @@
use rhai::Engine;
use rhai::EvalAltResult;
use rhai::{Engine, EvalAltResult};
#[test]
fn test_decrement() {
fn test_decrement() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
assert_eq!(engine.eval::<i64>("let x = 10; x -= 7; x"), Ok(3));
assert_eq!(engine.eval::<i64>("let x = 10; x -= 7; x")?, 3);
assert_eq!(
engine.eval::<String>("let s = \"test\"; s -= \"ing\"; s"),
Err(EvalAltResult::ErrorFunctionNotFound(
"- (alloc::string::String, alloc::string::String)".to_string()
))
);
let r = engine.eval::<String>("let s = \"test\"; s -= \"ing\"; s");
match r {
Err(EvalAltResult::ErrorFunctionNotFound(err, _)) if err.starts_with("- ") => (),
_ => panic!(),
}
Ok(())
}