github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zstring/dispose_test.go (about) 1 package zstring_test 2 3 import ( 4 "testing" 5 6 "github.com/sohaha/zlsgo" 7 "github.com/sohaha/zlsgo/zstring" 8 ) 9 10 func TestFilter(t *testing.T) { 11 tt := zlsgo.NewTest(t) 12 f := zstring.NewFilter([]string{"我", "你", "他", "初音", ""}, '#') 13 res, keywords, found := f.Filter("你是谁,我是谁,他又是谁") 14 tt.EqualTrue(found) 15 tt.EqualExit(3, len(keywords)) 16 tt.EqualExit("#是谁,#是谁,#又是谁", res) 17 18 _, _, found = f.Filter("") 19 tt.EqualExit(false, found) 20 21 t.Log(2, len(f.Find("你是谁,初音又是谁"))) 22 t.Log(0, len(f.Find(""))) 23 } 24 25 func TestReplacer(t *testing.T) { 26 tt := zlsgo.NewTest(t) 27 r := zstring.NewReplacer(map[string]string{"你": "初音", "它": "犬夜叉"}) 28 res := r.Replace("你是谁,我是谁,它又是谁") 29 tt.EqualExit("初音是谁,我是谁,犬夜叉又是谁", res) 30 t.Log("", r.Replace("")) 31 }