use ast::Type;
#[test]
fn type_forall_precedence() {
let ty1 = Type::Func(
Box::new(Type::Forall(Box::new(Type::Func(
Box::new(Type::Var(0)),
Box::new(Type::Var(0)),
)))),
Box::new(Type::Int),
);
let ty2 = Type::Forall(Box::new(Type::Func(
Box::new(Type::Func(Box::new(Type::Var(0)), Box::new(Type::Var(0)))),
Box::new(Type::Int),
)));
assert_eq!(ty1.to_string(), "('a. 'a -> 'a) -> int");
assert_eq!(ty2.to_string(), "'a. ('a -> 'a) -> int");
}
#[test]
fn type_func_precedence() {
let ty1 = Type::Func(
Box::new(Type::Func(Box::new(Type::Int), Box::new(Type::Int))),
Box::new(Type::Int),
);
let ty2 = Type::Func(
Box::new(Type::Int),
Box::new(Type::Func(Box::new(Type::Int), Box::new(Type::Int))),
);
assert_eq!(ty1.to_string(), "(int -> int) -> int");
assert_eq!(ty2.to_string(), "int -> int -> int");
}
#[test]
fn type_list_precedence() {
let ty1 = Type::Func(
Box::new(Type::Int),
Box::new(Type::List(Box::new(Type::Int))),
);
let ty2 = Type::List(Box::new(Type::Func(
Box::new(Type::Int),
Box::new(Type::Int),
)));
let ty3 = Type::Forall(Box::new(Type::List(Box::new(Type::Var(0)))));
let ty4 = Type::List(Box::new(Type::Forall(Box::new(Type::Var(0)))));
let ty5 = Type::Forall(Box::new(Type::Func(
Box::new(Type::List(Box::new(Type::Var(0)))),
Box::new(Type::List(Box::new(Type::Var(0)))),
)));
let ty6 = Type::Forall(Box::new(Type::List(Box::new(Type::Func(
Box::new(Type::List(Box::new(Type::Var(0)))),
Box::new(Type::Var(0)),
)))));
assert_eq!(ty1.to_string(), "int -> int list");
assert_eq!(ty2.to_string(), "(int -> int) list");
assert_eq!(ty3.to_string(), "'a. 'a list");
assert_eq!(ty4.to_string(), "('a. 'a) list");
assert_eq!(ty5.to_string(), "'a. 'a list -> 'a list");
assert_eq!(ty6.to_string(), "'a. ('a list -> 'a) list");
}