xref: /openbsd/regress/bin/ksh/integer.t (revision 4bdff4be)
1name: integer-base-err-1
2description:
3	Can't have 0 base (causes shell to exit)
4expected-exit: e != 0
5stdin:
6	typeset -i i
7	i=3
8	i=0#4
9	echo $i
10expected-stderr-pattern:
11	/^.*:.*0#4.*\n$/
12---
13
14name: integer-base-err-2
15description:
16	Can't have multiple bases in a `constant' (causes shell to exit)
17	(ksh88 fails this test)
18expected-exit: e != 0
19stdin:
20	typeset -i i
21	i=3
22	i=2#110#11
23	echo $i
24expected-stderr-pattern:
25	/^.*:.*2#110#11.*\n$/
26---
27
28name: integer-base-err-3
29description:
30	Syntax errors in expressions and effects on bases
31	(interactive so errors don't cause exits)
32	(ksh88 fails this test - shell exits, even with -i)
33arguments: !-i!
34stdin:
35	PS1= # minimize prompt hassles
36	typeset -i4 a=10
37	typeset -i a=2+
38	echo $a
39	typeset -i4 a=10
40	typeset -i2 a=2+
41	echo $a
42expected-stderr-pattern:
43	/^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/m
44expected-stdout:
45	4#22
46	4#22
47---
48
49name: integer-base-err-4
50description:
51	Are invalid digits (according to base) errors?
52	(ksh93 fails this test)
53expected-exit: e != 0
54stdin:
55	typeset -i i;
56	i=3#4
57expected-stderr-pattern:
58	/^([#\$] )?.*:.*3#4.*\n$/
59---
60
61
62name: integer-base-1
63description:
64	Missing number after base is treated as 0.
65stdin:
66	typeset -i i
67	i=3
68	i=2#
69	echo $i
70expected-stdout:
71	0
72---
73
74name: integer-base-2
75description:
76	Check `stickyness' of base in various situations
77stdin:
78	typeset -i i=8
79	echo $i
80	echo ---------- A
81	typeset -i4 j=8
82	echo $j
83	echo ---------- B
84	typeset -i k=8
85	typeset -i4 k=8
86	echo $k
87	echo ---------- C
88	typeset -i4 l
89	l=3#10
90	echo $l
91	echo ---------- D
92	typeset -i m
93	m=3#10
94	echo $m
95	echo ---------- E
96	n=2#11
97	typeset -i n
98	echo $n
99	n=10
100	echo $n
101	echo ---------- F
102	typeset -i8 o=12
103	typeset -i4 o
104	echo $o
105	echo ---------- G
106	typeset -i p
107	let p=8#12
108	echo $p
109expected-stdout:
110	8
111	---------- A
112	4#20
113	---------- B
114	4#20
115	---------- C
116	4#3
117	---------- D
118	3#10
119	---------- E
120	2#11
121	2#1010
122	---------- F
123	4#30
124	---------- G
125	8#12
126---
127
128name: integer-base-3
129description:
130	More base parsing (hmm doesn't test much..)
131stdin:
132	typeset -i aa
133	aa=1+12#10+2
134	echo $aa
135	typeset -i bb
136	bb=1+$aa
137	echo $bb
138	typeset -i bb
139	bb=$aa
140	echo $bb
141	typeset -i cc
142	cc=$aa
143	echo $cc
144expected-stdout:
145	15
146	16
147	15
148	15
149---
150
151name: integer-base-4
152description:
153	Check that things not declared as integers are not made integers,
154	also, check if base is not reset by -i with no arguments.
155	(ksh93 fails - prints 10#20 - go figure)
156stdin:
157	xx=20
158	let xx=10
159	typeset -i | grep '^xx='
160	typeset -i4 a=10
161	typeset -i a=20
162	echo $a
163expected-stdout:
164	4#110
165---
166
167name: integer-base-5
168description:
169	More base stuff
170stdin:
171	typeset -i4 a=3#10
172	echo $a
173	echo --
174	typeset -i j=3
175	j=~3
176	echo $j
177	echo --
178	typeset -i k=1
179	x[k=k+1]=3
180	echo $k
181	echo --
182	typeset -i l
183	for l in 1 2+3 4; do echo $l; done
184expected-stdout:
185	4#3
186	--
187	-4
188	--
189	2
190	--
191	1
192	5
193	4
194---
195
196name: integer-base-6
197description:
198	Even more base stuff
199	(ksh93 fails this test - prints 0)
200stdin:
201	typeset -i7 i
202	i=
203	echo $i
204expected-stdout:
205	7#0
206---
207
208name: integer-base-7
209description:
210	Check that non-integer parameters don't get bases assigned
211stdin:
212	echo $(( zz = 8#100 ))
213	echo $zz
214expected-stdout:
215	64
216	64
217---
218
219name: integer-1
220description:
221	Check that 64 bit integers get assigned
222stdin:
223	echo $(( zz = 0x7fffffffffffffff))
224	echo $zz
225expected-stdout:
226	9223372036854775807
227	9223372036854775807
228---
229
230