forked from Knetic/govaluate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dummies_test.go
85 lines (67 loc) · 1.68 KB
/
dummies_test.go
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
package govaluate
import (
"errors"
"fmt"
)
/*
Struct used to test "parameter calls".
*/
type dummyParameter struct {
String string
Int int
BoolFalse bool
Nil interface{}
Nested dummyNestedParameter
}
func (this dummyParameter) Func() string {
return "funk"
}
func (this dummyParameter) Func2() (string, error) {
return "frink", nil
}
func (this *dummyParameter) Func3() string {
return "fronk"
}
func (this dummyParameter) FuncArgStr(arg1 string) string {
return arg1
}
func (this dummyParameter) TestArgs(str string, ui uint, ui8 uint8, ui16 uint16, ui32 uint32, ui64 uint64, i int, i8 int8, i16 int16, i32 int32, i64 int64, f32 float32, f64 float64, b bool) string {
var sum float64
sum = float64(ui) + float64(ui8) + float64(ui16) + float64(ui32) + float64(ui64)
sum += float64(i) + float64(i8) + float64(i16) + float64(i32) + float64(i64)
sum += float64(f32)
if b {
sum += f64
}
return fmt.Sprintf("%v: %v", str, sum)
}
func (this dummyParameter) AlwaysFail() (interface{}, error) {
return nil, errors.New("function should always fail")
}
type dummyNestedParameter struct {
Funk string
}
func (this dummyNestedParameter) Dunk(arg1 string) string {
return arg1 + "dunk"
}
var dummyParameterInstance = dummyParameter{
String: "string!",
Int: 101,
BoolFalse: false,
Nil: nil,
Nested: dummyNestedParameter{
Funk: "funkalicious",
},
}
var fooParameter = EvaluationParameter{
Name: "foo",
Value: dummyParameterInstance,
}
var fooPtrParameter = EvaluationParameter{
Name: "fooptr",
Value: &dummyParameterInstance,
}
var fooFailureParameters = map[string]interface{}{
"foo": fooParameter.Value,
"fooptr": &fooPtrParameter.Value,
}