1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00
go-cqhttp/modules/config/config_test.go
2022-02-09 15:01:38 +08:00

49 lines
947 B
Go

package config
import (
"strings"
"testing"
)
func Test_expand(t *testing.T) {
nullStringMapping := func(_ string) string {
return ""
}
tests := []struct {
src string
mapping func(string) string
expected string
}{
{
src: "foo: ${bar}",
mapping: strings.ToUpper,
expected: "foo: BAR",
},
{
src: "$123",
mapping: strings.ToUpper,
expected: "$123",
},
{
src: "foo: ${bar:123456}",
mapping: nullStringMapping,
expected: "foo: 123456",
},
{
src: "foo: ${bar:127.0.0.1:5700}",
mapping: nullStringMapping,
expected: "foo: 127.0.0.1:5700",
},
{
src: "foo: ${bar:ws//localhost:9999/ws}",
mapping: nullStringMapping,
expected: "foo: ws//localhost:9999/ws",
},
}
for i, tt := range tests {
if got := expand(tt.src, tt.mapping); got != tt.expected {
t.Errorf("testcase %d failed, expected %v but got %v", i, tt.expected, got)
}
}
}