1# $FreeBSD$ 2 3failures=0 4 5check() { 6 if [ $(($1)) != $2 ]; then 7 failures=$((failures+1)) 8 echo "For $1, expected $2 actual $(($1))" 9 fi 10} 11 12# variables 13unset v 14check "v=2" 2 15check "v" 2 16check "$(($v))" 2 17check "v+=1" 3 18check "v" 3 19 20# constants 21check "4611686018427387904" 4611686018427387904 22check "0x4000000000000000" 4611686018427387904 23check "0400000000000000000000" 4611686018427387904 24check "0x4Ab0000000000000" 5381801554707742720 25check "010" 8 26 27# try out all operators 28v=42 29check "!v" 0 30check "!!v" 1 31check "!0" 1 32check "~0" -1 33check "~(-1)" 0 34check "-0" 0 35check "-v" -42 36check "v*v" 1764 37check "v/2" 21 38check "v%10" 2 39check "v+v" 84 40check "v-4" 38 41check "v<<1" 84 42check "v>>1" 21 43check "v<43" 1 44check "v>42" 0 45check "v<=43" 1 46check "v>=43" 0 47check "v==41" 0 48check "v!=42" 0 49check "v&3" 2 50check "v^3" 41 51check "v|3" 43 52check "v>=40&&v<=44" 1 53check "v<40||v>44" 0 54check "(v=42)&&(v+=1)==43" 1 55check "v" 43 56check "(v=42)&&(v-=1)==41" 1 57check "v" 41 58check "(v=42)&&(v*=2)==84" 1 59check "v" 84 60check "(v=42)&&(v/=10)==4" 1 61check "v" 4 62check "(v=42)&&(v%=10)==2" 1 63check "v" 2 64check "(v=42)&&(v<<=1)==84" 1 65check "v" 84 66check "(v=42)&&(v>>=2)==10" 1 67check "v" 10 68check "(v=42)&&(v&=32)==32" 1 69check "v" 32 70check "(v=42)&&(v^=32)==10" 1 71check "v" 10 72check "(v=42)&&(v|=32)==42" 1 73check "v" 42 74 75# missing: ternary 76 77exit $((failures != 0)) 78