arith2.0 revision 209652
1201428Sjilles# $FreeBSD: head/tools/regression/bin/sh/expansion/arith2.0 209652 2010-07-02 21:31:24Z jilles $ 2201428Sjilles 3201428Sjillesfailures=0 4201428Sjilles 5201428Sjillescheck() { 6201428Sjilles if [ $(($1)) != $2 ]; then 7201428Sjilles failures=$((failures+1)) 8201428Sjilles echo "For $1, expected $2 actual $(($1))" 9201428Sjilles fi 10201428Sjilles} 11201428Sjilles 12201428Sjilles# variables 13201428Sjillesunset v 14201428Sjillescheck "v=2" 2 15201428Sjillescheck "v" 2 16201428Sjillescheck "$(($v))" 2 17201428Sjillescheck "v+=1" 3 18201428Sjillescheck "v" 3 19201428Sjilles 20201428Sjilles# constants 21201428Sjillescheck "4611686018427387904" 4611686018427387904 22201428Sjillescheck "0x4000000000000000" 4611686018427387904 23201428Sjillescheck "0400000000000000000000" 4611686018427387904 24201428Sjillescheck "0x4Ab0000000000000" 5381801554707742720 25204016Sjillescheck "010" 8 26201428Sjilles 27201428Sjilles# try out all operators 28201428Sjillesv=42 29201428Sjillescheck "!v" 0 30201428Sjillescheck "!!v" 1 31201428Sjillescheck "!0" 1 32201428Sjillescheck "~0" -1 33201428Sjillescheck "~(-1)" 0 34201428Sjillescheck "-0" 0 35201428Sjillescheck "-v" -42 36201428Sjillescheck "v*v" 1764 37201428Sjillescheck "v/2" 21 38201428Sjillescheck "v%10" 2 39201428Sjillescheck "v+v" 84 40201428Sjillescheck "v-4" 38 41201428Sjillescheck "v<<1" 84 42201428Sjillescheck "v>>1" 21 43201428Sjillescheck "v<43" 1 44201428Sjillescheck "v>42" 0 45201428Sjillescheck "v<=43" 1 46201428Sjillescheck "v>=43" 0 47201428Sjillescheck "v==41" 0 48201428Sjillescheck "v!=42" 0 49201428Sjillescheck "v&3" 2 50201428Sjillescheck "v^3" 41 51201428Sjillescheck "v|3" 43 52201428Sjillescheck "v>=40&&v<=44" 1 53201428Sjillescheck "v<40||v>44" 0 54201428Sjillescheck "(v=42)&&(v+=1)==43" 1 55201428Sjillescheck "v" 43 56201428Sjillescheck "(v=42)&&(v-=1)==41" 1 57201428Sjillescheck "v" 41 58201428Sjillescheck "(v=42)&&(v*=2)==84" 1 59201428Sjillescheck "v" 84 60201428Sjillescheck "(v=42)&&(v/=10)==4" 1 61201428Sjillescheck "v" 4 62201428Sjillescheck "(v=42)&&(v%=10)==2" 1 63201428Sjillescheck "v" 2 64201428Sjillescheck "(v=42)&&(v<<=1)==84" 1 65201428Sjillescheck "v" 84 66201428Sjillescheck "(v=42)&&(v>>=2)==10" 1 67201428Sjillescheck "v" 10 68201428Sjillescheck "(v=42)&&(v&=32)==32" 1 69201428Sjillescheck "v" 32 70201428Sjillescheck "(v=42)&&(v^=32)==10" 1 71201428Sjillescheck "v" 10 72201428Sjillescheck "(v=42)&&(v|=32)==42" 1 73201428Sjillescheck "v" 42 74201428Sjilles 75209652Sjilles# missing: ternary 76201428Sjilles 77201428Sjillesexit $((failures != 0)) 78