mirror of
https://github.com/golang/go
synced 2024-11-25 19:07:57 -07:00
strings: adjust and add tests for strings.Index and strings.LastIndex
A strings.Index test is implemented in ExampleLastIndex, so moved to ExampleIndex. strings.Index and strings.LastIndex do not have empty substr test, so added them. Change-Id: I9ba6099467addf35b7b6df6840c3278cccca4892
This commit is contained in:
parent
6ae3b70ef2
commit
0d7c239f59
@ -107,9 +107,13 @@ func ExampleHasSuffix() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleIndex() {
|
func ExampleIndex() {
|
||||||
|
fmt.Println(strings.Index("go gopher", "go"))
|
||||||
|
fmt.Println(strings.Index("go gopher", ""))
|
||||||
fmt.Println(strings.Index("chicken", "ken"))
|
fmt.Println(strings.Index("chicken", "ken"))
|
||||||
fmt.Println(strings.Index("chicken", "dmr"))
|
fmt.Println(strings.Index("chicken", "dmr"))
|
||||||
// Output:
|
// Output:
|
||||||
|
// 0
|
||||||
|
// 0
|
||||||
// 4
|
// 4
|
||||||
// -1
|
// -1
|
||||||
}
|
}
|
||||||
@ -151,12 +155,12 @@ func ExampleIndexRune() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleLastIndex() {
|
func ExampleLastIndex() {
|
||||||
fmt.Println(strings.Index("go gopher", "go"))
|
|
||||||
fmt.Println(strings.LastIndex("go gopher", "go"))
|
fmt.Println(strings.LastIndex("go gopher", "go"))
|
||||||
|
fmt.Println(strings.LastIndex("go gopher", ""))
|
||||||
fmt.Println(strings.LastIndex("go gopher", "rodent"))
|
fmt.Println(strings.LastIndex("go gopher", "rodent"))
|
||||||
// Output:
|
// Output:
|
||||||
// 0
|
|
||||||
// 3
|
// 3
|
||||||
|
// 9
|
||||||
// -1
|
// -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user