Compare commits
2 Commits
ac05bceda3
...
6869cd00a2
| Author | SHA1 | Date | |
|---|---|---|---|
| 6869cd00a2 | |||
| 02bc8f30a2 |
@@ -148,7 +148,7 @@ func pruneIndices(indices []Match) []Match {
|
|||||||
func (regex Reg) Find(str string) (Group, error) {
|
func (regex Reg) Find(str string) (Group, error) {
|
||||||
match, err := regex.FindNthMatch(str, 1)
|
match, err := regex.FindNthMatch(str, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Group{}, nil
|
return Group{}, fmt.Errorf("no matches found")
|
||||||
}
|
}
|
||||||
return getZeroGroup(match), nil
|
return getZeroGroup(match), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -673,7 +673,33 @@ var groupTests = []struct {
|
|||||||
{`(<389-400>)`, nil, `391`, []Match{[]Group{{0, 3}, {0, 3}}}},
|
{`(<389-400>)`, nil, `391`, []Match{[]Group{{0, 3}, {0, 3}}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindAllMatches(t *testing.T) {
|
func TestFind(t *testing.T) {
|
||||||
|
for _, test := range reTests {
|
||||||
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
||||||
|
regComp, err := Compile(test.re, test.flags...)
|
||||||
|
if err != nil {
|
||||||
|
if test.result != nil {
|
||||||
|
panic(fmt.Errorf("Test Error: %v", err))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
groupIndex, err := regComp.Find(test.str)
|
||||||
|
if err != nil { // No matches found
|
||||||
|
if len(test.result) == 0 {
|
||||||
|
return // Manually pass the test, because this is the expected behavior
|
||||||
|
} else {
|
||||||
|
t.Errorf("Wanted no match Got %v\n", groupIndex)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if groupIndex != test.result[0] {
|
||||||
|
t.Errorf("Wanted %v Got %v\n", test.result, groupIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindAll(t *testing.T) {
|
||||||
for _, test := range reTests {
|
for _, test := range reTests {
|
||||||
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
||||||
regComp, err := Compile(test.re, test.flags...)
|
regComp, err := Compile(test.re, test.flags...)
|
||||||
@@ -716,7 +742,7 @@ func TestFindString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindAllStrings(t *testing.T) {
|
func TestFindAllString(t *testing.T) {
|
||||||
for _, test := range reTests {
|
for _, test := range reTests {
|
||||||
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
||||||
regComp, err := Compile(test.re, test.flags...)
|
regComp, err := Compile(test.re, test.flags...)
|
||||||
@@ -741,7 +767,7 @@ func TestFindAllStrings(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindAllGroups(t *testing.T) {
|
func TestFindAllSubmatch(t *testing.T) {
|
||||||
for _, test := range groupTests {
|
for _, test := range groupTests {
|
||||||
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
||||||
regComp, err := Compile(test.re, test.flags...)
|
regComp, err := Compile(test.re, test.flags...)
|
||||||
|
|||||||
Reference in New Issue
Block a user