2024-02-01 00:35:27 +00:00
|
|
|
use dust_lang::{error::ValidationError, *};
|
2024-01-06 07:26:51 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_assignment() {
|
|
|
|
let test = interpret("x = 1 x");
|
|
|
|
|
|
|
|
assert_eq!(Ok(Value::Integer(1)), test);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_assignment_with_type() {
|
|
|
|
let test = interpret("x <int> = 1 x");
|
|
|
|
|
|
|
|
assert_eq!(Ok(Value::Integer(1)), test);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_add_assign() {
|
|
|
|
let test = interpret(
|
|
|
|
"
|
|
|
|
x <[int]> = []
|
|
|
|
x += 1
|
|
|
|
x
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
Ok(Value::List(List::with_items(vec![Value::Integer(1)]))),
|
|
|
|
test
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_add_wrong_type() {
|
|
|
|
let result = interpret(
|
|
|
|
"
|
|
|
|
x <[str]> = []
|
|
|
|
x += 1
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
2024-02-01 00:35:27 +00:00
|
|
|
assert_eq!(
|
|
|
|
Err(Error::Validation(ValidationError::TypeCheck {
|
|
|
|
expected: Type::String,
|
|
|
|
actual: Type::Integer,
|
|
|
|
position: SourcePosition {
|
2024-02-01 02:21:42 +00:00
|
|
|
start_byte: 40,
|
|
|
|
end_byte: 46,
|
|
|
|
start_row: 3,
|
|
|
|
start_column: 12,
|
|
|
|
end_row: 3,
|
|
|
|
end_column: 18
|
2024-02-01 00:35:27 +00:00
|
|
|
}
|
|
|
|
})),
|
|
|
|
result
|
|
|
|
);
|
2024-01-06 07:26:51 +00:00
|
|
|
}
|