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