Skip to content

Commit

Permalink
Temp fix, I need more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 26, 2024
1 parent 135f459 commit 57c0f69
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/rue-typing/src/check/check_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ fn check_union_against_rhs(
Type::PublicKey if attrs.atoms_are_public_key() => Check::IsAtom,
Type::PublicKey => Check::And(vec![Check::IsAtom, Check::Length(48)]),
Type::Pair(..) if attrs.all_atoms() => Check::False,
Type::Pair(..) if attrs.pairs.len() == 1 && attrs.atom_count == attrs.length - 1 => {
Check::IsPair
}
Type::Pair(first, rest) => {
let (first, rest) = (*first, *rest);

Expand Down Expand Up @@ -539,6 +542,15 @@ mod tests {
check_str(&mut db, list, pair, "(l val)");
}

#[test]
fn test_check_list_pair_generic() {
let mut db = TypeSystem::new();
let generic = db.alloc(Type::Generic);
let list = alloc_list(&mut db, generic);
let pair = db.alloc(Type::Pair(generic, list));
check_str(&mut db, list, pair, "(l val)");
}

#[test]
fn test_check_any_list() {
let mut db = TypeSystem::new();
Expand Down
21 changes: 21 additions & 0 deletions crates/rue-typing/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,4 +795,25 @@ mod tests {
Comparison::Castable
);
}

#[test]
fn test_compare_generic_equal() {
let mut db = TypeSystem::new();
let types = db.std();
let generic = db.alloc(Type::Generic);
assert_eq!(db.compare(types.int, generic), Comparison::Incompatible);
assert_eq!(db.compare(generic, generic), Comparison::Equal);
}

#[test]
fn test_compare_generic_list_assignable() {
let mut db = TypeSystem::new();
let types = db.std();
let generic = db.alloc(Type::Generic);
let list = alloc_list(&mut db, generic);
let pair = db.alloc(Type::Pair(generic, list));
assert_eq!(db.compare(types.nil, list), Comparison::Assignable);
assert_eq!(db.compare(list, list), Comparison::Equal);
assert_eq!(db.compare(pair, list), Comparison::Assignable);
}
}

0 comments on commit 57c0f69

Please sign in to comment.