package controllers import ( "testing" ) func TestExtractEmailSimple(t *testing.T) { tests := []struct { input string want string }{ {"user@example.com", "user@example.com"}, {"", "user@example.com"}, {"John Doe ", "john@example.com"}, {"\"John Doe\" ", "john@example.com"}, {" spaced@example.com ", "spaced@example.com"}, {"", ""}, {"", "onlybrackets"}, } for _, tt := range tests { got := extractEmail(tt.input) if got != tt.want { t.Errorf("extractEmail(%q) = %q, want %q", tt.input, got, tt.want) } } } func TestExtractNameSimple(t *testing.T) { tests := []struct { input string want string }{ {"John Doe ", "John Doe"}, {"", ""}, {"user@example.com", ""}, {" Spaces Here ", "Spaces Here"}, {"\"Quoted Name\" ", "\"Quoted Name\""}, {"", ""}, } for _, tt := range tests { got := extractName(tt.input) if got != tt.want { t.Errorf("extractName(%q) = %q, want %q", tt.input, got, tt.want) } } } func TestExtractEmailRealWorld(t *testing.T) { inputs := []struct { full string mail string name string }{ {"María López ", "maria@example.com", "María López"}, {"soporte@u-s.app", "soporte@u-s.app", ""}, {"Cliente Final ", "cliente+tag@dominio.co", "Cliente Final"}, {"", "", ""}, } for _, tt := range inputs { gotMail := extractEmail(tt.full) gotName := extractName(tt.full) if gotMail != tt.mail { t.Errorf("extractEmail(%q) = %q, want %q", tt.full, gotMail, tt.mail) } if gotName != tt.name { t.Errorf("extractName(%q) = %q, want %q", tt.full, gotName, tt.name) } } } func TestExtractEmailEdgeCases(t *testing.T) { // Formato RFC 5322 con nombre y ángulos if got := extractEmail("a"); got != "b@c.com" { t.Errorf("extractEmail('a') = %q, want 'b@c.com'", got) } // Múltiples brackets — usa el último par if got := extractEmail(""); got != "b@c.com" { t.Errorf("extractEmail('') = %q, want 'b@c.com'", got) } }