mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-19 17:15:21 +00:00
add SplitName util and use it to parse email contact names
This commit is contained in:
@@ -270,3 +270,29 @@ func TestSanitizeUTF8(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
wantFirst string
|
||||
wantLast string
|
||||
}{
|
||||
{name: "empty", input: "", wantFirst: "", wantLast: ""},
|
||||
{name: "whitespace only", input: " ", wantFirst: "", wantLast: ""},
|
||||
{name: "single name", input: "Cher", wantFirst: "Cher", wantLast: ""},
|
||||
{name: "first and last", input: "John Doe", wantFirst: "John", wantLast: "Doe"},
|
||||
{name: "middle name", input: "John Michael Doe", wantFirst: "John", wantLast: "Michael Doe"},
|
||||
{name: "multi-word surname", input: "Ludwig van der Berg", wantFirst: "Ludwig", wantLast: "van der Berg"},
|
||||
{name: "extra spaces", input: " John Doe ", wantFirst: "John", wantLast: "Doe"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
first, last := SplitName(tt.input)
|
||||
if first != tt.wantFirst || last != tt.wantLast {
|
||||
t.Errorf("SplitName(%q) = (%q, %q), want (%q, %q)", tt.input, first, last, tt.wantFirst, tt.wantLast)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user