github.com/gogf/gf/v2@v2.7.4/text/gstr/gstr_z_unit_array_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 // go test *.go -bench=".*" 8 9 package gstr_test 10 11 import ( 12 "testing" 13 14 "github.com/gogf/gf/v2/frame/g" 15 "github.com/gogf/gf/v2/test/gtest" 16 "github.com/gogf/gf/v2/text/gstr" 17 ) 18 19 func Test_SearchArray(t *testing.T) { 20 gtest.C(t, func(t *gtest.T) { 21 a := g.SliceStr{"a", "b", "c"} 22 t.AssertEQ(gstr.SearchArray(a, "a"), 0) 23 t.AssertEQ(gstr.SearchArray(a, "b"), 1) 24 t.AssertEQ(gstr.SearchArray(a, "c"), 2) 25 t.AssertEQ(gstr.SearchArray(a, "d"), -1) 26 }) 27 } 28 29 func Test_InArray(t *testing.T) { 30 gtest.C(t, func(t *gtest.T) { 31 a := g.SliceStr{"a", "b", "c"} 32 t.AssertEQ(gstr.InArray(a, "a"), true) 33 t.AssertEQ(gstr.InArray(a, "b"), true) 34 t.AssertEQ(gstr.InArray(a, "c"), true) 35 t.AssertEQ(gstr.InArray(a, "d"), false) 36 }) 37 } 38 39 func Test_PrefixArray(t *testing.T) { 40 gtest.C(t, func(t *gtest.T) { 41 a := g.SliceStr{"a", "b", "c"} 42 gstr.PrefixArray(a, "1-") 43 t.AssertEQ(a, g.SliceStr{"1-a", "1-b", "1-c"}) 44 }) 45 }