summaryrefslogtreecommitdiff
path: root/shell/ash_test
diff options
context:
space:
mode:
authorDenys Vlasenko2023-06-13 18:27:19 +0200
committerDenys Vlasenko2023-06-14 00:41:18 +0200
commit8acbf31708779e7ad559775c9db4ebd7a962be33 (patch)
tree6ebbb1943faa703f53257b6b64c3426e9cf647d6 /shell/ash_test
parent373f64eef3cc121d7531522ef654feb0a8068d5a (diff)
downloadbusybox-8acbf31708779e7ad559775c9db4ebd7a962be33.zip
busybox-8acbf31708779e7ad559775c9db4ebd7a962be33.tar.gz
shell/math: document ternary ?: op's weirdness, add code comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test')
-rw-r--r--shell/ash_test/ash-arith/arith-precedence1.right3
-rwxr-xr-xshell/ash_test/ash-arith/arith-precedence1.tests13
2 files changed, 16 insertions, 0 deletions
diff --git a/shell/ash_test/ash-arith/arith-precedence1.right b/shell/ash_test/ash-arith/arith-precedence1.right
index 7f407b5..3f9320a 100644
--- a/shell/ash_test/ash-arith/arith-precedence1.right
+++ b/shell/ash_test/ash-arith/arith-precedence1.right
@@ -1 +1,4 @@
4:4
+4:4
+4:4
+4:4
diff --git a/shell/ash_test/ash-arith/arith-precedence1.tests b/shell/ash_test/ash-arith/arith-precedence1.tests
index 964ae4e..bfef052 100755
--- a/shell/ash_test/ash-arith/arith-precedence1.tests
+++ b/shell/ash_test/ash-arith/arith-precedence1.tests
@@ -1,2 +1,15 @@
exec 2>&1
+# bash documentation says that precedence order is:
+# ...
+# expr ? expr1 : expr2
+# = *= /= %= += -= <<= >>= &= ^= |=
+# exprA , exprB
+# but in practice, the rules for expr1 and expr2 are different:
+# assignments and commas in expr1 have higher precedence than :?,
+# but in expr2 they haven't:
+# "v ? 1,2 : 3,4" is parsed as "(v ? (1,2) : 3),4"
+# "v ? a=2 : b=4" is parsed as "(v ? (a=1) : b)=4" (thus, this is a syntax error)
+echo 4:$((0 ? 1,2 : 3,4))
+echo 4:$((1 ? 1,2 : 3,4))
echo 4:"$((0 ? 1,2 : 3,4))"
+echo 4:"$((1 ? 1,2 : 3,4))"