-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget_test.go
85 lines (68 loc) · 1.78 KB
/
get_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 goml_test
import (
. "github.com/JulzDiverse/goml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/smallfish/simpleyaml"
)
var _ = Describe("Get", func() {
var yml *simpleyaml.Yaml
var err error
var yaml string
BeforeEach(func() {
yaml = `map:
name: foo
array:
- bar
- var
- zar
mapArray:
- foo: bar
zoo: lion
arr:
- one
- two
- three
- foo: var
boo: laa`
yml, err = simpleyaml.NewYaml([]byte(yaml))
Expect(err).NotTo(HaveOccurred())
})
It("should get a value from a map, array, array with maps", func() {
value, err := Get(yml, "map.name")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("foo"))
value, err = Get(yml, "array.0")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("bar"))
value, err = Get(yml, "mapArray.0.foo")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("bar"))
value, err = Get(yml, "mapArray.foo:var.boo")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("laa"))
value, err = Get(yml, "array.:var")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("var"))
value, err = Get(yml, "mapArray.foo:bar.arr.0")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("one"))
})
Context("Using the | delimiter", func() {
It("should get a value from a array inside a map", func() {
value, err := Get(yml, "mapArray.foo|bar.arr.0")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("one"))
})
It("should get a vlaue from a map", func() {
value, err := Get(yml, "mapArray.foo|var.boo")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("laa"))
})
It("should get a value form an array", func() {
value, err := Get(yml, "array.|var")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("var"))
})
})
})