2024-03-24 13:10:49 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
2024-03-07 03:15:35 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn logic() {
|
|
|
|
assert_eq!(
|
2024-03-24 13:10:49 +00:00
|
|
|
interpret(Rc::new("test".to_string()), "1 == 1").unwrap(),
|
|
|
|
Some(Value::boolean(true))
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
interpret(Rc::new("test".to_string()), "('42' == '42') && (42 != 0)").unwrap(),
|
2024-03-17 21:39:39 +00:00
|
|
|
Some(Value::boolean(true))
|
2024-03-07 03:15:35 +00:00
|
|
|
);
|
|
|
|
}
|
2024-03-07 10:37:26 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn math() {
|
2024-03-07 17:29:07 +00:00
|
|
|
assert_eq!(
|
2024-03-24 13:10:49 +00:00
|
|
|
interpret(Rc::new("test".to_string()), "1 + 1").unwrap(),
|
|
|
|
Some(Value::integer(2))
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
interpret(Rc::new("test".to_string()), "2 * (21 + 19 + 1 * 2) / 2").unwrap(),
|
2024-03-17 21:39:39 +00:00
|
|
|
Some(Value::integer(42))
|
2024-03-07 17:29:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_index() {
|
2024-03-08 17:24:11 +00:00
|
|
|
assert_eq!(
|
2024-03-24 13:10:49 +00:00
|
|
|
interpret(Rc::new("test".to_string()), "foo = [1, 2, 3]; foo[2]").unwrap(),
|
2024-03-18 01:07:03 +00:00
|
|
|
Some(Value::integer(3))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn map_index() {
|
|
|
|
assert_eq!(
|
2024-03-24 13:10:49 +00:00
|
|
|
interpret(Rc::new("test".to_string()), "{ x = 3 }.x").unwrap(),
|
|
|
|
Some(Value::integer(3))
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
interpret(Rc::new("test".to_string()), "foo = { x = 3 }; foo.x").unwrap(),
|
2024-03-17 21:39:39 +00:00
|
|
|
Some(Value::integer(3))
|
2024-03-08 17:24:11 +00:00
|
|
|
);
|
2024-03-07 10:37:26 +00:00
|
|
|
}
|