...
1 package sprig
2
3 import (
4 "testing"
5 )
6
7 type fixtureTO struct {
8 Name, Value string
9 }
10
11 func TestTypeOf(t *testing.T) {
12 f := &fixtureTO{"hello", "world"}
13 tpl := `{{typeOf .}}`
14 if err := runtv(tpl, "*sprig.fixtureTO", f); err != nil {
15 t.Error(err)
16 }
17 }
18
19 func TestKindOf(t *testing.T) {
20 tpl := `{{kindOf .}}`
21
22 f := fixtureTO{"hello", "world"}
23 if err := runtv(tpl, "struct", f); err != nil {
24 t.Error(err)
25 }
26
27 f2 := []string{"hello"}
28 if err := runtv(tpl, "slice", f2); err != nil {
29 t.Error(err)
30 }
31
32 var f3 *fixtureTO
33 if err := runtv(tpl, "ptr", f3); err != nil {
34 t.Error(err)
35 }
36 }
37
38 func TestTypeIs(t *testing.T) {
39 f := &fixtureTO{"hello", "world"}
40 tpl := `{{if typeIs "*sprig.fixtureTO" .}}t{{else}}f{{end}}`
41 if err := runtv(tpl, "t", f); err != nil {
42 t.Error(err)
43 }
44
45 f2 := "hello"
46 if err := runtv(tpl, "f", f2); err != nil {
47 t.Error(err)
48 }
49 }
50 func TestTypeIsLike(t *testing.T) {
51 f := "foo"
52 tpl := `{{if typeIsLike "string" .}}t{{else}}f{{end}}`
53 if err := runtv(tpl, "t", f); err != nil {
54 t.Error(err)
55 }
56
57
58 f2 := &f
59 if err := runtv(tpl, "t", f2); err != nil {
60 t.Error(err)
61 }
62 }
63 func TestKindIs(t *testing.T) {
64 f := &fixtureTO{"hello", "world"}
65 tpl := `{{if kindIs "ptr" .}}t{{else}}f{{end}}`
66 if err := runtv(tpl, "t", f); err != nil {
67 t.Error(err)
68 }
69 f2 := "hello"
70 if err := runtv(tpl, "f", f2); err != nil {
71 t.Error(err)
72 }
73 }
74
View as plain text