Add failing if_scopes() test

This commit is contained in:
mars 2022-03-26 21:54:52 -06:00
parent de051f71b8
commit eacd907c3b
1 changed files with 28 additions and 2 deletions

View File

@ -139,10 +139,36 @@ mod tests {
} else {
a
}
}
"#;
}"#;
let code_fn = jit_fn::<(i64, i64), i64>(source);
assert_eq!(code_fn((2, 4)), 2);
assert_eq!(code_fn((5, 3)), 3);
}
#[test]
fn if_scopes() {
// TODO this is overcomplicated for a test but i had fun writing it
let source = r#"
if_scopes(i64 a, i64 b) i64 {
let mut c = (a + b); // Test 1: 6, Test 2: 10
let d = (a * b); // Test 1: 8, Test 2: 21
let e = if a < b {
// Test 1 only
let d = (b - a); // 2
c = (c * d); // 12
d
} else {
// Test 2 only
// let d = (a - b); // 4
// c = (c * d); // 40
d
};
c + d + e // Test 1: 22, Test 2: 65
}"#;
let code_fn = jit_fn::<(i64, i64), i64>(source);
assert_eq!(code_fn((2, 4)), 22); // Test 1
assert_eq!(code_fn((7, 3)), 65); // Test 2
}
}