basic typing tests
This commit is contained in:
parent
ba838292f6
commit
e157bf036a
1 changed files with 33 additions and 0 deletions
33
src/typing/tests.rs
Normal file
33
src/typing/tests.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
use crate::{
|
||||||
|
ast::ModulePath,
|
||||||
|
parsing::parse_as_module,
|
||||||
|
typing::{
|
||||||
|
error::{TypeError, TypeErrorKind},
|
||||||
|
BinaryOperator, Type,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn addition_int_and_float() {
|
||||||
|
let source = "fn add(a: int, b: float) int { a + b }";
|
||||||
|
let mut ast = parse_as_module(source, ModulePath::default()).unwrap();
|
||||||
|
let res = ast.type_check();
|
||||||
|
assert!(res.is_err_and(|e| e.kind
|
||||||
|
== TypeErrorKind::InvalidBinaryOperator {
|
||||||
|
operator: BinaryOperator::Add,
|
||||||
|
lht: Type::Int,
|
||||||
|
rht: Type::Float
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn return_int_instead_of_float() {
|
||||||
|
let source = "fn add(a: int, b: int) float { a + b }";
|
||||||
|
let mut ast = parse_as_module(source, ModulePath::default()).unwrap();
|
||||||
|
let res = ast.type_check();
|
||||||
|
assert!(res.is_err_and(|e| e.kind
|
||||||
|
== TypeErrorKind::BlockTypeDoesNotMatchFunctionType {
|
||||||
|
block_type: Type::Int,
|
||||||
|
function_type: Type::Float
|
||||||
|
}));
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue