2024-03-07 04:21:07 +00:00
|
|
|
use dust_lang::{
|
|
|
|
abstract_tree::Type,
|
|
|
|
error::{Error, TypeCheckError, ValidationError},
|
|
|
|
*,
|
|
|
|
};
|
2024-03-06 23:15:25 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn set_and_get_variable() {
|
2024-03-07 00:45:41 +00:00
|
|
|
assert_eq!(interpret("foobar = true; foobar"), Ok(Value::boolean(true)));
|
2024-03-06 23:15:25 +00:00
|
|
|
}
|
2024-03-07 04:21:07 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn set_variable_with_type() {
|
|
|
|
assert_eq!(
|
|
|
|
interpret("foobar: bool = true; foobar"),
|
|
|
|
Ok(Value::boolean(true))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn set_variable_with_type_error() {
|
|
|
|
assert_eq!(
|
|
|
|
interpret("foobar: str = true"),
|
|
|
|
Err(vec![Error::Validation {
|
|
|
|
error: ValidationError::TypeCheck(TypeCheckError {
|
|
|
|
actual: Type::Boolean,
|
|
|
|
expected: Type::String
|
|
|
|
}),
|
|
|
|
span: (0..18).into()
|
|
|
|
}])
|
|
|
|
);
|
|
|
|
}
|