-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables_test.go
More file actions
88 lines (77 loc) · 1.46 KB
/
variables_test.go
File metadata and controls
88 lines (77 loc) · 1.46 KB
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
87
88
package variables
import (
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func assertProp(t *testing.T, data, props string) {
pr := NewVariables()
assert.NoError(t, pr.FromProperties(props, ""))
target, _ := json.Marshal(pr)
assert.Equal(t, data, string(target))
}
func TestArrayProperties(t *testing.T) {
assertProp(t, `{"foo":[{"bar":"bar1"},{"bar":"bar2"}]}`,
`
foo.0.bar=bar1
foo.1.bar=bar2
`)
assertProp(t, `{"foo":[null,{"bar":"bar1"},{"bar":"bar2"}]}`,
`foo.1.bar=bar1
foo.-1.bar=bar2
`)
}
func TestArrayValue(t *testing.T) {
assertProp(t, `{"foo":["bar1","bar2"]}`, `
foo.0=bar1
foo.1=bar2
`)
assertProp(t, `{"foo":[null,"bar1","bar2"]}`, `
foo.1=bar1
foo.-1=bar2`)
assertProp(t, `{"foo":["bar2","bar1"]}`, `
foo.1=bar1
foo.0=bar2
`)
}
func TestBigArrayValue(t *testing.T) {
assertProp(t, `{"data":["foo0",{"name":"foo1","value":"test"},"bbb"]}`, `
data.0=foo0
data.1.name=foo1
data.1.value=test
data.2=bbb
`)
}
func TestCompile(t *testing.T) {
properties := NewVariables()
assert.NoError(t, properties.FromProperties(`
a=b
b=12
c=true
d=121212.121212
e=null
f={{.d}}+{{.e}}
g.0=1
g.1={{index .g 0}}
g.2=1
foo=1
bar=2
aaa=true
bbb=false
`, ""))
marshal, err := json.Marshal(properties)
fmt.Println(string(marshal), err)
_, err = properties.Execute("bbb")
assert.NoError(t, err)
}
func TestOverride(t *testing.T) {
assertProp(t, `{"foo":["bar2"]}`, `
foo.0=bar1
foo.0=bar2
`)
assertProp(t, `{"foo":1}`, `
foo=2
foo=1
`)
}