package store import "testing" func TestNormalizeContactPhone(t *testing.T) { for _, tc := range []struct{ input, want string }{ {"", ""}, {" 03-1234-5678 ", "0312345678"}, {"+81 (90) 1234-5678", "+819012345678"}, } { _, got, err := NormalizeContactPhone(tc.input) if err != nil || got != tc.want { t.Fatalf("%q: %q %v", tc.input, got, err) } } for _, input := range []string{"*21*123#", "tel:1234", "javascript:alert(1)", "123;ext=4", "123,456", "123\r\n456", "\t123", "123", "12+34", "+", "12", "1234567890123456", "(+)123", "123\x1b"} { if _, _, err := NormalizeContactPhone(input); err == nil { t.Errorf("accepted %q", input) } } }