-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_test.go
56 lines (40 loc) · 1.2 KB
/
map_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
package interpolate
import (
"testing"
)
func TestFromMapSingleValue(t *testing.T) {
m := make(map[string]interface{})
m["name"] = "Bob"
result := FromMap("Hello %{name}, how are you?", m)
expected := "Hello Bob, how are you?"
if result != expected {
t.Fatalf("Expected: '" + expected + "'. But got: '" + result + "'")
}
}
func TestFromMapDoubleValue(t *testing.T) {
m := make(map[string]interface{})
m["animal"] = "Turtles"
result := FromMap("I like %{animal}! %{animal} are awesome!", m)
expected := "I like Turtles! Turtles are awesome!"
if result != expected {
t.Fatalf("Expected: '" + expected + "'. But got: '" + result + "'")
}
}
func TestFromMapMultiValues(t *testing.T) {
m := make(map[string]interface{})
m["type"] = "Info"
m["message"] = "You got mail!"
result := FromMap("%{type}: %{message}", m)
expected := "Info: You got mail!"
if result != expected {
t.Fatalf("Expected: '" + expected + "'. But got: '" + result + "'")
}
}
func TestFromMapMissingValue(t *testing.T) {
m := make(map[string]interface{})
result := FromMap("Hello %{audience}!", m)
expected := "Hello !"
if result != expected {
t.Fatalf("Expected: '" + expected + "'. But got: '" + result + "'")
}
}