-
Notifications
You must be signed in to change notification settings - Fork 1
/
funcs_test.go
38 lines (33 loc) · 839 Bytes
/
funcs_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
// Copyright 2020 Jonathan Amsterdam.
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.
package templatecheck
import (
"reflect"
"testing"
"text/template/parse"
)
func TestCheckSlice(t *testing.T) {
// Verify return types for slice.
type (
stringType string
sliceType []int
arrayType [1]int
)
for _, test := range []struct {
item, want any
}{
{"x", ""},
{[]int{}, []int{}},
{stringType(""), stringType("")},
{sliceType{}, sliceType{}},
{[1]int{}, []int{}}, // slice(array) => slice
{arrayType{}, []int{}}, // ditto, defined type is lost
} {
got := checkSlice(&state{}, reflect.TypeOf(test.item), []parse.Node{&parse.DotNode{}})
want := reflect.TypeOf(test.want)
if got != want {
t.Errorf("%T: got %s, want %s", test.item, got, want)
}
}
}