-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpand_test.go
54 lines (43 loc) · 1.19 KB
/
expand_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
package onigmo
import (
"reflect"
"testing"
)
func FooTestExpand(t *testing.T) {
content := []byte(`
# comment line
option1: value1
option2: value2
# another comment line
option3: value3
`)
pattern := MustCompile(`(?m)(?P<key>\w+):\s+(?P<value>\w+)$`)
template := []byte("$key=$value\n")
result := []byte{}
for _, submatches := range pattern.FindAllSubmatchIndex(content, -1) {
result = pattern.Expand(result, template, content, submatches)
}
expected := []byte("option1=value1\noption2=value2\noption3=value3\n")
if !reflect.DeepEqual(result, expected) {
t.Errorf("got %q; want %q", expected, result)
}
}
func TestExpandString(t *testing.T) {
content := `
# comment line
option1: value1
option2: value2
# another comment line
option3: value3
`
pattern := MustCompile(`(?m)(?P<key>\w+):\s+(?P<value>\w+)$`)
template := "$key=$value\n"
result := []byte{}
for _, submatches := range pattern.FindAllStringSubmatchIndex(content, -1) {
result = pattern.ExpandString(result, template, content, submatches)
}
expected := []byte("option1=value1\noption2=value2\noption3=value3\n")
if !reflect.DeepEqual(result, expected) {
t.Errorf("got %q; want %q", expected, result)
}
}