-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitter_test.go
More file actions
123 lines (117 loc) · 2.63 KB
/
splitter_test.go
File metadata and controls
123 lines (117 loc) · 2.63 KB
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
116
117
118
119
120
121
122
123
package dipper
import (
"reflect"
"testing"
)
func TestAttributeSplitter(t *testing.T) {
type args struct {
s string
sep string
}
tests := []struct {
name string
args args
want []string
}{
{
name: "01",
args: args{s: "foo.bar", sep: "."},
want: []string{"foo", "bar"},
},
{
name: "02",
args: args{s: ",a,b,c,d,e,f,g,h,", sep: ","},
want: []string{"", "a", "b", "c", "d", "e", "f", "g", "h", ""},
},
{
name: "03",
args: args{s: "", sep: "."},
want: []string{""},
},
{
name: "04",
args: args{s: "-a->b->c->d->e->f->g->h->", sep: "->"},
want: []string{"-a", "b", "c", "d", "e", "f", "g", "h", ""},
},
{
name: "05",
args: args{s: "", sep: "->"},
want: []string{""},
},
{
name: "06",
args: args{s: "a-->b", sep: "-->"},
want: []string{"a", "b"},
},
{
name: "07",
args: args{s: "", sep: "."},
want: []string{""},
},
{
name: "08",
args: args{s: "Book", sep: "."},
want: []string{"Book"},
},
{
name: "09",
args: args{s: "Book.1.Year", sep: "."},
want: []string{"Book", "1", "Year"},
},
{
name: "10",
args: args{s: "Book[1].Year", sep: "."},
want: []string{"Book", "[1]", "Year"},
},
{
name: "11",
args: args{s: "genres[id=0]", sep: "."},
want: []string{"genres", "[id=0]"},
},
{
name: "12",
args: args{s: "genres[id=0].name", sep: "."},
want: []string{"genres", "[id=0]", "name"},
},
{
name: "13",
args: args{s: "genres[id=0.0].name", sep: "."},
want: []string{"genres", "[id=0.0]", "name"},
},
{
name: "14",
args: args{s: "genres->[id=0.0]->name", sep: "->"},
want: []string{"genres", "", "[id=0.0]", "name"},
},
{
name: "15",
args: args{s: "genres.[id=0].name", sep: "."},
want: []string{"genres", "", "[id=0]", "name"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
split := newAttributeSplitter(tt.args.s, tt.args.sep)
count := split.CountRemaining()
if count != len(tt.want) {
t.Errorf("CountRemaining() returned an unexpected value (got %d, want %d)", count, len(tt.want))
}
expectedIndex := 0
var results []string
for split.HasMore() {
part, index := split.Next()
results = append(results, part)
if index != expectedIndex {
t.Errorf("HasMore() returned an unexpected index (got %d, want %d)", index, expectedIndex)
}
expectedIndex++
}
if _, i := split.Next(); i != -1 {
t.Errorf("Next() returned an index different than -1, but splitter is exhausted")
}
if !reflect.DeepEqual(results, tt.want) {
t.Errorf("newAttributeSplitter() = %v, want %v", results, tt.want)
}
})
}
}