github.com/Mrs4s/go-cqhttp@v1.2.0/modules/config/config_test.go (about) 1 package config 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func Test_expand(t *testing.T) { 9 nullStringMapping := func(_ string) string { 10 return "" 11 } 12 tests := []struct { 13 src string 14 mapping func(string) string 15 expected string 16 }{ 17 { 18 src: "foo: ${bar}", 19 mapping: strings.ToUpper, 20 expected: "foo: BAR", 21 }, 22 { 23 src: "$123", 24 mapping: strings.ToUpper, 25 expected: "$123", 26 }, 27 { 28 src: "foo: ${bar:123456}", 29 mapping: nullStringMapping, 30 expected: "foo: 123456", 31 }, 32 { 33 src: "foo: ${bar:127.0.0.1:5700}", 34 mapping: nullStringMapping, 35 expected: "foo: 127.0.0.1:5700", 36 }, 37 { 38 src: "foo: ${bar:ws//localhost:9999/ws}", 39 mapping: nullStringMapping, 40 expected: "foo: ws//localhost:9999/ws", 41 }, 42 } 43 for i, tt := range tests { 44 if got := expand(tt.src, tt.mapping); got != tt.expected { 45 t.Errorf("testcase %d failed, expected %v but got %v", i, tt.expected, got) 46 } 47 } 48 }