1
0
dust/dust-lang/tests/expressions.rs

43 lines
891 B
Rust
Raw Normal View History

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