Bash-4.3 distribution sources and documentation
[platform/upstream/bash.git] / tests / arith.tests
index d37e77f..7dcc36d 100644 (file)
@@ -84,6 +84,12 @@ echo $(( 4<(2+3) ? 1 : 32))
 echo $(( (2+2)<(2+3) ? 1 : 32))
 echo $(( (2+2)>(2+3) ? 1 : 32))
 
+# bug in bash versions through bash-3.2
+S=105
+W=$((S>99?4:S>9?3:S>0?2:0))
+echo $W
+unset W S
+
 # check that the unevaluated part of the ternary operator does not do
 # evaluation or assignment
 x=i+=2
@@ -136,8 +142,8 @@ echo $(( 32#A ))
 echo $(( 56#A ))
 echo $(( 64#A ))
 
-echo $(( 64#_ ))
 echo $(( 64#@ ))
+echo $(( 64#_ ))
 
 # weird bases
 echo $(( 3425#56 ))
@@ -220,3 +226,77 @@ echo $(( 2**(16-1)))
 echo $(( 2**16*2 ))
 echo $(( 2**31-1))
 echo $(( 2**0 ))
+
+# {pre,post}-{inc,dec}rement and associated errors
+
+x=4
+
+echo $x
+echo $(( x++ ))
+echo $x
+echo $(( x-- ))
+echo $x
+
+echo $(( --x ))
+echo $x
+
+echo $(( ++x ))
+echo $x
+
+echo $(( ++7 ))
+echo $(( 7-- ))
+
+echo $(( --x=7 ))
+echo $(( ++x=7 ))
+
+echo $(( x++=7 ))
+echo $(( x--=7 ))
+
+echo $x
+
+echo $(( +7 ))
+echo $(( -7 ))
+
+echo $(( ++7 ))
+echo $(( --7 ))
+
+${THIS_SH} ./arith1.sub
+${THIS_SH} ./arith2.sub
+${THIS_SH} ./arith3.sub
+${THIS_SH} ./arith4.sub
+
+# make sure arithmetic expansion handles ints > 2**31 - 1 using intmax_t
+echo $(( 2147483645 + 4 ))
+
+# other tests using INTMAX_MIN and INTMAX_MAX that cause exceptions if not
+# handled correctly -- problem through bash-4.2
+${THIS_SH} ./arith5.sub
+
+# problems with suppressing evaluation present through bash-4.2
+${THIS_SH} ./arith6.sub
+
+x=4
+y=7
+
+(( x=8 , y=12 ))
+
+echo $x $y
+
+# should be an error
+(( x=9 y=41 ))
+
+# These are errors
+unset b
+echo $((a b))
+((a b))
+
+n=42
+printf "%d\n" $n
+printf "%i\n" $n
+echo $(( 8#$(printf "%o\n" $n) ))
+printf "%u\n" $n
+echo $(( 16#$(printf "%x\n" $n) ))
+echo $(( 16#$(printf "%X\n" $n) ))
+
+# causes longjmp botches through bash-2.05b
+a[b[c]d]=e