✓
Passing This code compiles and runs correctly.
Code
// Test: Mock forces specific branch path (flow pruning)
//
// When an event has multiple branches, mocking forces ONE branch.
// This enables compile-time flow pruning - no switch statement needed.
~import "$std/testing"
// Event with multiple possible outcomes
~event withdraw { amount: u32 }
| success { new_balance: u32 }
| insufficient_funds {}
| account_locked {}
// Test: Mock forces success branch - verify the mocked value
~test(Withdrawal succeeds when mocked) {
~withdraw = success { new_balance: 50 }
~withdraw(amount: 100)
| success s |> assert(s.new_balance == 50)
}
// Test: Mock forces failure branch (different branch same event)
// For empty branches, just assert true to confirm branch was taken
~test(Withdrawal fails when funds insufficient) {
~withdraw = insufficient_funds {}
~withdraw(amount: 100)
| insufficient_funds |> assert(true)
}
pub fn main() void {}
Test Configuration
Post-validation Script:
#!/bin/bash
# Run the actual Zig tests to verify multiple branch mocking works
cd "$(dirname "$0")"
# Run zig test on the generated output
zig test output_emitted.zig 2>&1
exit $?