1
0
dust/dust-lang/tests/expressions.rs
2024-03-24 09:10:49 -04:00

48 lines
1.1 KiB
Rust

use std::rc::Rc;
use dust_lang::*;
#[test]
fn logic() {
assert_eq!(
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(),
Some(Value::boolean(true))
);
}
#[test]
fn math() {
assert_eq!(
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(),
Some(Value::integer(42))
);
}
#[test]
fn list_index() {
assert_eq!(
interpret(Rc::new("test".to_string()), "foo = [1, 2, 3]; foo[2]").unwrap(),
Some(Value::integer(3))
);
}
#[test]
fn map_index() {
assert_eq!(
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(),
Some(Value::integer(3))
);
}