github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2012/simple/test/string_test.go (about) 1 // +build OMIT 2 3 package string_test 4 5 import ( 6 "fmt" 7 "strings" 8 "testing" 9 ) 10 11 func TestIndex(t *testing.T) { 12 var tests = []struct { 13 s string 14 sep string 15 out int 16 }{ 17 {"", "", 0}, 18 {"", "a", -1}, 19 {"fo", "foo", -1}, 20 {"foo", "foo", 0}, 21 {"oofofoofooo", "f", 2}, 22 // etc 23 } 24 for _, test := range tests { 25 actual := strings.Index(test.s, test.sep) 26 if actual != test.out { 27 t.Errorf("Index(%q,%q) = %v; want %v", test.s, test.sep, actual, test.out) 28 } 29 } 30 } 31 32 func BenchmarkIndex(b *testing.B) { 33 const s = "some_text=some☺value" 34 for i := 0; i < b.N; i++ { 35 strings.Index(s, "v") 36 } 37 } 38 39 func ExampleIndex() { 40 fmt.Println(strings.Index("chicken", "ken")) 41 fmt.Println(strings.Index("chicken", "dmr")) 42 // Output: 43 // 4 44 // -1 45 }