blob: 61862989139d14c8ff2558e5bc5f4a683ea6b651 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#!/bin/ksh
function test_expr {
echo "Testing: `eval echo $1`"
res=`eval expr $1 2>&1`
if [ "$res" != "$2" ]; then
echo "Expected $2, got $res from expression: `eval echo $1`"
exit 1
fi
}
# The first arg will get eval'd so escape any meta characters
# The 2nd arg is an expected string/response from expr for that op.
# Test overflow cases
test_expr '4611686018427387904 + 4611686018427387903' '9223372036854775807'
test_expr '4611686018427387904 + 4611686018427387904' "expr: integer overflow or underflow occurred for operation '4611686018427387904 + 4611686018427387904'"
test_expr '4611686018427387904 - -4611686018427387904' "expr: integer overflow or underflow occurred for operation '4611686018427387904 - -4611686018427387904'"
test_expr '-4611686018427387904 - 4611686018427387903' '-9223372036854775807'
test_expr '-4611686018427387904 - 4611686018427387905' "expr: integer overflow or underflow occurred for operation '-4611686018427387904 - 4611686018427387905'"
test_expr '-4611686018427387904 \* 1' '-4611686018427387904'
test_expr '-4611686018427387904 \* -1' '4611686018427387904'
test_expr '-4611686018427387904 \* 2' '-9223372036854775808'
test_expr '-4611686018427387904 \* 3' "expr: integer overflow or underflow occurred for operation '-4611686018427387904 * 3'"
test_expr '-4611686018427387904 \* -2' "expr: integer overflow or underflow occurred for operation '-4611686018427387904 * -2'"
test_expr '4611686018427387904 \* 1' '4611686018427387904'
test_expr '4611686018427387904 \* 2' "expr: integer overflow or underflow occurred for operation '4611686018427387904 * 2'"
test_expr '4611686018427387904 \* 3' "expr: integer overflow or underflow occurred for operation '4611686018427387904 * 3'"
# Test from gtk-- configure that cause problems on old expr
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '0'
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 3 \& 5 \>= 5' '0'
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 2 \& 4 = 4 \& 5 \>= 5' '0'
test_expr '3 \> 2 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '1'
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 3 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
# Basic precendence test with the : operator vs. math
test_expr '2 : 4 / 2' '0'
test_expr '4 : 4 % 3' '1'
# Dangling arithemtic operator
test_expr '.java_wrapper : /' '0'
test_expr '4 : \*' '0'
test_expr '4 : +' '0'
test_expr '4 : -' '0'
test_expr '4 : /' '0'
test_expr '4 : %' '0'
# Basic math test
test_expr '2 + 4 \* 5' '22'
# Basic functional tests
test_expr '2' '2'
test_expr '-4' '-4'
test_expr 'hello' 'hello'
# Compare operator precendence test
test_expr '2 \> 1 \* 17' '0'
# Compare operator tests
test_expr '2 \!= 5' '1'
test_expr '2 \!= 2' '0'
test_expr '2 \<= 3' '1'
test_expr '2 \<= 2' '1'
test_expr '2 \<= 1' '0'
test_expr '2 \< 3' '1'
test_expr '2 \< 2' '0'
test_expr '2 = 2' '1'
test_expr '2 = 4' '0'
test_expr '2 \>= 1' '1'
test_expr '2 \>= 2' '1'
test_expr '2 \>= 3' '0'
test_expr '2 \> 1' '1'
test_expr '2 \> 2' '0'
# Known failure once
test_expr '1 \* -1' '-1'
# Test a known case that should fail
test_expr '- 1 + 5' 'expr: syntax error'
# Double check negative numbers
test_expr '1 - -5' '6'
# More complex math test for precedence
test_expr '-3 + -1 \* 4 + 3 / -6' '-7'
# The next two are messy but the shell escapes cause that.
# Test precendence
test_expr 'X1/2/3 : X\\\(.\*[^/]\\\)//\*[^/][^/]\*/\*$ \| . : \\\(.\\\)' '1/2'
# Test proper () returning \1 from a regex
test_expr '1/2 : .\*/\\\(.\*\\\)' '2'
exit 0
|