Rust 2018

This commit is contained in:
timfish
2019-09-18 11:21:07 +01:00
parent b92ed6201e
commit 82fd20b2b1
41 changed files with 533 additions and 490 deletions

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
use rhai::RegisterFn;
@@ -59,8 +57,10 @@ fn test_array_with_structs() {
assert!(false);
}
if let Ok(result) = engine.eval::<i64>("let a = [new_ts()]; a[0].x = 100; a[0].update(); \
a[0].x") {
if let Ok(result) = engine.eval::<i64>(
"let a = [new_ts()]; a[0].x = 100; a[0].update(); \
a[0].x",
) {
assert_eq!(result, 1100);
} else {
assert!(false);

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,12 +1,14 @@
extern crate rhai;
use rhai::Engine;
#[test]
fn test_comments() {
let mut engine = Engine::new();
let mut engine = Engine::new();
assert!(engine.eval::<i64>("let x = 5; x // I am a single line comment, yay!").is_ok());
assert!(engine
.eval::<i64>("let x = 5; x // I am a single line comment, yay!")
.is_ok());
assert!(engine.eval::<i64>("let /* I am a multiline comment, yay! */ x = 5; x").is_ok());
assert!(engine
.eval::<i64>("let /* I am a multiline comment, yay! */ x = 5; x")
.is_ok());
}

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
use rhai::RegisterFn;

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
use rhai::RegisterFn;
@@ -74,7 +72,9 @@ fn test_big_get_set() {
}
fn new() -> TestParent {
TestParent { child: TestChild::new() }
TestParent {
child: TestChild::new(),
}
}
}
@@ -88,5 +88,8 @@ fn test_big_get_set() {
engine.register_fn("new_tp", TestParent::new);
assert_eq!(engine.eval::<i64>("let a = new_tp(); a.child.x = 500; a.child.x"), Ok(500));
assert_eq!(
engine.eval::<i64>("let a = new_tp(); a.child.x = 500; a.child.x"),
Ok(500)
);
}

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]
@@ -23,8 +21,10 @@ fn test_internal_fn() {
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)") {
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);

View File

@@ -1,13 +1,12 @@
extern crate rhai;
use rhai::Engine;
#[test]
fn test_loop() {
let mut engine = Engine::new();
let mut engine = Engine::new();
assert!(
engine.eval::<bool>("
assert!(engine
.eval::<bool>(
"
let x = 0;
let i = 0;
@@ -22,6 +21,7 @@ fn test_loop() {
}
x == 45
").unwrap()
)
"
)
.unwrap())
}

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
use rhai::RegisterFn;
@@ -32,5 +30,4 @@ fn test_method_call() {
} else {
assert!(false);
}
}

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::{Engine, EvalAltResult};
#[test]
@@ -8,6 +6,8 @@ fn test_mismatched_op() {
assert_eq!(
engine.eval::<i64>("60 + \"hello\""),
Err(EvalAltResult::ErrorFunctionNotFound("+ (integer,string)".into()))
Err(EvalAltResult::ErrorFunctionNotFound(
"+ (integer,string)".into()
))
);
}

View File

@@ -1,15 +1,21 @@
extern crate rhai;
use rhai::Engine;
#[test]
fn test_not() {
let mut engine = Engine::new();
let mut engine = Engine::new();
assert_eq!(engine.eval::<bool>("let not_true = !true; not_true").unwrap(), false);
assert_eq!(
engine
.eval::<bool>("let not_true = !true; not_true")
.unwrap(),
false
);
assert_eq!(engine.eval::<bool>("fn not(x) { !x } not(false)").unwrap(), true);
assert_eq!(
engine.eval::<bool>("fn not(x) { !x } not(false)").unwrap(),
true
);
// TODO - do we allow stacking unary operators directly? e.g '!!!!!!!true'
assert_eq!(engine.eval::<bool>("!(!(!(!(true))))").unwrap(), true)
// TODO - do we allow stacking unary operators directly? e.g '!!!!!!!true'
assert_eq!(engine.eval::<bool>("!(!(!(!(true))))").unwrap(), true)
}

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]
@@ -8,7 +6,10 @@ fn test_power_of() {
assert_eq!(engine.eval::<i64>("2 ~ 3").unwrap(), 8);
assert_eq!(engine.eval::<i64>("(-2 ~ 3)").unwrap(), -8);
assert_eq!(engine.eval::<f64>("2.2 ~ 3.3").unwrap(), 13.489468760533386_f64);
assert_eq!(
engine.eval::<f64>("2.2 ~ 3.3").unwrap(),
13.489468760533386_f64
);
assert_eq!(engine.eval::<f64>("2.0~-2.0").unwrap(), 0.25_f64);
assert_eq!(engine.eval::<f64>("(-2.0~-2.0)").unwrap(), 0.25_f64);
assert_eq!(engine.eval::<f64>("(-2.0~-2)").unwrap(), 0.25_f64);
@@ -21,9 +22,21 @@ fn test_power_of_equals() {
assert_eq!(engine.eval::<i64>("let x = 2; x ~= 3; x").unwrap(), 8);
assert_eq!(engine.eval::<i64>("let x = -2; x ~= 3; x").unwrap(), -8);
assert_eq!(engine.eval::<f64>("let x = 2.2; x ~= 3.3; x").unwrap(), 13.489468760533386_f64);
assert_eq!(engine.eval::<f64>("let x = 2.0; x ~= -2.0; x").unwrap(), 0.25_f64);
assert_eq!(engine.eval::<f64>("let x = -2.0; x ~= -2.0; x").unwrap(), 0.25_f64);
assert_eq!(engine.eval::<f64>("let x = -2.0; x ~= -2; x").unwrap(), 0.25_f64);
assert_eq!(
engine.eval::<f64>("let x = 2.2; x ~= 3.3; x").unwrap(),
13.489468760533386_f64
);
assert_eq!(
engine.eval::<f64>("let x = 2.0; x ~= -2.0; x").unwrap(),
0.25_f64
);
assert_eq!(
engine.eval::<f64>("let x = -2.0; x ~= -2.0; x").unwrap(),
0.25_f64
);
assert_eq!(
engine.eval::<f64>("let x = -2.0; x ~= -2; x").unwrap(),
0.25_f64
);
assert_eq!(engine.eval::<i64>("let x =4; x ~= 3; x").unwrap(), 64);
}

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,12 +1,9 @@
extern crate rhai;
use rhai::Engine;
#[test]
// TODO also add test case for unary after compound
// Hah, turns out unary + has a good use after all!
fn test_unary_after_binary()
{
fn test_unary_after_binary() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i64>("10 % +4") {

View File

@@ -1,14 +1,12 @@
extern crate rhai;
use rhai::Engine;
#[test]
fn test_unary_minus() {
let mut engine = Engine::new();
let mut engine = Engine::new();
assert_eq!(engine.eval::<i64>("let x = -5; x").unwrap(), -5);
assert_eq!(engine.eval::<i64>("let x = -5; x").unwrap(), -5);
assert_eq!(engine.eval::<i64>("fn n(x) { -x } n(5)").unwrap(), -5);
assert_eq!(engine.eval::<i64>("fn n(x) { -x } n(5)").unwrap(), -5);
assert_eq!(engine.eval::<i64>("5 - -(-5)").unwrap(), 0);
assert_eq!(engine.eval::<i64>("5 - -(-5)").unwrap(), 0);
}

View File

@@ -1,5 +1,3 @@
extern crate rhai;
use rhai::Engine;
#[test]

View File

@@ -1,11 +1,9 @@
extern crate rhai;
use rhai::{Engine, Scope};
#[test]
fn test_var_scope() {
let mut engine = Engine::new();
let mut scope: Scope = Vec::new();
let mut scope = Scope::new();
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5") {
} else {

View File

@@ -1,13 +1,13 @@
extern crate rhai;
use rhai::Engine;
#[test]
fn test_while() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i64>("let x = 0; while x < 10 { x = x + 1; if x > 5 { \
break } } x") {
if let Ok(result) = engine.eval::<i64>(
"let x = 0; while x < 10 { x = x + 1; if x > 5 { \
break } } x",
) {
assert_eq!(result, 6);
} else {
assert!(false);