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

52 lines
1.3 KiB
Rust

use dust_lang::{
error::{DustError, TypeConflict, ValidationError},
*,
};
#[test]
fn set_variable_with_type_error() {
assert_eq!(
interpret("test", "foobar: str = true")
.unwrap_err()
.errors(),
&vec![DustError::Validation {
error: ValidationError::TypeCheck {
conflict: TypeConflict {
actual: Type::Boolean,
expected: Type::String
},
actual_position: (14, 18).into(),
expected_position: Some((8, 11).into())
},
position: (0, 18).into()
}]
);
}
#[test]
fn function_return_type_error() {
assert_eq!(
interpret(
"test",
"
foo = fn () -> str { 'foo' }
bar: int = foo()
"
)
.unwrap_err()
.errors(),
&vec![DustError::Validation {
error: ValidationError::TypeCheck {
conflict: TypeConflict {
actual: Type::String,
expected: Type::Integer
},
actual_position: (66, 71).into(),
expected_position: Some((60, 63).into())
},
position: (55, 71).into()
}]
);
}