arith2.0 revision 201428
1201428Sjilles# $FreeBSD: head/tools/regression/bin/sh/expansion/arith2.0 201428 2010-01-03 12:50:27Z 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 25201428Sjilles 26201428Sjilles# try out all operators 27201428Sjillesv=42 28201428Sjillescheck "!v" 0 29201428Sjillescheck "!!v" 1 30201428Sjillescheck "!0" 1 31201428Sjillescheck "~0" -1 32201428Sjillescheck "~(-1)" 0 33201428Sjillescheck "-0" 0 34201428Sjillescheck "-v" -42 35201428Sjillescheck "v*v" 1764 36201428Sjillescheck "v/2" 21 37201428Sjillescheck "v%10" 2 38201428Sjillescheck "v+v" 84 39201428Sjillescheck "v-4" 38 40201428Sjillescheck "v<<1" 84 41201428Sjillescheck "v>>1" 21 42201428Sjillescheck "v<43" 1 43201428Sjillescheck "v>42" 0 44201428Sjillescheck "v<=43" 1 45201428Sjillescheck "v>=43" 0 46201428Sjillescheck "v==41" 0 47201428Sjillescheck "v!=42" 0 48201428Sjillescheck "v&3" 2 49201428Sjillescheck "v^3" 41 50201428Sjillescheck "v|3" 43 51201428Sjillescheck "v>=40&&v<=44" 1 52201428Sjillescheck "v<40||v>44" 0 53201428Sjillescheck "(v=42)&&(v+=1)==43" 1 54201428Sjillescheck "v" 43 55201428Sjillescheck "(v=42)&&(v-=1)==41" 1 56201428Sjillescheck "v" 41 57201428Sjillescheck "(v=42)&&(v*=2)==84" 1 58201428Sjillescheck "v" 84 59201428Sjillescheck "(v=42)&&(v/=10)==4" 1 60201428Sjillescheck "v" 4 61201428Sjillescheck "(v=42)&&(v%=10)==2" 1 62201428Sjillescheck "v" 2 63201428Sjillescheck "(v=42)&&(v<<=1)==84" 1 64201428Sjillescheck "v" 84 65201428Sjillescheck "(v=42)&&(v>>=2)==10" 1 66201428Sjillescheck "v" 10 67201428Sjillescheck "(v=42)&&(v&=32)==32" 1 68201428Sjillescheck "v" 32 69201428Sjillescheck "(v=42)&&(v^=32)==10" 1 70201428Sjillescheck "v" 10 71201428Sjillescheck "(v=42)&&(v|=32)==42" 1 72201428Sjillescheck "v" 42 73201428Sjilles 74201428Sjilles# missing: ternary, comma 75201428Sjilles 76201428Sjillesexit $((failures != 0)) 77