| 1 | #!/bin/sh |
| 2 | TEST_PREFIX="[let]" |
| 3 | . "$(cd "$(dirname "$0")" && pwd)/test_harness.sh" |
| 4 | |
| 5 | section "1. let arithmetic" |
| 6 | compare_output "let addition" 'let "x=5+3"; echo $x' |
| 7 | compare_output "let subtraction" 'let "x=10-3"; echo $x' |
| 8 | compare_output "let multiplication" 'let "x=4*3"; echo $x' |
| 9 | compare_output "let division" 'let "x=20/4"; echo $x' |
| 10 | compare_output "let modulo" 'let "x=17%5"; echo $x' |
| 11 | |
| 12 | section "2. let compound assignment" |
| 13 | compare_output "let increment" 'x=10; let "x++"; echo $x' |
| 14 | compare_output "let decrement" 'x=10; let "x--"; echo $x' |
| 15 | compare_output "let multiply assign" 'x=4; let "x*=3"; echo $x' |
| 16 | compare_output "let add assign" 'x=10; let "x+=5"; echo $x' |
| 17 | compare_output "let subtract assign" 'x=10; let "x-=3"; echo $x' |
| 18 | |
| 19 | section "3. let exit codes" |
| 20 | compare_exit "let nonzero result exits 0" 'let "1+1"' |
| 21 | compare_exit "let zero result exits 1" 'let "0"' |
| 22 | compare_exit "let comparison true" 'let "5 > 3"' |
| 23 | compare_exit "let comparison false" 'let "3 > 5"' |
| 24 | |
| 25 | section "4. let multiple expressions" |
| 26 | compare_output "let multiple args" 'let "x=5" "y=10" "z=x+y"; echo $z' |
| 27 | compare_output "let with variables" 'a=3; b=4; let "c=a*b"; echo $c' |
| 28 | |
| 29 | print_summary |