Skip to content

Commit

Permalink
More decl info tests
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Feb 7, 2024
1 parent 46bce2b commit 12c5f41
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion crates/h10/src/decl_info/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ast::TopDecl;
use crate::parser::parse_module;

#[test]
fn id() {
fn simple_value() {
let pgm = "id x = x";
let mut decl_infos = program_decl_infos(pgm);
assert_eq!(decl_infos.len(), 1);
Expand All @@ -25,6 +25,61 @@ fn id() {
assert_eq!(to_sorted_vec(&used_values), empty_id_vec());
}

#[test]
fn simple_type() {
let pgm = "data X = A | B";
let mut decl_infos = program_decl_infos(pgm);
assert_eq!(decl_infos.len(), 1);

let DeclInfo {
defines: Defs {
tys: def_tys,
values: def_values,
},
uses: Uses {
tys: used_tys,
values: used_values,
},
} = decl_infos.remove(0);

assert_eq!(to_sorted_vec(&def_tys), vec!["X"]);
assert_eq!(to_sorted_vec(&def_values), vec!["A", "B"]);
assert_eq!(to_sorted_vec(&used_tys), empty_id_vec());
assert_eq!(to_sorted_vec(&used_values), empty_id_vec());
}

#[test]
fn simple_pattern() {
#[rustfmt::skip]
let lines = [
"f (a : b) = 1 + f b",
"f [] = 0",
];
let pgm = lines.join("\n");
let mut decl_infos = program_decl_infos(&pgm);
assert_eq!(decl_infos.len(), 2);

{
let DeclInfo {
defines:
Defs {
tys: def_tys,
values: def_values,
},
uses:
Uses {
tys: used_tys,
values: used_values,
},
} = decl_infos.remove(0);

assert_eq!(to_sorted_vec(&def_tys), empty_id_vec());
assert_eq!(to_sorted_vec(&def_values), vec!["f"]);
assert_eq!(to_sorted_vec(&used_tys), empty_id_vec());
assert_eq!(to_sorted_vec(&used_values), vec!["+", ":"]);
}
}

fn to_sorted_vec(set: &Set<String>) -> Vec<&str> {
let mut values: Vec<&str> = set.iter().map(|s| s.as_str()).collect();
values.sort();
Expand Down

0 comments on commit 12c5f41

Please sign in to comment.