-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexp_test.go
47 lines (42 loc) · 932 Bytes
/
regexp_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
package aoc_test
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/teivah/go-aoc"
)
func TestRegexpFindAll(t *testing.T) {
re := regexp.MustCompile(`\d*`)
s := "123,456"
assert.Equal(t, []string{"123", "456"}, aoc.RegexpFindAll(s, re))
}
func TestRegexpFindIndices(t *testing.T) {
re := regexp.MustCompile(`\d*`)
s := "123,456"
assert.Equal(t, []aoc.CapturingGroup{
{0, 3},
{4, 7},
}, aoc.RegexpFindIndices(s, re))
}
func TestRegexpFindSubmatches(t *testing.T) {
re := regexp.MustCompile(`mul\((\d{1,3}),(\d{1,3})\)`)
s := "mul(1,2),mul(42,0)"
assert.Equal(t, []aoc.Submatch{
{
Start: 0,
End: 8,
CapturingGroups: []aoc.CapturingGroup{
{Start: 4, End: 5},
{Start: 6, End: 7},
},
},
{
Start: 9,
End: 18,
CapturingGroups: []aoc.CapturingGroup{
{Start: 13, End: 15},
{Start: 16, End: 17},
},
},
}, aoc.RegexpFindSubmatches(s, re))
}