xref: /openbsd/regress/bin/ksh/arith.t (revision 73471bf0)
1name: arith-lazy-1
2description:
3	Check that only one side of ternary operator is evaluated
4stdin:
5	x=i+=2
6	y=j+=2
7	typeset -i i=1 j=1
8	echo $((1 ? 20 : (x+=2)))
9	echo $i,$x
10	echo $((0 ? (y+=2) : 30))
11	echo $j,$y
12expected-stdout:
13	20
14	1,i+=2
15	30
16	1,j+=2
17---
18
19name: arith-lazy-2
20description:
21	Check that assignments not done on non-evaluated side of ternary
22	operator
23stdin:
24	x=i+=2
25	y=j+=2
26	typeset -i i=1 j=1
27	echo $((1 ? 20 : (x+=2)))
28	echo $i,$x
29	echo $((0 ? (y+=2) : 30))
30	echo $i,$y
31expected-stdout:
32	20
33	1,i+=2
34	30
35	1,j+=2
36---
37
38name: arith-ternary-prec-1
39description:
40	Check precidance of ternary operator vs assignment
41stdin:
42	typeset -i x=2
43	y=$((1 ? 20 : x+=2))
44expected-exit: e != 0
45expected-stderr-pattern:
46	/.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
47---
48
49name: arith-ternary-prec-2
50description:
51	Check precidance of ternary operator vs assignment
52stdin:
53	typeset -i x=2
54	echo $((0 ? x+=2 : 20))
55expected-stdout:
56	20
57---
58
59name: arith-div-assoc-1
60description:
61	Check associativity of division operator
62stdin:
63	echo $((20 / 2 / 2))
64expected-stdout:
65	5
66---
67
68name: arith-assop-assoc-1
69description:
70	Check associativity of assignment-operator operator
71stdin:
72	typeset -i i=1 j=2 k=3
73	echo $((i += j += k))
74	echo $i,$j,$k
75expected-stdout:
76	6
77	6,5,3
78---
79
80name: check-octal-valid-1
81description:
82	Check octal notation (valid input)
83stdin:
84	echo $((00)),$((-00)),$((007)),$((-007)),$((010)),$((-010))
85	echo $((010 + 1))
86expected-stdout:
87	0,0,7,-7,8,-8
88	9
89
90---
91
92name: check-octal-invalid-1
93description:
94	Check octal notation (invalid input)
95stdin:
96	echo $((08))
97expected-exit: e != 0
98expected-stderr-pattern:
99	/.*:.*08.*bad number/
100
101---
102name: check-hex-valid-1
103description:
104	Check hex notation (valid input)
105stdin:
106	echo $((0x0)),$((-0x0)),$((0xf)),$((-0xf)),$((0x10)),$((-0x10))
107	echo $((0x10 + 1))
108expected-stdout:
109	0,0,15,-15,16,-16
110	17
111
112---
113
114name: check-hex-invalid-1
115description:
116	Check hex notation (invalid input)
117stdin:
118	echo $((0xg))
119expected-exit: e != 0
120expected-stderr-pattern:
121	/.*:.* 0xg.*bad number/
122
123---
124
125name: arith-recurse-1
126description:
127	Check that arithmetic evaluation substitutes integer values
128	of variables recursively.
129stdin:
130	vb=va
131	va=42
132	echo $((vb))
133expected-stdout:
134	42
135
136---
137
138name: arith-recurse-2
139description:
140	Check that variables can be used as array indices.
141stdin:
142	vb='aa[va]'
143	set -A aa 40 41 42 43
144	va=2
145	echo ${aa[va]}
146	echo ${aa[$va]}
147	echo $((aa[va]))
148	echo $((aa[$va]))
149	echo $((vb))
150expected-stdout:
151	42
152	42
153	42
154	42
155	42
156
157---
158
159name: arith-subst-1
160description:
161	Check that arithmetic evaluation does not apply parameter
162	substitution to the values of variables.
163stdin:
164	va=17
165	vb='$va'
166	echo $((vb))
167expected-exit: e != 0
168expected-stderr-pattern:
169	/.*:.*\$va.*unexpected.*\$/
170
171---
172
173name: arith-subst-2
174description:
175	Check that arithmetic evaluation does not apply parameter
176	substitution to arry indices inside the values of variables.
177stdin:
178	set -A aa 40 41 42 43
179	va=2
180	vb='aa[$va]'
181	echo $((vb))
182expected-exit: e != 0
183expected-stderr-pattern:
184	/.*:.*\$va.*unexpected.*\$/
185
186---
187