-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_test.go
79 lines (73 loc) · 1.54 KB
/
node_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
// Copyright 2014 Alvaro J. Genial. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package form
import (
"reflect"
"testing"
)
type foo int
type bar interface {
void()
}
type qux struct{}
type zee []bar
func TestCanIndexOrdinally(t *testing.T) {
for _, c := range []struct {
x interface{}
b bool
}{
{int(0), false},
{foo(0), false},
{qux{}, false},
{(*int)(nil), false},
{(*foo)(nil), false},
{(*bar)(nil), false},
{(*qux)(nil), false},
{[]qux{}, true},
{[5]qux{}, true},
{&[]foo{}, true},
{&[5]foo{}, true},
{zee{}, true},
{&zee{}, true},
{map[int]foo{}, false},
{map[string]interface{}{}, false},
{map[interface{}]bar{}, false},
{(chan<- int)(nil), false},
{(chan bar)(nil), false},
{(<-chan foo)(nil), false},
} {
v := reflect.ValueOf(c.x)
if b := canIndexOrdinally(v); b != c.b {
t.Errorf("canIndexOrdinally(%v)\nwant (%v)\nhave (%v)", v, c.b, b)
}
}
}
func TestEscape(t *testing.T) {
for _, c := range []struct {
a, b string
}{
{"Foo", "Foo"},
{"Foo.Bar.Qux", "Foo\\.Bar\\.Qux"},
{"0", "0"},
{"0.1.2", "0\\.1\\.2"},
} {
if b := escape(c.a); b != c.b {
t.Errorf("escape(%v)\nwant (%v)\nhave (%v)", c.a, c.b, b)
}
}
}
func TestUnescape(t *testing.T) {
for _, c := range []struct {
a, b string
}{
{"Foo", "Foo"},
{"Foo.Bar.Qux", "Foo\\.Bar\\.Qux"},
{"0", "0"},
{"0.1.2", "0\\.1\\.2"},
} {
if a := unescape(c.b); a != c.a {
t.Errorf("unescape(%v)\nwant (%v)\nhave (%v)", c.b, c.a, a)
}
}
}