-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstreamregex_test.go
More file actions
55 lines (52 loc) · 998 Bytes
/
streamregex_test.go
File metadata and controls
55 lines (52 loc) · 998 Bytes
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
package streamregex
import (
"context"
"regexp"
"strings"
"testing"
)
func TestFindReader(t *testing.T) {
tests := []struct {
input string
match string
regex *regexp.Regexp
maxMatchLen int
numMatchs int
}{
{
`0123456789this is a stream of data with lots of trailing information`,
`stream of`,
regexp.MustCompile(`stream\s+of`),
40,
1,
},
{
`test test test test test test test test test`,
`test`,
regexp.MustCompile(`test`),
4,
9,
},
{
`cut off match`,
`f ma`,
regexp.MustCompile(`f ma`),
4,
1,
},
}
for _, test := range tests {
// Find matches
matchedData := FindReader(context.Background(), test.regex, test.maxMatchLen, strings.NewReader(test.input))
matches := 0
for match := range matchedData {
matches++
if match != test.match {
t.Errorf("Invalid match: %s", match)
}
}
if matches != test.numMatchs {
t.Errorf("Did not find correct number of matches")
}
}
}