代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"testing"
)
func TestValidateID(t *testing.T) {
for _, tc := range []struct {
in string
want error
}{
{
in: "D9L6MbPfE4",
want: nil,
},
{
in: "ABZdez09-_",
want: nil,
},
{
in: "N_M_YelfGeR",
want: nil,
},
{
in: "Abc",
want: fmt.Errorf("id length is 3 instead of 10 or 11"),
},
{
in: "Abc?q=1235",
want: fmt.Errorf("id contains unexpected character '?'"),
},
{
in: "../../file",
want: fmt.Errorf("id contains unexpected character '.'"),
},
{
in: "Heya世界",
want: fmt.Errorf(`id contains unexpected character '\u00e4'`),
},
} {
got := validateID(tc.in)
if !equalError(got, tc.want) {
t.Errorf("validateID(%q) error doesn't match:\n got: %v\nwant: %v", tc.in, got, tc.want)
}
}
}
// equalError reports whether errors a and b are considered equal.
// They're equal if both are nil, or both are not nil and a.Error() == b.Error().
func equalError(a, b error) bool {
return a == nil && b == nil || a != nil && b != nil && a.Error() == b.Error()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。