Add basic tests for octal and hex notation in arithmetic expansions
authorjca <jca@openbsd.org>
Fri, 12 Jan 2018 11:13:29 +0000 (11:13 +0000)
committerjca <jca@openbsd.org>
Fri, 12 Jan 2018 11:13:29 +0000 (11:13 +0000)
POSIX requires only decimal, octal and hex, tests for the $((x#number))
notation could be useful too.

regress/bin/ksh/arith.t

index e18ea2e..888909e 100644 (file)
@@ -77,3 +77,47 @@ expected-stdout:
        6,5,3
 ---
 
+name: check-octal-valid-1
+description:
+       Check octal notation (valid input)
+stdin:
+       echo $((00)),$((-00)),$((007)),$((-007)),$((010)),$((-010))
+       echo $((010 + 1))
+expected-stdout:
+       0,0,7,-7,8,-8
+       9
+
+---
+
+name: check-octal-invalid-1
+description:
+       Check octal notation (invalid input)
+stdin:
+       echo $((08))
+expected-exit: e != 0
+expected-stderr-pattern:
+       /.*:.*08.*bad number/
+
+---
+name: check-hex-valid-1
+description:
+       Check hex notation (valid input)
+stdin:
+       echo $((0x0)),$((-0x0)),$((0xf)),$((-0xf)),$((0x10)),$((-0x10))
+       echo $((0x10 + 1))
+expected-stdout:
+       0,0,15,-15,16,-16
+       17
+
+---
+
+name: check-hex-invalid-1
+description:
+       Check hex notation (invalid input)
+stdin:
+       echo $((0xg))
+expected-exit: e != 0
+expected-stderr-pattern:
+       /.*:.* 0xg.*bad number/
+
+---