-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecution_test.go
More file actions
60 lines (51 loc) · 1.82 KB
/
Copy pathexecution_test.go
File metadata and controls
60 lines (51 loc) · 1.82 KB
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
package expr
import (
"errors"
"reflect"
"testing"
)
var tests = []struct {
op Operator
x, y any
want any
wantError error
}{
{RelationalOperatorEqualTo, 1, 1, true, nil},
{RelationalOperatorEqualTo, 0, 0, true, nil},
{RelationalOperatorEqualTo, -1, -1, true, nil},
{RelationalOperatorEqualTo, 1, 2, false, nil},
{RelationalOperatorGreaterThan, 2, 1, true, nil},
{RelationalOperatorGreaterThan, 2, -1, true, nil},
{RelationalOperatorGreaterThan, 1, 2, false, nil},
{RelationalOperatorGreaterThan, -1, 2, false, nil},
{RelationalOperatorGreaterThanOrEqualTo, 2, 1, true, nil},
{RelationalOperatorGreaterThanOrEqualTo, 2, -1, true, nil},
{RelationalOperatorGreaterThanOrEqualTo, 2, 2, true, nil},
{RelationalOperatorGreaterThanOrEqualTo, 1, 2, false, nil},
{RelationalOperatorGreaterThanOrEqualTo, -1, 2, false, nil},
{Operator("MOCK_UNSUPPORTED_OPERATOR"), 1, 1, false, errors.New("Unsupported operator MOCK_UNSUPPORTED_OPERATOR, Can't execute the given operator MOCK_UNSUPPORTED_OPERATOR on expression (1 MOCK_UNSUPPORTED_OPERATOR 1)")},
}
func TestExecuteRelationalOperator(t *testing.T) {
for _, test := range tests {
var (
got any
gotErr error
)
switch test.x.(type) {
case int:
got, gotErr = Execute(test.x.(int), test.op, test.y.(int))
case string:
got, gotErr = Execute(test.x.(string), test.op, test.y.(string))
case float64:
got, gotErr = Execute(test.x.(float64), test.op, test.y.(float64))
case uintptr:
got, gotErr = Execute(test.x.(uintptr), test.op, test.y.(uintptr))
}
if test.wantError == nil && !reflect.DeepEqual(got, test.want) {
t.Errorf("Execute() = got %v, want %v", got, test.want)
}
if test.wantError != nil && !reflect.DeepEqual(gotErr.Error(), test.wantError.Error()) {
t.Errorf("Execute() = got %v, want %v", gotErr, test.wantError)
}
}
}