// Test case: If-else control flow
//
// This file tests if-else support in WASM compilation.
// Expected features:
// - Simple if statements
// - if-else statements
// - if-else if-else chains
// - Nested if statements
// - If as expression (returning value)
module if_else_test @ 0.1.0
// Test 1: Simple if with return
fun test_simple_if(x: i64) -> i64 {
if x > 0 {
return 1
}
return 0
}
// Test 2: If-else
fun test_if_else(x: i64) -> i64 {
if x > 0 {
return 1
} else {
return -1
}
}
// Test 3: If-else if-else chain
fun test_if_else_chain(x: i64) -> i64 {
if x > 0 {
return 1
} else if x < 0 {
return -1
} else {
return 0
}
}
// Test 4: Max function
fun test_max(a: i64, b: i64) -> i64 {
if a > b {
return a
} else {
return b
}
}
// Test 5: Min function
fun test_min(a: i64, b: i64) -> i64 {
if a < b {
return a
} else {
return b
}
}
// Test 6: Absolute value
fun test_abs(x: i64) -> i64 {
if x < 0 {
return 0 - x
}
return x
}
// Test 7: Clamp function
fun test_clamp(x: i64, low: i64, high: i64) -> i64 {
if x < low {
return low
}
if x > high {
return high
}
return x
}
// Test 8: Nested if statements
fun test_nested_if(x: i64, y: i64) -> i64 {
if x > 0 {
if y > 0 {
return 1
} else {
return 2
}
} else {
if y > 0 {
return 3
} else {
return 4
}
}
}
// Test 9: If with complex condition
fun test_complex_condition(a: i64, b: i64, c: i64) -> i64 {
if a > 0 && b > 0 && c > 0 {
return 1
}
return 0
}
// Test 10: If with or condition
fun test_or_condition(a: i64, b: i64) -> i64 {
if a == 0 || b == 0 {
return 0
}
return a * b
}
// Test 11: Sign function
fun test_sign(x: i64) -> i64 {
if x > 0 {
return 1
} else if x < 0 {
return -1
} else {
return 0
}
}
// Test 12: Comparison classification
fun test_classify_comparison(a: i64, b: i64) -> i64 {
if a > b {
return 1
}
if a < b {
return -1
}
return 0
}