Skip to content

Commit

Permalink
reformat two tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aatxe committed Mar 6, 2024
1 parent faa7710 commit c23b210
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/sgir/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ fn test_kind_checking_trivial() {

#[test]
fn test_kind_checking_polymorphic_identity_function() {
let typ = Type::ForAll { parameters: vec![TypeBinding { id: "a".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Function { arguments: vec![Type::Variable("a".to_owned())],
result: Box::new(Type::Variable("a".to_owned())) }) };
let typ = Type::ForAll {
parameters: vec![TypeBinding { id: "a".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Function {
arguments: vec![Type::Variable("a".to_owned())],
result: Box::new(Type::Variable("a".to_owned()))
})
};
let kind = check_kinds(&HashMap::new(), typ);
assert_eq!(kind, Ok(Kind::Arrow { from: vec![Kind::Star], to: Box::new(Kind::Star) }));
}

#[test]
fn test_kind_checking_instantiated_polymorphic_identity_function() {
let typ = Type::Instantiate { typ: Box::new(Type::ForAll { parameters: vec![TypeBinding { id: "a".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Function { arguments: vec![Type::Variable("a".to_owned())],
result: Box::new(Type::Variable("a".to_owned())) }) }),
arguments: vec![Type::Number] };
let typ = Type::Instantiate {
typ: Box::new(Type::ForAll {
parameters: vec![TypeBinding { id: "a".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Function {
arguments: vec![Type::Variable("a".to_owned())],
result: Box::new(Type::Variable("a".to_owned()))
})
}),
arguments: vec![Type::Number]
};
let kind = check_kinds(&HashMap::new(), typ);
assert_eq!(kind, Ok(Kind::Star));
}
Expand All @@ -45,11 +55,19 @@ fn test_kind_checking_instantiated_monomorphic_type() {

#[test]
fn test_kind_checking_instantiated_polymorphic_function_with_type_constructor() {
let typ = Type::Instantiate { typ: Box::new(Type::ForAll { parameters: vec![TypeBinding { id: "a".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Function { arguments: vec![Type::Variable("a".to_owned())],
result: Box::new(Type::Variable("a".to_owned())) }) }),
arguments: vec![Type::ForAll { parameters: vec![TypeBinding { id: "b".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Variable("b".to_owned())) }] };
let typ = Type::Instantiate {
typ: Box::new(Type::ForAll {
parameters: vec![TypeBinding { id: "a".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Function {
arguments: vec![Type::Variable("a".to_owned())],
result: Box::new(Type::Variable("a".to_owned()))
})
}),
arguments: vec![Type::ForAll {
parameters: vec![TypeBinding { id: "b".to_owned(), kind: Kind::Star }],
typ: Box::new(Type::Variable("b".to_owned()))
}]
};
let kind = check_kinds(&HashMap::new(), typ);
assert_eq!(kind, Err(TypeError::KindMismatch { expected: Kind::Star, found: Kind::Arrow { from: vec![Kind::Star], to: Box::new(Kind::Star) }}));
}
Expand Down

0 comments on commit c23b210

Please sign in to comment.