-
Notifications
You must be signed in to change notification settings - Fork 2
/
is_defined_test.go
83 lines (70 loc) · 2.51 KB
/
is_defined_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
package functions_for_govaluate_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/jamillosantos/functions-for-govaluate"
)
var _ = Describe("is_defined function", func() {
It("should return that a nil value is not defined", func() {
c, err := functions_for_govaluate.IsDefined(nil)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
})
It("should return that a non empty string is defined", func() {
c, err := functions_for_govaluate.IsDefined("this is a non empty string")
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should return that a non empty string is defined", func() {
c, err := functions_for_govaluate.IsDefined("")
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
})
It("should return that a zero valued integer is not defined", func() {
c, err := functions_for_govaluate.IsDefined(0)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
})
It("should return that a non zero valued integer is defined (positive)", func() {
c, err := functions_for_govaluate.IsDefined(1)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should return that a non zero valued integer is defined (negative)", func() {
c, err := functions_for_govaluate.IsDefined(-1)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should return that a zero valued float is not defined", func() {
c, err := functions_for_govaluate.IsDefined(0.0)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
})
It("should return that a non zero valued float is defined (positive)", func() {
c, err := functions_for_govaluate.IsDefined(0.000001)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should return that a non zero valued float is defined (negative)", func() {
c, err := functions_for_govaluate.IsDefined(-0.000001)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should return an param wrong type error", func() {
_, err := functions_for_govaluate.IsDefined(map[string]interface{}{
"str": "value",
})
Expect(err).NotTo(BeNil())
Expect(functions_for_govaluate.IsWrongParamType(err)).To(BeTrue())
})
It("should return a param count error (too few arguments)", func() {
_, err := functions_for_govaluate.IsDefined()
Expect(err).NotTo(BeNil())
Expect(functions_for_govaluate.IsWrongParamsCount(err)).To(BeTrue())
})
It("should return a param count error (too many arguments)", func() {
_, err := functions_for_govaluate.IsDefined(1, 2)
Expect(err).NotTo(BeNil())
Expect(functions_for_govaluate.IsWrongParamsCount(err)).To(BeTrue())
})
})