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