blob: c95d0301952a48ce33a9cd442970d7bc8395257a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/bin/bash
[ -f testing.sh ] && . testing.sh
testing "integer" "expr 5" "5\n" "" ""
testing "integer negative" "expr -5" "-5\n" "" ""
testing "string" "expr astring" "astring\n" "" ""
testing "1 + 3" "expr 1 + 3" "4\n" "" ""
testing "5 + 6 * 3" "expr 5 + 6 \* 3" "23\n" "" ""
testing "( 5 + 6 ) * 3" "expr \( 5 + 6 \) \* 3" "33\n" "" ""
testing "* / same priority" "expr 4 \* 3 / 2" "6\n" "" ""
testing "/ * same priority" "expr 3 / 2 \* 4" "4\n" "" ""
testing "& before |" "expr 0 \| 1 \& 0" "0\n" "" ""
testing "| after &" "expr 1 \| 0 \& 0" "1\n" "" ""
testing "| & same priority" "expr 0 \& 0 \| 1" "1\n" "" ""
testing "% * same priority" "expr 3 % 2 \* 4" "4\n" "" ""
testing "* % same priority" "expr 3 \* 2 % 4" "2\n" "" ""
testing "= > same priority" "expr 0 = 2 \> 3" "0\n" "" ""
testing "> = same priority" "expr 3 \> 2 = 1" "1\n" "" ""
testing "string becomes integer" "expr ab21xx : '[^0-9]*\([0-9]*\)' + 3" \
"24\n" "" ""
|