forked from herrjulz/goml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
86 lines (68 loc) · 1.9 KB
/
delete_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
86
package goml_test
import (
. "github.com/JulzDiverse/goml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/smallfish/simpleyaml"
)
var _ = Describe("Delete", 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 also delete", func() {
yam, _ := DeleteInMemory([]byte(yaml), "array.:lar")
//Expect(err).ToNot(HaveOccurred())
Expect(1).To(Equal(2))
})
It("should delete a value from a map", func() {
err = Delete(yml, "map.name")
Expect(err).NotTo(HaveOccurred())
_, err = Get(yml, "map.name")
Expect(err).To(MatchError("property not found"))
})
It("should delete a value from an array ", func() {
err = Delete(yml, "array.0")
Expect(err).NotTo(HaveOccurred())
_, err := Get(yml, "array.:bar")
Expect(err).To(MatchError("property not found"))
err = Delete(yml, "array.:zar")
Expect(err).NotTo(HaveOccurred())
_, err = Get(yml, "array.:zar")
Expect(err).To(MatchError("property not found"))
})
It("should delete a value from an map inside an array ", func() {
err = Delete(yml, "mapArray.foo:bar.zoo")
Expect(err).NotTo(HaveOccurred())
_, err := Get(yml, "mapArray.foo:bar.zoo")
Expect(err).To(HaveOccurred())
})
It("should delete a value from an array inside a map which in turn is inside an array ", func() {
err = Delete(yml, "mapArray.foo:bar.arr.0")
Expect(err).NotTo(HaveOccurred())
_, err := Get(yml, "mapArray.foo:bar.arr.:one")
Expect(err).To(MatchError("property not found"))
err = Delete(yml, "mapArray.foo:bar.arr.:two")
Expect(err).NotTo(HaveOccurred())
_, err = Get(yml, "mapArray.foo:bar.arr.:two")
Expect(err).To(MatchError("property not found"))
})
})