arith2.0 revision 204016
1251886Speter# $FreeBSD: head/tools/regression/bin/sh/expansion/arith2.0 204016 2010-02-17 22:22:20Z jilles $ 2251886Speter 3251886Speterfailures=0 4251886Speter 5251886Spetercheck() { 6251886Speter if [ $(($1)) != $2 ]; then 7251886Speter failures=$((failures+1)) 8251886Speter echo "For $1, expected $2 actual $(($1))" 9251886Speter fi 10289180Speter} 11289180Speter 12251886Speter# variables 13289180Speterunset v 14289180Spetercheck "v=2" 2 15289180Spetercheck "v" 2 16251886Spetercheck "$(($v))" 2 17251886Spetercheck "v+=1" 3 18251886Spetercheck "v" 3 19251886Speter 20251886Speter# constants 21251886Spetercheck "4611686018427387904" 4611686018427387904 22251886Spetercheck "0x4000000000000000" 4611686018427387904 23251886Spetercheck "0400000000000000000000" 4611686018427387904 24251886Spetercheck "0x4Ab0000000000000" 5381801554707742720 25251886Spetercheck "010" 8 26251886Speter 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, comma 76 77exit $((failures != 0)) 78