-
Notifications
You must be signed in to change notification settings - Fork 15
/
t.params_test.go
59 lines (45 loc) · 1.19 KB
/
t.params_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
package docxplate
import (
"fmt"
"testing"
)
func TestAnyToParamsMapStringString(t *testing.T) {
inParams := map[string]string{
"Name": "Alice",
"Greeting": "Hi!",
}
outParams := AnyToParams(inParams)
if len(inParams) != outParams.Len() {
t.Fatalf("param count don't match. Expected %d, found %d", len(inParams), outParams.Len())
}
// check if all params exists
for k := range inParams {
if p := outParams.Get(k); p == nil {
t.Fatalf("param `%s` not found", k)
}
}
}
func TestAnyToParamsMapStringAny(t *testing.T) {
type dummyTestType int
inParams := map[string]any{
"Name": "Bob",
"Age": uint(28),
"FavColor": dummyTestType(0xF00),
"Numbers": []int{1, 2, 3, 4, 5},
}
outParams := AnyToParams(inParams)
if len(inParams) != outParams.Len() {
t.Fatalf("param count don't match. Expected %d, found %d", len(inParams), outParams.Len())
}
// check if all params exists
for k, v := range inParams {
// log.Printf("[%s] ==> [%v]", k, v)
val := outParams.Get(k)
if val == nil {
t.Fatalf("param `%s` not found", k)
}
if fmt.Sprintf("%v", v) != fmt.Sprintf("%v", val) {
t.Fatalf("param `%s` value not equal: [%v]!=[%v]", k, v, val)
}
}
}