commit: 54754836c804c7aa56159ca20546337ae4e19747
parent 03bf16a04f428b6a93403c1b91b6a960419abac5
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 28 Sep 2024 12:03:50 +0200
test-cmd/expr.sh: make sure logic operators are correct
Diffstat:
M | test-cmd/expr.sh | 80 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
1 file changed, 52 insertions(+), 28 deletions(-)
diff --git a/test-cmd/expr.sh b/test-cmd/expr.sh
@@ -4,10 +4,21 @@
WD="$(dirname "$0")/../"
target="${WD}/cmd/expr"
-plans=23
+plans=41
. "${WD}/test-cmd/tap.sh"
+t_expr_no() {
+ name="$1"; shift
+ t_args --exit=1 "$name" '0
+' "$@"
+}
+t_expr_ok() {
+ name="$1"; shift
+ t_args "$name" '1
+' "$@"
+}
+
t int 1 '1
'
@@ -19,6 +30,46 @@ t_args 'char_count:1234' '4
t_args 'char_count:12345' '5
' "X12345" : '.*' - 1
+t_expr_no or:00 0 '|' 0
+t_expr_ok or:01 0 '|' 1
+t_expr_ok or:10 1 '|' 0
+t_expr_ok or:11 1 '|' 1
+
+t_expr_no and:00 0 '&' 0
+t_expr_no and:01 0 '&' 1
+t_expr_no and:10 1 '&' 0
+t_expr_ok and:11 1 '&' 1
+
+t_expr_ok eq:00 0 '=' 0
+t_expr_no eq:01 0 '=' 1
+t_expr_no eq:10 1 '=' 0
+t_expr_ok eq:11 1 '=' 1
+
+t_expr_no gt:00 0 '>' 0
+t_expr_no gt:01 0 '>' 1
+t_expr_ok gt:10 1 '>' 0
+t_expr_no gt:11 1 '>' 1
+
+t_expr_no lt:00 0 '<' 0
+t_expr_ok lt:01 0 '<' 1
+t_expr_no lt:10 1 '<' 0
+t_expr_no lt:11 1 '<' 1
+
+t_expr_ok ge:00 0 '>=' 0
+t_expr_no ge:01 0 '>=' 1
+t_expr_ok ge:10 1 '>=' 0
+t_expr_ok ge:11 1 '>=' 1
+
+t_expr_ok le:00 0 '<=' 0
+t_expr_ok le:01 0 '<=' 1
+t_expr_no le:10 1 '<=' 0
+t_expr_ok le:11 1 '<=' 1
+
+t_expr_no ne:00 0 '!=' 0
+t_expr_ok ne:01 0 '!=' 1
+t_expr_ok ne:10 1 '!=' 0
+t_expr_no ne:11 1 '!=' 1
+
t_args mul '6
' 3 '*' 2
t_args div '3
@@ -29,30 +80,3 @@ t_args add '3
' 1 + 2
t_args sub '2
' 3 - 1
-
-good='1
-'
-bad='0
-'
-
-t_args eq:eq "$good" 1 = 1
-t_args --exit=1 eq:ne "$bad" 1 = 0
-
-t_args gt:gt "$good" 2 '>' 1
-t_args --exit=1 gt:lt "$bad" 1 '>' 2
-
-t_args gte:gt "$good" 2 '>=' 1
-t_args gte:eq "$good" 2 '>=' 2
-t_args --exit=1 gte:lt "$bad" 1 '>=' 2
-
-t_args lt:lt "$good" 1 '<' 2
-t_args --exit=1 lt:gt "$bad" 2 '<' 1
-
-t_args lte:lt "$good" 1 '<=' 2
-t_args lte:eq "$good" 2 '<=' 2
-t_args --exit=1 lte:gt "$bad" 2 '<=' 1
-
-t_args ne:ne "$good" 1 != 2
-t_args --exit=1 ne:eq "$bad" 1 != 1
-
-# TODO: and (&), or (|)