add tests for dead code elim

This commit is contained in:
collin 2021-03-23 15:49:56 -07:00
parent 99efdf00cb
commit 113ba12959
6 changed files with 37 additions and 7 deletions

View File

@ -0,0 +1,7 @@
function main () {
let mut x = 100i8;
if false {
x = 1i8;
x *= 100i8;
}
}

View File

@ -51,13 +51,7 @@ fn test_const_fail() {
#[test]
fn test_cond_mut() {
let program_string = r#"function main () {
let mut x = 100i8;
if false {
x = 1i8;
x *= 100i8;
}
}"#;
let program_string = include_str!("cond_mut.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);

View File

@ -0,0 +1,9 @@
function main (x: bool) -> bool {
if false {
return x
} else if x {
return false
} else {
return false
}
}

View File

@ -0,0 +1,5 @@
[main]
x: bool = true;
[registers]
r: bool = false;

View File

@ -221,3 +221,16 @@ fn test_multiple_returns() {
output_zero(program);
}
#[test]
fn test_cond_switch() {
let input_string = include_str!("input/cond_switch.in");
let program_string = include_str!("cond_switch.leo");
let expect_output = include_bytes!("output/cond_switch.out");
let program = parse_program_with_input(program_string, input_string).unwrap();
let actual_output = get_output(program);
assert_eq!(expect_output, actual_output.bytes().as_slice());
}

View File

@ -0,0 +1,2 @@
[registers]
r: bool = false;