package phone import "testing" func TestToLocal(t *testing.T) { tests := []struct { name string input string want string wantErr bool }{ {"e164 with plus", "+639171234567", "09171234567", false}, {"e164 without plus", "639171234567", "09171234567", false}, {"already local", "09171234567", "09171234567", false}, {"missing leading zero", "9171234567", "09171234567", false}, {"non-PH number", "+1234567890", "", true}, {"empty", "", "", true}, {"with spaces", "+63 917 123 4567", "09171234567", false}, {"with dashes", "0917-123-4567", "09171234567", false}, {"too short", "0917", "", true}, {"too long", "091712345678", "", true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := ToLocal(tt.input) if (err != nil) != tt.wantErr { t.Errorf("ToLocal(%q) error = %v, wantErr %v", tt.input, err, tt.wantErr) return } if got != tt.want { t.Errorf("ToLocal(%q) = %q, want %q", tt.input, got, tt.want) } }) } } func TestToE164(t *testing.T) { tests := []struct { name string input string want string wantErr bool }{ {"standard local", "09171234567", "+639171234567", false}, {"missing leading zero", "9171234567", "+639171234567", false}, {"already e164", "+639171234567", "+639171234567", false}, {"e164 without plus", "639171234567", "+639171234567", false}, {"with spaces", "0917 123 4567", "+639171234567", false}, {"with dashes", "0917-123-4567", "+639171234567", false}, {"empty", "", "", true}, {"too short", "0917", "", true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := ToE164(tt.input) if (err != nil) != tt.wantErr { t.Errorf("ToE164(%q) error = %v, wantErr %v", tt.input, err, tt.wantErr) return } if got != tt.want { t.Errorf("ToE164(%q) = %q, want %q", tt.input, got, tt.want) } }) } }