Make sure all tests run with all features.

This commit is contained in:
Stephen Chung
2020-03-10 19:48:47 +08:00
parent cc772c6e2a
commit e22aaca5c1
14 changed files with 71 additions and 38 deletions

View File

@@ -1,3 +1,4 @@
#![cfg(not(feature = "no_index"))]
use rhai::{Engine, EvalAltResult, RegisterFn};
#[test]

View File

@@ -6,11 +6,15 @@ fn test_chars() -> Result<(), EvalAltResult> {
assert_eq!(engine.eval::<char>("'y'")?, 'y');
assert_eq!(engine.eval::<char>("'\\u2764'")?, '❤');
assert_eq!(engine.eval::<char>(r#"let x="hello"; x[2]"#)?, 'l');
assert_eq!(
engine.eval::<String>(r#"let x="hello"; x[2]='$'; x"#)?,
"he$lo".to_string()
);
#[cfg(not(feature = "no_index"))]
{
assert_eq!(engine.eval::<char>(r#"let x="hello"; x[2]"#)?, 'l');
assert_eq!(
engine.eval::<String>(r#"let x="hello"; x[2]='$'; x"#)?,
"he$lo".to_string()
);
}
assert!(engine.eval::<char>("'\\uhello'").is_err());
assert!(engine.eval::<char>("''").is_err());

View File

@@ -1,3 +1,4 @@
#![cfg(not(feature = "no_stdlib"))]
use rhai::{Engine, EvalAltResult};
#[test]

View File

@@ -1,3 +1,4 @@
#![cfg(not(feature = "no_float"))]
use rhai::{Engine, EvalAltResult, RegisterFn};
#[test]

View File

@@ -1,3 +1,4 @@
#![cfg(not(feature = "no_index"))]
use rhai::{Engine, EvalAltResult};
#[test]

View File

@@ -1,6 +1,7 @@
use rhai::{Engine, EvalAltResult, RegisterFn};
#[test]
#[cfg(not(feature = "no_stdlib"))]
fn test_mismatched_op() {
let mut engine = Engine::new();
@@ -26,17 +27,13 @@ fn test_mismatched_op_custom_type() {
}
let mut engine = Engine::new();
engine.register_type::<TestStruct>();
engine.register_type_with_name::<TestStruct>("TestStruct");
engine.register_fn("new_ts", TestStruct::new);
let r = engine.eval::<i64>("60 + new_ts()");
match r {
Err(EvalAltResult::ErrorFunctionNotFound(err, _))
if err == "+ (i64, mismatched_op::test_mismatched_op_custom_type::TestStruct)" =>
{
()
}
Err(EvalAltResult::ErrorFunctionNotFound(err, _)) if err == "+ (i64, TestStruct)" => (),
_ => panic!(),
}
}

View File

@@ -6,11 +6,15 @@ fn test_power_of() -> Result<(), EvalAltResult> {
assert_eq!(engine.eval::<i64>("2 ~ 3")?, 8);
assert_eq!(engine.eval::<i64>("(-2 ~ 3)")?, -8);
assert_eq!(engine.eval::<f64>("2.2 ~ 3.3")?, 13.489468760533386_f64);
assert_eq!(engine.eval::<f64>("2.0~-2.0")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("(-2.0~-2.0)")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("(-2.0~-2)")?, 0.25_f64);
assert_eq!(engine.eval::<i64>("4~3")?, 64);
#[cfg(not(feature = "no_float"))]
{
assert_eq!(engine.eval::<f64>("2.2 ~ 3.3")?, 13.489468760533386_f64);
assert_eq!(engine.eval::<f64>("2.0~-2.0")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("(-2.0~-2.0)")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("(-2.0~-2)")?, 0.25_f64);
assert_eq!(engine.eval::<i64>("4~3")?, 64);
}
Ok(())
}
@@ -21,14 +25,18 @@ fn test_power_of_equals() -> Result<(), EvalAltResult> {
assert_eq!(engine.eval::<i64>("let x = 2; x ~= 3; x")?, 8);
assert_eq!(engine.eval::<i64>("let x = -2; x ~= 3; x")?, -8);
assert_eq!(
engine.eval::<f64>("let x = 2.2; x ~= 3.3; x")?,
13.489468760533386_f64
);
assert_eq!(engine.eval::<f64>("let x = 2.0; x ~= -2.0; x")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("let x = -2.0; x ~= -2.0; x")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("let x = -2.0; x ~= -2; x")?, 0.25_f64);
assert_eq!(engine.eval::<i64>("let x =4; x ~= 3; x")?, 64);
#[cfg(not(feature = "no_float"))]
{
assert_eq!(
engine.eval::<f64>("let x = 2.2; x ~= 3.3; x")?,
13.489468760533386_f64
);
assert_eq!(engine.eval::<f64>("let x = 2.0; x ~= -2.0; x")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("let x = -2.0; x ~= -2.0; x")?, 0.25_f64);
assert_eq!(engine.eval::<f64>("let x = -2.0; x ~= -2; x")?, 0.25_f64);
assert_eq!(engine.eval::<i64>("let x =4; x ~= 3; x")?, 64);
}
Ok(())
}

View File

@@ -12,10 +12,20 @@ fn test_string() -> Result<(), EvalAltResult> {
engine.eval::<String>(r#""Test string: \x58""#)?,
"Test string: X".to_string()
);
assert_eq!(
engine.eval::<String>(r#""foo" + "bar""#)?,
"foobar".to_string()
);
#[cfg(not(feature = "no_stdlib"))]
assert_eq!(
engine.eval::<String>(r#""foo" + 123"#)?,
"foo123".to_string()
);
#[cfg(not(feature = "no_float"))]
#[cfg(not(feature = "no_stdlib"))]
assert_eq!(
engine.eval::<String>(r#""foo" + 123.4556"#)?,
"foo123.4556".to_string()

View File

@@ -5,11 +5,17 @@ fn test_type_of() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
assert_eq!(engine.eval::<String>("type_of(60 + 5)")?, "i64");
#[cfg(not(feature = "no_float"))]
assert_eq!(engine.eval::<String>("type_of(1.0 + 2.0)")?, "f64");
#[cfg(not(feature = "no_index"))]
#[cfg(not(feature = "no_float"))]
assert_eq!(
engine.eval::<String>(r#"type_of([1.0, 2, "hello"])"#)?,
"array"
);
assert_eq!(engine.eval::<String>(r#"type_of("hello")"#)?, "string");
assert_eq!(engine.eval::<String>("let x = 123; x.type_of()")?, "i64");