package tools import ( "log" "strings" "testing" ) func TestShowString(t *testing.T) { ShowStringByte("hello,世界") } func TestReverse2(t *testing.T) { cases := []struct { in, want string }{ {"Hello, world", "dlrow ,olleH"}, {"Hello, 世界", "界世 ,olleH"}, {"", ""}, } for _, c := range cases { got := Reverse2(c.in) if got != c.want { t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want) } } } func TestSubStr(t *testing.T) { str := "kefu1.baidu.com.cn" log.Println(SubStr(str, 1, 1)) start := strings.Index(str, ".") res := SubStr(str, start+1, -1) log.Println(res) res = SubStr("21", 1, 1) log.Println(res) str2 := []rune("21") log.Println(string(str2[len(str2)-2 : len(str2)-1])) str3 := ReplaceAtPosition(string(str2), 1, "3") log.Println(str3) } func TestIsMatchingDomain(t *testing.T) { allowedDomain := "*.baidu.com" domainsToCheck := []string{ "baidu.com", "www.baidu.com", "news.baidu.com", "images.google.com", } for _, domain := range domainsToCheck { if IsMatchingDomain(allowedDomain, domain) { log.Printf("%s 匹配 %s\n", domain, allowedDomain) } else { log.Printf("%s 不匹配 %s\n", domain, allowedDomain) } } } func TestIsStrongPass(t *testing.T) { pass := "123" b := IsStrongPass(pass) log.Println(b) pass = "Aa;2345678a" b = IsStrongPass(pass) log.Println(b) }