This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
option_test.go
115 lines (105 loc) · 2.46 KB
/
option_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
package views
import (
"html/template"
"reflect"
"testing"
)
func TestCache(t *testing.T) {
tests := []bool{false, true, false}
for _, cache := range tests {
m := New(testFileSystem, Cache(cache))
if m.cache != cache {
t.Errorf("expected cache %t, got %t", cache, m.cache)
}
}
}
func TestDelimis(t *testing.T) {
tests := [][]string{
{"{{", "}}"},
{"{{{", "}}}"},
{"{{#", "#}}"},
}
for _, test := range tests {
m := New(testFileSystem, Delims(test[0], test[1]))
if !reflect.DeepEqual(m.delims, test) {
t.Errorf("expected delims %v, got %v", test, m.delims)
}
}
}
/*
func TestLayout(t *testing.T) {
tests := [][]string{
{},
{"foo"},
{"foo", "bar"},
}
for _, layouts := range tests {
m := New("", Layouts(layouts...))
if !reflect.DeepEqual(v.layouts, layouts) {
t.Errorf("expected layouts %v, got %v", layouts, v.layouts)
}
}
}
*/
func TestSuffix(t *testing.T) {
tests := []string{".tmpl", ".tpl", ".html", "htm"}
for _, suffix := range tests {
m := New(testFileSystem, Suffix(suffix))
if m.suffix != suffix {
t.Errorf("expected suffix %q, got %q", suffix, m.suffix)
}
}
}
func TestDefaultLayout(t *testing.T) {
tests := []struct {
layout string
}{
{"main"},
{"page"},
}
for _, test := range tests {
m := New(testFileSystem, DefaultLayout(test.layout))
if m.defaultLayout != test.layout {
t.Errorf("expected default layout %q, got %q", test.layout, m.defaultLayout)
}
}
}
func TestLayoutsDir(t *testing.T) {
tests := []string{"layouts1", "layouts2"}
for _, dir := range tests {
m := New(testFileSystem, LayoutsDir(dir))
if m.layoutsDir != dir {
t.Errorf("expected layouts directory %q, got %q", dir, m.partialsDir)
}
}
}
func TestPartialsDir(t *testing.T) {
tests := []string{"partials1", "partials2"}
for _, dir := range tests {
m := New(testFileSystem, PartialsDir(dir))
if m.partialsDir != dir {
t.Errorf("expected partials directory %q, got %q", dir, m.partialsDir)
}
}
}
func TestFuncMap(t *testing.T) {
tests := []template.FuncMap{
{
"foo": func() string { return "foo" },
},
{
"bar": func() string { return "bar" },
},
}
for _, funcMap := range tests {
m := New(testFileSystem, FuncMap(funcMap))
for name := range funcMap {
if _, ok := m.funcMap[name]; !ok {
t.Errorf("failed to add function %s", name)
}
}
}
}