2023-08-22 16:31:45 +00:00
|
|
|
use whale_lib::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn assert() {
|
|
|
|
eval("assert(true)").unwrap();
|
|
|
|
eval("assert(false)").unwrap_err();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn assert_equal() {
|
2023-08-22 16:43:13 +00:00
|
|
|
eval("assert_equal(true, true)").unwrap();
|
|
|
|
eval("assert_equal(true, false)").unwrap_err();
|
2023-08-22 16:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn r#if() {
|
|
|
|
eval("if(true, assert(true))").unwrap();
|
|
|
|
|
|
|
|
let value = eval("if(true, 1)").unwrap();
|
2023-08-22 17:00:34 +00:00
|
|
|
assert_eq!(Value::Integer(1), value);
|
2023-08-22 16:31:45 +00:00
|
|
|
|
2023-08-22 17:00:34 +00:00
|
|
|
let value = eval("if(false, 1)").unwrap();
|
2023-08-22 17:19:57 +00:00
|
|
|
assert_eq!(Value::Empty, value);
|
2023-08-22 16:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn r#if_else() {
|
2023-08-22 17:19:57 +00:00
|
|
|
let value = eval("if_else(true, 1, 2)").unwrap();
|
2023-08-22 17:00:34 +00:00
|
|
|
assert_eq!(Value::Integer(1), value);
|
|
|
|
|
2023-08-22 17:19:57 +00:00
|
|
|
let value = eval("if_else(false, 1, 2)").unwrap();
|
2023-08-22 17:00:34 +00:00
|
|
|
assert_eq!(Value::Integer(2), value);
|
|
|
|
|
2023-08-22 17:19:57 +00:00
|
|
|
let value = eval("if_else(true, '1', '2')").unwrap();
|
2023-08-22 17:00:34 +00:00
|
|
|
assert_eq!(Value::Integer(1), value);
|
|
|
|
|
2023-08-22 17:19:57 +00:00
|
|
|
let value = eval("if_else(false, '1', '2')").unwrap();
|
2023-08-22 17:00:34 +00:00
|
|
|
assert_eq!(Value::Integer(2), value);
|
2023-08-22 16:31:45 +00:00
|
|
|
}
|