From eacd907c3bf2d4ad684d8b8be1ec1127c12b824b Mon Sep 17 00:00:00 2001 From: mars Date: Sat, 26 Mar 2022 21:54:52 -0600 Subject: [PATCH] Add failing if_scopes() test --- src/jit/engine.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/jit/engine.rs b/src/jit/engine.rs index 6a993fd..21f34d4 100644 --- a/src/jit/engine.rs +++ b/src/jit/engine.rs @@ -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 + } }