1
0
dust/tests/expressions.rs

28 lines
552 B
Rust
Raw Permalink Normal View History

2024-03-07 03:15:35 +00:00
use dust_lang::*;
#[test]
fn logic() {
2024-03-08 17:24:11 +00:00
assert_eq!(interpret("1 == 1"), Ok(Some(Value::boolean(true))));
2024-03-07 03:15:35 +00:00
assert_eq!(
interpret("('42' == '42') && (42 != 0)"),
2024-03-08 17:24:11 +00:00
Ok(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-08 17:24:11 +00:00
assert_eq!(interpret("1 + 1"), Ok(Some(Value::integer(2))));
2024-03-07 17:29:07 +00:00
assert_eq!(
interpret("2 * (21 + 19 + 1 * 2) / 2"),
2024-03-08 17:24:11 +00:00
Ok(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!(
interpret("foo = [1, 2, 3]; foo.2"),
Ok(Some(Value::integer(3)))
);
2024-03-07 10:37:26 +00:00
}