mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-06 07:26:53 +08:00

* anyutil test * fix:delete debug * unit test utils * unit test * strUtil unit test * fix;4, 6, 9, 11 Month determination error * fix:The last digit of ID number is x, and the weighted sum comparison condition is wrong * test * test * docs * fix:docs * idcard test * test unit * no message * docs update * 单元测试覆盖 --------- Co-authored-by: libin <libinjob@163.com> Co-authored-by: 李斌 <libin1-hj@huafang.com>
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package validUtil
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
//func TestIsIDCard18Demo(t *testing.T) {
|
|
// fmt.Println(IsIDCard18("120103199001015953"))
|
|
// fmt.Println(IsIDCard18("44080319861221348X"))
|
|
//}
|
|
|
|
func TestIsIDCard(t *testing.T) {
|
|
cases := []struct {
|
|
input string
|
|
want bool
|
|
}{
|
|
{"", false},
|
|
{"110102197809193026", true},
|
|
{"142629680611101", true},
|
|
}
|
|
for _, c := range cases {
|
|
got := IsIDCard(c.input)
|
|
if got != c.want {
|
|
t.Errorf("IsIDCard(%q) == %v, want %v", c.input, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsIDCard18(t *testing.T) {
|
|
// 18位身份证号码测试
|
|
cases18 := []struct {
|
|
input string
|
|
want bool
|
|
}{
|
|
{"", false},
|
|
{"120103109001015953", false}, // 年份非法
|
|
{"120103199018015953", false}, // 月份非法
|
|
{"120103199001505953", false}, // 日期非法
|
|
{"123456789012345678", false},
|
|
{"12345678901234567X", false},
|
|
{"12345678901234567x", false},
|
|
{"110102197809193026", true},
|
|
{"210381199503166219", true},
|
|
{"64010219940313212X", true},
|
|
{"120103199001015953", true},
|
|
{"44080319861221348X", true},
|
|
}
|
|
for _, c := range cases18 {
|
|
got := IsIDCard18(c.input)
|
|
if got != c.want {
|
|
t.Errorf("IsIDCard18(%q) == %v, want %v", c.input, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsIDCard15(t *testing.T) {
|
|
// 15位身份证号码测试
|
|
cases15 := []struct {
|
|
input string
|
|
want bool
|
|
}{
|
|
{"", false},
|
|
{"142629680611101", true},
|
|
{"610104620927690", true},
|
|
{"142629601611101", false}, // 年份非法
|
|
{"01345678901234", false},
|
|
{"1234567890123X", false},
|
|
{"9994567890123X", false},
|
|
}
|
|
for _, c := range cases15 {
|
|
got := IsIDCard15(c.input)
|
|
if got != c.want {
|
|
t.Errorf("IsIDCard15(%q) == %v, want %v", c.input, got, c.want)
|
|
}
|
|
}
|
|
}
|