mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
regexp: add (*Regexp).Longest
Fixes #3696. R=rsc CC=golang-dev https://golang.org/cl/7133051
This commit is contained in:
parent
1d9f67daf0
commit
f41ffc2bf4
2 changed files with 22 additions and 0 deletions
|
|
@ -706,3 +706,17 @@ func BenchmarkMatchHard_1K(b *testing.B) { benchmark(b, hard, 1<<10) }
|
|||
func BenchmarkMatchHard_32K(b *testing.B) { benchmark(b, hard, 32<<10) }
|
||||
func BenchmarkMatchHard_1M(b *testing.B) { benchmark(b, hard, 1<<20) }
|
||||
func BenchmarkMatchHard_32M(b *testing.B) { benchmark(b, hard, 32<<20) }
|
||||
|
||||
func TestLongest(t *testing.T) {
|
||||
re, err := Compile(`a(|b)`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if g, w := re.FindString("ab"), "a"; g != w {
|
||||
t.Errorf("first match was %q, want %q", g, w)
|
||||
}
|
||||
re.Longest()
|
||||
if g, w := re.FindString("ab"), "ab"; g != w {
|
||||
t.Errorf("longest match was %q, want %q", g, w)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue