Imported from ../bash-4.0-rc1.tar.gz.
[platform/upstream/bash.git] / tests / arith.tests
index 6bad312..9e82bb1 100644 (file)
@@ -1,3 +1,4 @@
+set +o posix
 declare -i iv jv
 
 iv=$(( 3 + 5 * 32 ))
@@ -83,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
@@ -135,8 +142,8 @@ echo $(( 32#A ))
 echo $(( 56#A ))
 echo $(( 64#A ))
 
-echo $(( 64#_ ))
 echo $(( 64#@ ))
+echo $(( 64#_ ))
 
 # weird bases
 echo $(( 3425#56 ))
@@ -156,3 +163,128 @@ let 'rv = 7 + (43 * 6'
 declare -i i
 i=0#4
 i=2#110#11
+
+((echo abc; echo def;); echo ghi)
+
+if (((4+4) + (4 + 7))); then
+       echo ok
+fi
+
+(())   # make sure the null expression works OK
+
+a=(0 2 4 6)
+echo $(( a[1] + a[2] ))
+echo $(( (a[1] + a[2]) == a[3] ))
+(( (a[1] + a[2]) == a[3] )) ; echo $?
+
+# test pushing and popping the expression stack
+unset A
+A="4 + "
+echo $(( ( 4 + A ) + 4 ))
+A="3 + 5"
+echo $(( ( 4 + A ) + 4 ))
+
+# badly-formed conditional expressions
+echo $(( 4 ? : $A ))
+echo $(( 1 ? 20 ))
+echo $(( 4 ? 20 : ))
+
+# precedence and short-circuit evaluation
+B=9
+echo $B
+
+echo $(( 0 && B=42 ))
+echo $B
+
+echo $(( 1 || B=88 ))
+echo $B
+
+echo $(( 0 && (B=42) ))
+echo $B
+
+echo $(( (${$} - $$) && (B=42) ))
+echo $B
+
+echo $(( 1 || (B=88) ))
+echo $B
+
+# until command with (( )) command
+x=7
+
+echo $x
+until (( x == 4 ))
+do
+       echo $x
+       x=4
+done
+
+echo $x
+
+# exponentiation
+echo $(( 2**15 - 1))
+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
+
+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