add tests

This commit is contained in:
Folkert 2020-03-19 14:59:05 +01:00
parent 006b1f8696
commit 9745d86efb
2 changed files with 42 additions and 21 deletions

View file

@ -614,22 +614,21 @@ mod test_gen {
); );
} }
// doesn't work yet. The condition must be cast to an integer to use a jump table #[test]
// #[test] fn branch_third_float() {
// fn branch_third_float() { assert_evals_to!(
// assert_evals_to!( indoc!(
// indoc!( r#"
// r#" when 10.0 is
// when 10.0 is 1.0 -> 63
// 1.0 -> 63 2.0 -> 48
// 2 -> 48 _ -> 112
// _ -> 112 "#
// "# ),
// ), 112,
// 112.0, i64
// f64 );
// ); }
// }
#[test] #[test]
fn branch_first_int() { fn branch_first_int() {
@ -1297,11 +1296,14 @@ mod test_gen {
assert_evals_to!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
x : [ This Int, These Int Int ] These a b : [ This a, That b, These a b ]
x : These Int Int
x = These 0x3 0x2 x = These 0x3 0x2
when x is when x is
These a b -> a + b These a b -> a + b
That v -> 8
This v -> v This v -> v
"# "#
), ),
@ -1331,6 +1333,26 @@ mod test_gen {
); );
} }
// #[test]
// fn when_on_just_just() {
// assert_evals_to!(
// indoc!(
// r#"
// Maybe a : [ Nothing, Just a ]
//
// x : Maybe (Maybe a)
// x = Just (Just 41)
//
// when x is
// Just (Just v) -> v + 0x1
// _ -> 0x1
// "#
// ),
// 42,
// i64
// );
// }
// #[test] // #[test]
// fn linked_list_empty() { // fn linked_list_empty() {
// assert_evals_to!( // assert_evals_to!(

View file

@ -156,7 +156,7 @@ fn flatten<'a>(path_pattern: (Path, Pattern<'a>), path_patterns: &mut Vec<(Path,
// dearg (Can.PatternCtorArg _ _ pattern) = // dearg (Can.PatternCtorArg _ _ pattern) =
// pattern // pattern
todo!() todo!("alternatives: {:?}", union.alternatives)
} else { } else {
path_patterns.push(path_pattern); path_patterns.push(path_pattern);
} }
@ -911,7 +911,8 @@ fn decide_to_branching<'a>(
Test::IsFloat(v) => v as u64, Test::IsFloat(v) => v as u64,
Test::IsBit(v) => v as u64, Test::IsBit(v) => v as u64,
Test::IsByte { tag_id, .. } => tag_id as u64, Test::IsByte { tag_id, .. } => tag_id as u64,
_ => todo!(), Test::IsCtor { tag_id, .. } => tag_id as u64,
other => todo!("other {:?}", other),
}; };
branches.push((tag, branch)); branches.push((tag, branch));
@ -921,9 +922,7 @@ fn decide_to_branching<'a>(
Expr::Switch { Expr::Switch {
cond, cond,
cond_layout, cond_layout,
// branches: &'a [(u64, Expr<'a>)],
branches: branches.into_bump_slice(), branches: branches.into_bump_slice(),
// default_branch: &'a Expr<'a>,
default_branch, default_branch,
ret_layout, ret_layout,
} }