Make sure all tests run with all features.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#![cfg(not(feature = "no_index"))]
|
||||
use rhai::{Engine, EvalAltResult, RegisterFn};
|
||||
|
||||
#[test]
|
||||
|
@@ -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());
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#![cfg(not(feature = "no_stdlib"))]
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[test]
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#![cfg(not(feature = "no_float"))]
|
||||
use rhai::{Engine, EvalAltResult, RegisterFn};
|
||||
|
||||
#[test]
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#![cfg(not(feature = "no_index"))]
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[test]
|
||||
|
@@ -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!(),
|
||||
}
|
||||
}
|
||||
|
@@ -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(())
|
||||
}
|
||||
|
@@ -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()
|
||||
|
@@ -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");
|
||||
|
||||
|
Reference in New Issue
Block a user