expr.sh (996B)
- #!/bin/sh
- # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- WD="$(dirname "$0")/../"
- target="${WD}/cmd/expr"
- plans=23
- . "${WD}/test-cmd/tap.sh"
- t int 1 '1
- '
- t_args group '4
- ' '(' 2 '*' 3 ')' - 2
- t_args 'char_count:1234' '4
- ' "X1234" : '.*' - 1
- t_args 'char_count:12345' '5
- ' "X12345" : '.*' - 1
- t_args mul '6
- ' 3 '*' 2
- t_args div '3
- ' 7 / 2
- t_args rem '1
- ' 7 % 2
- 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 (|)