Tidy up tests

This commit is contained in:
jonathandturner 2016-03-26 13:36:26 -07:00
parent 5ccfab87ce
commit d133a62fc6

View File

@ -1293,6 +1293,68 @@ fn test_big_get_set() {
}
}
#[test]
fn test_internal_fn() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i32>("fn addme(a, b) { a+b } addme(3, 4)") {
assert_eq!(result, 7);
}
else {
assert!(false);
}
if let Ok(result) = engine.eval::<i32>("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::<i32>("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);
}
}
#[test]
fn test_string() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<String>("\"Test string: \\u2764\"") {
assert_eq!(result, "Test string: ❤");
}
else {
assert!(false);
}
}
#[test]
fn test_arrays() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i32>("var x = [1, 2, 3]; x[1]") {
assert_eq!(result, 2);
}
else {
assert!(false);
}
if let Ok(result) = engine.eval::<i32>("var y = [1, 2, 3]; y[1] = 5; y[1]") {
assert_eq!(result, 5);
}
else {
assert!(false);
}
}
#[test]
fn test_array_with_structs() {
#[derive(Clone)]
@ -1341,66 +1403,4 @@ fn test_array_with_structs() {
}
}
#[test]
fn test_internal_fn() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i32>("fn addme(a, b) { a+b } addme(3, 4)") {
assert_eq!(result, 7);
}
else {
assert!(false);
}
if let Ok(result) = engine.eval::<i32>("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::<i32>("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);
}
}
#[test]
fn test_string() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<String>("\"Test string: \\u2764\"") {
assert_eq!(result, "Test string: ❤");
}
else {
assert!(false);
}
}
#[test]
fn test_vec() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i32>("var x = [1, 2, 3]; x[1]") {
assert_eq!(result, 2);
}
else {
assert!(false);
}
if let Ok(result) = engine.eval::<i32>("var y = [1, 2, 3]; y[1] = 5; y[1]") {
assert_eq!(result, 5);
}
else {
assert!(false);
}
}