forked from herrjulz/goml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_test.go
58 lines (48 loc) · 1.3 KB
/
set_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
package goml_test
import (
. "github.com/JulzDiverse/goml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/smallfish/simpleyaml"
)
var _ = Describe("Set", func() {
var yml *simpleyaml.Yaml
var err error
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 add an value to an array", func() {
err = Set(yml, "array.2", "bumblebee")
Expect(err).NotTo(HaveOccurred())
err = Set(yml, "array.+", "optimusPrime")
Expect(err).NotTo(HaveOccurred())
err = Set(yml, "mapArray.0.foo", "wolverine")
Expect(err).NotTo(HaveOccurred())
err = Set(yml, "mapArray.foo:var.boo", "baymax")
Expect(err).NotTo(HaveOccurred())
Expect(Get(yml, "array.2")).To(Equal("bumblebee"))
Expect(Get(yml, "array.3")).To(Equal("optimusPrime"))
Expect(Get(yml, "mapArray.0.foo")).To(Equal("wolverine"))
Expect(Get(yml, "mapArray.foo:var.boo")).To(Equal("baymax"))
err = Set(yml, "array.:optimusPrime", "pikachu")
Expect(Get(yml, "array.:pikachu")).To(Equal("pikachu"))
err = Set(yml, "mapArray.foo:wolverine.arr.0", "new")
Expect(Get(yml, "mapArray.foo:wolverine.arr.0")).To(Equal("new"))
})
})