@@ -12,61 +12,61 @@ import (
12
12
13
13
func TestExpandVars (t * testing.T ) {
14
14
kases := []struct {
15
- template string
16
- maps map [string ]string
17
- expected string
18
- fail bool
15
+ tmpl string
16
+ data map [string ]string
17
+ out string
18
+ error bool
19
19
}{
20
20
{
21
- template : "{a}" ,
22
- maps : map [string ]string {
21
+ tmpl : "{a}" ,
22
+ data : map [string ]string {
23
23
"a" : "1" ,
24
24
},
25
- expected : "1" ,
25
+ out : "1" ,
26
26
},
27
27
{
28
- template : "expand {a}, {b} and {c}, with escaped {#{ }" ,
29
- maps : map [string ]string {
28
+ tmpl : "expand {a}, {b} and {c}, with non-var { } {# }" ,
29
+ data : map [string ]string {
30
30
"a" : "1" ,
31
31
"b" : "2" ,
32
32
"c" : "3" ,
33
33
},
34
- expected : "expand 1, 2 and 3, with escaped { " ,
34
+ out : "expand 1, 2 and 3, with non-var { } {#} " ,
35
35
},
36
36
{
37
- template : "中文内容 {一}, {二} 和 {三} 中文结尾" ,
38
- maps : map [string ]string {
37
+ tmpl : "中文内容 {一}, {二} 和 {三} 中文结尾" ,
38
+ data : map [string ]string {
39
39
"一" : "11" ,
40
40
"二" : "22" ,
41
41
"三" : "33" ,
42
42
},
43
- expected : "中文内容 11, 22 和 33 中文结尾" ,
43
+ out : "中文内容 11, 22 和 33 中文结尾" ,
44
44
},
45
45
{
46
- template : "expand {{a}, {b} and {c}" ,
47
- maps : map [string ]string {
46
+ tmpl : "expand {{a}, {b} and {c}" ,
47
+ data : map [string ]string {
48
48
"a" : "foo" ,
49
49
"b" : "bar" ,
50
50
},
51
- expected : "expand {{a}, bar and {c}" ,
52
- fail : true ,
51
+ out : "expand {{a}, bar and {c}" ,
52
+ error : true ,
53
53
},
54
54
{
55
- template : "expand } {} and {" ,
56
- expected : "expand } {} and {" ,
57
- fail : true ,
55
+ tmpl : "expand } {} and {" ,
56
+ out : "expand } {} and {" ,
57
+ error : true ,
58
58
},
59
59
}
60
60
61
61
for _ , kase := range kases {
62
- t .Run (kase .template , func (t * testing.T ) {
63
- res , err := Expand (kase .template , kase .maps )
64
- if kase .fail {
62
+ t .Run (kase .tmpl , func (t * testing.T ) {
63
+ res , err := Expand (kase .tmpl , kase .data )
64
+ if kase .error {
65
65
assert .Error (t , err )
66
66
} else {
67
67
assert .NoError (t , err )
68
68
}
69
- assert .EqualValues (t , kase .expected , res )
69
+ assert .EqualValues (t , kase .out , res )
70
70
})
71
71
}
72
72
}
0 commit comments