diff options
Diffstat (limited to 'src/runtime/string_test.go')
| -rw-r--r-- | src/runtime/string_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/runtime/string_test.go b/src/runtime/string_test.go index 678ff00363..a1716fa32f 100644 --- a/src/runtime/string_test.go +++ b/src/runtime/string_test.go @@ -240,6 +240,34 @@ func TestCompareTempString(t *testing.T) { } } +func TestStringIndexHaystack(t *testing.T) { + // See issue 25864. + haystack := []byte("hello") + needle := "ll" + n := testing.AllocsPerRun(1000, func() { + if strings.Index(string(haystack), needle) != 2 { + t.Fatalf("needle not found") + } + }) + if n != 0 { + t.Fatalf("want 0 allocs, got %v", n) + } +} + +func TestStringIndexNeedle(t *testing.T) { + // See issue 25864. + haystack := "hello" + needle := []byte("ll") + n := testing.AllocsPerRun(1000, func() { + if strings.Index(haystack, string(needle)) != 2 { + t.Fatalf("needle not found") + } + }) + if n != 0 { + t.Fatalf("want 0 allocs, got %v", n) + } +} + func TestStringOnStack(t *testing.T) { s := "" for i := 0; i < 3; i++ { |
