xref: /openbsd-src/regress/bin/ksh/integer.t (revision 517d3880010591498a8b274d9d8fd7e787d73ebe)
17a45d967Smillertname: integer-base-err-1
27a45d967Smillertdescription:
37a45d967Smillert	Can't have 0 base (causes shell to exit)
47a45d967Smillertexpected-exit: e != 0
57a45d967Smillertstdin:
67a45d967Smillert	typeset -i i
77a45d967Smillert	i=3
87a45d967Smillert	i=0#4
97a45d967Smillert	echo $i
107a45d967Smillertexpected-stderr-pattern:
117a45d967Smillert	/^.*:.*0#4.*\n$/
127a45d967Smillert---
137a45d967Smillert
147a45d967Smillertname: integer-base-err-2
157a45d967Smillertdescription:
167a45d967Smillert	Can't have multiple bases in a `constant' (causes shell to exit)
177a45d967Smillert	(ksh88 fails this test)
187a45d967Smillertexpected-exit: e != 0
197a45d967Smillertstdin:
207a45d967Smillert	typeset -i i
217a45d967Smillert	i=3
227a45d967Smillert	i=2#110#11
237a45d967Smillert	echo $i
247a45d967Smillertexpected-stderr-pattern:
257a45d967Smillert	/^.*:.*2#110#11.*\n$/
267a45d967Smillert---
277a45d967Smillert
287a45d967Smillertname: integer-base-err-3
297a45d967Smillertdescription:
307a45d967Smillert	Syntax errors in expressions and effects on bases
317a45d967Smillert	(interactive so errors don't cause exits)
327a45d967Smillert	(ksh88 fails this test - shell exits, even with -i)
337a45d967Smillertarguments: !-i!
347a45d967Smillertstdin:
357a45d967Smillert	PS1= # minimize prompt hassles
367a45d967Smillert	typeset -i4 a=10
377a45d967Smillert	typeset -i a=2+
387a45d967Smillert	echo $a
397a45d967Smillert	typeset -i4 a=10
407a45d967Smillert	typeset -i2 a=2+
417a45d967Smillert	echo $a
427a45d967Smillertexpected-stderr-pattern:
43d67abc0bSbluhm	/^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/m
447a45d967Smillertexpected-stdout:
457a45d967Smillert	4#22
467a45d967Smillert	4#22
477a45d967Smillert---
487a45d967Smillert
497a45d967Smillertname: integer-base-err-4
507a45d967Smillertdescription:
517a45d967Smillert	Are invalid digits (according to base) errors?
527a45d967Smillert	(ksh93 fails this test)
537a45d967Smillertexpected-exit: e != 0
547a45d967Smillertstdin:
557a45d967Smillert	typeset -i i;
567a45d967Smillert	i=3#4
577a45d967Smillertexpected-stderr-pattern:
587a45d967Smillert	/^([#\$] )?.*:.*3#4.*\n$/
597a45d967Smillert---
607a45d967Smillert
617a45d967Smillert
627a45d967Smillertname: integer-base-1
637a45d967Smillertdescription:
647a45d967Smillert	Missing number after base is treated as 0.
657a45d967Smillertstdin:
667a45d967Smillert	typeset -i i
677a45d967Smillert	i=3
687a45d967Smillert	i=2#
697a45d967Smillert	echo $i
707a45d967Smillertexpected-stdout:
717a45d967Smillert	0
727a45d967Smillert---
737a45d967Smillert
747a45d967Smillertname: integer-base-2
757a45d967Smillertdescription:
767a45d967Smillert	Check `stickyness' of base in various situations
777a45d967Smillertstdin:
787a45d967Smillert	typeset -i i=8
797a45d967Smillert	echo $i
807a45d967Smillert	echo ---------- A
817a45d967Smillert	typeset -i4 j=8
827a45d967Smillert	echo $j
837a45d967Smillert	echo ---------- B
847a45d967Smillert	typeset -i k=8
857a45d967Smillert	typeset -i4 k=8
867a45d967Smillert	echo $k
877a45d967Smillert	echo ---------- C
887a45d967Smillert	typeset -i4 l
897a45d967Smillert	l=3#10
907a45d967Smillert	echo $l
917a45d967Smillert	echo ---------- D
927a45d967Smillert	typeset -i m
937a45d967Smillert	m=3#10
947a45d967Smillert	echo $m
957a45d967Smillert	echo ---------- E
967a45d967Smillert	n=2#11
977a45d967Smillert	typeset -i n
987a45d967Smillert	echo $n
997a45d967Smillert	n=10
1007a45d967Smillert	echo $n
1017a45d967Smillert	echo ---------- F
1027a45d967Smillert	typeset -i8 o=12
1037a45d967Smillert	typeset -i4 o
1047a45d967Smillert	echo $o
1057a45d967Smillert	echo ---------- G
1067a45d967Smillert	typeset -i p
1077a45d967Smillert	let p=8#12
1087a45d967Smillert	echo $p
1097a45d967Smillertexpected-stdout:
1107a45d967Smillert	8
1117a45d967Smillert	---------- A
1127a45d967Smillert	4#20
1137a45d967Smillert	---------- B
1147a45d967Smillert	4#20
1157a45d967Smillert	---------- C
1167a45d967Smillert	4#3
1177a45d967Smillert	---------- D
1187a45d967Smillert	3#10
1197a45d967Smillert	---------- E
1207a45d967Smillert	2#11
1217a45d967Smillert	2#1010
1227a45d967Smillert	---------- F
1237a45d967Smillert	4#30
1247a45d967Smillert	---------- G
1257a45d967Smillert	8#12
1267a45d967Smillert---
1277a45d967Smillert
1287a45d967Smillertname: integer-base-3
1297a45d967Smillertdescription:
1307a45d967Smillert	More base parsing (hmm doesn't test much..)
1317a45d967Smillertstdin:
1327a45d967Smillert	typeset -i aa
1337a45d967Smillert	aa=1+12#10+2
1347a45d967Smillert	echo $aa
1357a45d967Smillert	typeset -i bb
1367a45d967Smillert	bb=1+$aa
1377a45d967Smillert	echo $bb
1387a45d967Smillert	typeset -i bb
1397a45d967Smillert	bb=$aa
1407a45d967Smillert	echo $bb
1417a45d967Smillert	typeset -i cc
1427a45d967Smillert	cc=$aa
1437a45d967Smillert	echo $cc
1447a45d967Smillertexpected-stdout:
1457a45d967Smillert	15
1467a45d967Smillert	16
1477a45d967Smillert	15
1487a45d967Smillert	15
1497a45d967Smillert---
1507a45d967Smillert
1517a45d967Smillertname: integer-base-4
1527a45d967Smillertdescription:
1537a45d967Smillert	Check that things not declared as integers are not made integers,
1547a45d967Smillert	also, check if base is not reset by -i with no arguments.
1557a45d967Smillert	(ksh93 fails - prints 10#20 - go figure)
1567a45d967Smillertstdin:
1577a45d967Smillert	xx=20
1587a45d967Smillert	let xx=10
1597a45d967Smillert	typeset -i | grep '^xx='
1607a45d967Smillert	typeset -i4 a=10
1617a45d967Smillert	typeset -i a=20
1627a45d967Smillert	echo $a
1637a45d967Smillertexpected-stdout:
1647a45d967Smillert	4#110
1657a45d967Smillert---
1667a45d967Smillert
1677a45d967Smillertname: integer-base-5
1687a45d967Smillertdescription:
1697a45d967Smillert	More base stuff
1707a45d967Smillertstdin:
1717a45d967Smillert	typeset -i4 a=3#10
1727a45d967Smillert	echo $a
1737a45d967Smillert	echo --
1747a45d967Smillert	typeset -i j=3
1757a45d967Smillert	j=~3
1767a45d967Smillert	echo $j
1777a45d967Smillert	echo --
1787a45d967Smillert	typeset -i k=1
1797a45d967Smillert	x[k=k+1]=3
1807a45d967Smillert	echo $k
1817a45d967Smillert	echo --
1827a45d967Smillert	typeset -i l
1837a45d967Smillert	for l in 1 2+3 4; do echo $l; done
1847a45d967Smillertexpected-stdout:
1857a45d967Smillert	4#3
1867a45d967Smillert	--
1877a45d967Smillert	-4
1887a45d967Smillert	--
1897a45d967Smillert	2
1907a45d967Smillert	--
1917a45d967Smillert	1
1927a45d967Smillert	5
1937a45d967Smillert	4
1947a45d967Smillert---
1957a45d967Smillert
1967a45d967Smillertname: integer-base-6
1977a45d967Smillertdescription:
1987a45d967Smillert	Even more base stuff
1997a45d967Smillert	(ksh93 fails this test - prints 0)
2007a45d967Smillertstdin:
2017a45d967Smillert	typeset -i7 i
2027a45d967Smillert	i=
2037a45d967Smillert	echo $i
2047a45d967Smillertexpected-stdout:
2057a45d967Smillert	7#0
2067a45d967Smillert---
2077a45d967Smillert
2087a45d967Smillertname: integer-base-7
2097a45d967Smillertdescription:
2107a45d967Smillert	Check that non-integer parameters don't get bases assigned
2117a45d967Smillertstdin:
2127a45d967Smillert	echo $(( zz = 8#100 ))
2137a45d967Smillert	echo $zz
2147a45d967Smillertexpected-stdout:
2157a45d967Smillert	64
2167a45d967Smillert	64
2177a45d967Smillert---
2187a45d967Smillert
219*517d3880Stobiasname: integer-1
220*517d3880Stobiasdescription:
221*517d3880Stobias	Check that 64 bit integers get assigned
222*517d3880Stobiasstdin:
223*517d3880Stobias	echo $(( zz = 0x7fffffffffffffff))
224*517d3880Stobias	echo $zz
225*517d3880Stobiasexpected-stdout:
226*517d3880Stobias	9223372036854775807
227*517d3880Stobias	9223372036854775807
228*517d3880Stobias---
229*517d3880Stobias
230