-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathtemplate_test.go
57 lines (46 loc) · 1.15 KB
/
template_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
package utils
import (
"testing"
)
func TestRenderMustaches(t *testing.T) {
t.Run("Normal", func(t *testing.T) {
data := "Hello, {{ name }}! Your age is {{ age }}."
dict := map[string]interface{}{
"name": "Alice",
"age": 30,
}
expected := "Hello, Alice! Your age is 30."
result := RenderMustaches(data, dict)
if result != expected {
t.Errorf("Expected:\n%s\nGot:\n%s", expected, result)
}
})
t.Run("WithCustomValueGetter", func(t *testing.T) {
data := "Hello, {{ name }}!"
dict := map[string]interface{}{
"name": "Bob",
}
valueGetter := func(key string, val interface{}) string {
if key == "name" {
return "Mr. " + val.(string)
}
return ""
}
expected := "Hello, Mr. Bob!"
result := RenderMustaches(data, dict, valueGetter)
if result != expected {
t.Errorf("Expected:\n%s\nGot:\n%s", expected, result)
}
})
t.Run("WithMissingKeys", func(t *testing.T) {
data := "Hello, {{ name }}!"
dict := map[string]interface{}{
"age": 25,
}
expected := "Hello, {{ name }}!"
result := RenderMustaches(data, dict)
if result != expected {
t.Errorf("Expected:\n%s\nGot:\n%s", expected, result)
}
})
}