mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
regexp: move to old/regexp, replace with exp/regexp
R=golang-dev, r CC=golang-dev https://golang.org/cl/5127042
This commit is contained in:
parent
a8a18f6566
commit
6c230fbc67
37 changed files with 1065 additions and 1065 deletions
101
src/pkg/regexp/syntax/prog_test.go
Normal file
101
src/pkg/regexp/syntax/prog_test.go
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
package syntax
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var compileTests = []struct {
|
||||
Regexp string
|
||||
Prog string
|
||||
}{
|
||||
{"a", ` 0 fail
|
||||
1* rune "a" -> 2
|
||||
2 match
|
||||
`},
|
||||
{"[A-M][n-z]", ` 0 fail
|
||||
1* rune "AM" -> 2
|
||||
2 rune "nz" -> 3
|
||||
3 match
|
||||
`},
|
||||
{"", ` 0 fail
|
||||
1* nop -> 2
|
||||
2 match
|
||||
`},
|
||||
{"a?", ` 0 fail
|
||||
1 rune "a" -> 3
|
||||
2* alt -> 1, 3
|
||||
3 match
|
||||
`},
|
||||
{"a??", ` 0 fail
|
||||
1 rune "a" -> 3
|
||||
2* alt -> 3, 1
|
||||
3 match
|
||||
`},
|
||||
{"a+", ` 0 fail
|
||||
1* rune "a" -> 2
|
||||
2 alt -> 1, 3
|
||||
3 match
|
||||
`},
|
||||
{"a+?", ` 0 fail
|
||||
1* rune "a" -> 2
|
||||
2 alt -> 3, 1
|
||||
3 match
|
||||
`},
|
||||
{"a*", ` 0 fail
|
||||
1 rune "a" -> 2
|
||||
2* alt -> 1, 3
|
||||
3 match
|
||||
`},
|
||||
{"a*?", ` 0 fail
|
||||
1 rune "a" -> 2
|
||||
2* alt -> 3, 1
|
||||
3 match
|
||||
`},
|
||||
{"a+b+", ` 0 fail
|
||||
1* rune "a" -> 2
|
||||
2 alt -> 1, 3
|
||||
3 rune "b" -> 4
|
||||
4 alt -> 3, 5
|
||||
5 match
|
||||
`},
|
||||
{"(a+)(b+)", ` 0 fail
|
||||
1* cap 2 -> 2
|
||||
2 rune "a" -> 3
|
||||
3 alt -> 2, 4
|
||||
4 cap 3 -> 5
|
||||
5 cap 4 -> 6
|
||||
6 rune "b" -> 7
|
||||
7 alt -> 6, 8
|
||||
8 cap 5 -> 9
|
||||
9 match
|
||||
`},
|
||||
{"a+|b+", ` 0 fail
|
||||
1 rune "a" -> 2
|
||||
2 alt -> 1, 6
|
||||
3 rune "b" -> 4
|
||||
4 alt -> 3, 6
|
||||
5* alt -> 1, 3
|
||||
6 match
|
||||
`},
|
||||
{"A[Aa]", ` 0 fail
|
||||
1* rune "A" -> 2
|
||||
2 rune "A"/i -> 3
|
||||
3 match
|
||||
`},
|
||||
{"(?:(?:^).)", ` 0 fail
|
||||
1* empty 4 -> 2
|
||||
2 rune "\x00\t\v\U0010ffff" -> 3
|
||||
3 match
|
||||
`},
|
||||
}
|
||||
|
||||
func TestCompile(t *testing.T) {
|
||||
for _, tt := range compileTests {
|
||||
re, _ := Parse(tt.Regexp, Perl)
|
||||
p, _ := Compile(re)
|
||||
s := p.String()
|
||||
if s != tt.Prog {
|
||||
t.Errorf("compiled %#q:\n--- have\n%s---\n--- want\n%s---", tt.Regexp, s, tt.Prog)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue