1
0

86 lines
2.0 KiB
Rust
Raw Normal View History

2024-01-31 19:35:27 -05:00
use dust_lang::{error::ValidationError, *};
2024-01-06 02:26:51 -05:00
#[test]
fn simple_type_check() {
let result = interpret("x <bool> = 1");
2024-01-31 19:35:27 -05:00
assert_eq!(
Err(Error::Validation(ValidationError::TypeCheck {
expected: Type::Boolean,
actual: Type::Integer,
position: SourcePosition {
start_byte: 0,
2024-01-31 21:21:42 -05:00
end_byte: 12,
start_row: 1,
2024-01-31 19:35:27 -05:00
start_column: 0,
2024-01-31 21:21:42 -05:00
end_row: 1,
end_column: 12,
2024-01-31 19:35:27 -05:00
}
})),
result
);
2024-01-06 02:26:51 -05:00
}
#[test]
fn argument_count_check() {
let source = "
2024-01-09 20:38:40 -05:00
foo = (x <int>) <int> {
2024-01-06 02:26:51 -05:00
x
}
foo()
";
2024-01-23 17:08:26 -05:00
let result = interpret(source);
2024-01-06 02:26:51 -05:00
assert_eq!(
2024-02-13 08:10:34 -05:00
Err(Error::Validation(
ValidationError::ExpectedFunctionArgumentAmount {
expected: 1,
actual: 0,
position: SourcePosition {
start_byte: 81,
end_byte: 86,
start_row: 5,
start_column: 12,
end_row: 5,
end_column: 17
}
}
)),
result
2024-01-06 02:26:51 -05:00
)
}
#[test]
fn callback_type_check() {
let result = interpret(
"
x = (cb <() -> bool>) <bool> {
cb()
}
x(() <int> { 1 })
",
);
2024-01-31 19:35:27 -05:00
assert_eq!(
Err(Error::Validation(ValidationError::TypeCheck {
expected: Type::Function {
parameter_types: vec![],
return_type: Box::new(Type::Boolean),
},
actual: Type::Function {
parameter_types: vec![],
return_type: Box::new(Type::Integer),
},
position: SourcePosition {
2024-01-31 21:21:42 -05:00
start_byte: 91,
end_byte: 108,
start_row: 5,
start_column: 12,
end_row: 5,
end_column: 29,
2024-01-31 19:35:27 -05:00
}
})),
result
);
2024-01-06 02:26:51 -05:00
}