-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_replacer_test.go
More file actions
22 lines (19 loc) · 1.09 KB
/
Copy pathpython_replacer_test.go
File metadata and controls
22 lines (19 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package onig
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestPythonRegexReplacer(t *testing.T) {
r := MustCompileWithSyntax(`hello (.*)`, SyntaxPython)
assert.Equal(t, "goodbye hello world", r.MustReplaceAll("hello world", `goodbye \0`))
assert.Equal(t, "goodbye world", r.MustReplaceAll("hello world", `goodbye \1`))
assert.Equal(t, `goodbye \1`, r.MustReplaceAll("hello world", `goodbye \\1`))
r = MustCompileWithSyntax(`hello (?P<name>.*)`, SyntaxPython)
assert.Equal(t, `goodbye \g <name>`, r.MustReplaceAll("hello world", `goodbye \g <name>`))
assert.Equal(t, `goodbye \ g<name>`, r.MustReplaceAll("hello world", `goodbye \ g<name>`))
assert.Equal(t, "goodbye world", r.MustReplaceAll("hello world", `goodbye \g<name>`))
assert.Equal(t, "goodbye world", r.MustReplaceAll("hello world", `goodbye \g<1>`))
assert.Equal(t, "goodbye world1", r.MustReplaceAll("hello world", `goodbye \g<1>1`))
assert.Equal(t, "goodbye hello world", r.MustReplaceAll("hello world", `goodbye \g<0>`))
assert.Equal(t, "goodbye hello world0", r.MustReplaceAll("hello world", `goodbye \g<0>0`))
}