github.com/zhongdalu/gf@v1.0.0/g/text/gstr/gstr_z_unit_pos_test.go (about) 1 // Copyright 2019 gf Author(https://github.com/zhongdalu/gf). 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/zhongdalu/gf. 6 7 // go test *.go -bench=".*" 8 9 package gstr_test 10 11 import ( 12 "github.com/zhongdalu/gf/g/test/gtest" 13 "github.com/zhongdalu/gf/g/text/gstr" 14 "testing" 15 ) 16 17 func Test_Pos(t *testing.T) { 18 gtest.Case(t, func() { 19 s1 := "abcdEFGabcdefg" 20 gtest.Assert(gstr.Pos(s1, "ab"), 0) 21 gtest.Assert(gstr.Pos(s1, "ab", 2), 7) 22 gtest.Assert(gstr.Pos(s1, "abd", 0), -1) 23 gtest.Assert(gstr.Pos(s1, "e", -4), 11) 24 }) 25 } 26 27 func Test_PosI(t *testing.T) { 28 gtest.Case(t, func() { 29 s1 := "abcdEFGabcdefg" 30 gtest.Assert(gstr.PosI(s1, "zz"), -1) 31 gtest.Assert(gstr.PosI(s1, "ab"), 0) 32 gtest.Assert(gstr.PosI(s1, "ef", 2), 4) 33 gtest.Assert(gstr.PosI(s1, "abd", 0), -1) 34 gtest.Assert(gstr.PosI(s1, "E", -4), 11) 35 }) 36 } 37 38 func Test_PosR(t *testing.T) { 39 gtest.Case(t, func() { 40 s1 := "abcdEFGabcdefg" 41 s2 := "abcdEFGz1cdeab" 42 gtest.Assert(gstr.PosR(s1, "zz"), -1) 43 gtest.Assert(gstr.PosR(s1, "ab"), 7) 44 gtest.Assert(gstr.PosR(s2, "ab", -2), 0) 45 gtest.Assert(gstr.PosR(s1, "ef"), 11) 46 gtest.Assert(gstr.PosR(s1, "abd", 0), -1) 47 gtest.Assert(gstr.PosR(s1, "e", -4), -1) 48 }) 49 } 50 51 func Test_PosRI(t *testing.T) { 52 gtest.Case(t, func() { 53 s1 := "abcdEFGabcdefg" 54 s2 := "abcdEFGz1cdeab" 55 gtest.Assert(gstr.PosRI(s1, "zz"), -1) 56 gtest.Assert(gstr.PosRI(s1, "AB"), 7) 57 gtest.Assert(gstr.PosRI(s2, "AB", -2), 0) 58 gtest.Assert(gstr.PosRI(s1, "EF"), 11) 59 gtest.Assert(gstr.PosRI(s1, "abd", 0), -1) 60 gtest.Assert(gstr.PosRI(s1, "e", -5), 4) 61 }) 62 }