github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zstring/expand_test.go (about) 1 package zstring 2 3 import ( 4 "testing" 5 6 "github.com/sohaha/zlsgo" 7 ) 8 9 func TestExpand(t *testing.T) { 10 tt := zlsgo.NewTest(t) 11 12 tt.Equal("hello zlsgo", Expand("hello $world", func(key string) string { 13 return "zlsgo" 14 })) 15 16 tt.Equal("hello {zlsgo}", Expand("hello {$world}", func(key string) string { 17 return "zlsgo" 18 })) 19 20 tt.Equal("hello zlsgo", Expand("hello ${world}", func(key string) string { 21 t.Log(key) 22 return "zlsgo" 23 })) 24 25 var keys []string 26 Expand("${a} $b $c.d ${e.f} $1 - ${*}", func(key string) string { 27 t.Log(key) 28 keys = append(keys, key) 29 return "" 30 }) 31 tt.Equal([]string{"a", "b", "c", "e.f", "1", "*"}, keys) 32 }