Debian Codegraph @

internal/stringutil/addr_test.go

raw
1 package stringutil_test
2
3 import (
4 "net/mail"
5 "testing"
6
7 "github.com/jhillyerd/enmime/internal/stringutil"
8 )
9
10 func TestJoinAddressEmpty(t *testing.T) {
11 got := stringutil.JoinAddress(make([]mail.Address, 0))
12 if got != "" {
13 t.Errorf("Empty list got: %q, wanted empty string", got)
14 }
15 }
16
17 func TestJoinAddressSingle(t *testing.T) {
18 input := []mail.Address{
19 {Name: "", Address: "[email protected]"},
20 }
21 want := "<[email protected]>"
22 got := stringutil.JoinAddress(input)
23 if got != want {
24 t.Errorf("got: %q, want: %q", got, want)
25 }
26
27 input = []mail.Address{
28 {Name: "one name", Address: "[email protected]"},
29 }
30 want = `"one name" <[email protected]>`
31 got = stringutil.JoinAddress(input)
32 if got != want {
33 t.Errorf("got: %q, want: %q", got, want)
34 }
35 }
36
37 func TestJoinAddressMany(t *testing.T) {
38 input := []mail.Address{
39 {Name: "one", Address: "[email protected]"},
40 {Name: "", Address: "[email protected]"},
41 {Name: "three", Address: "[email protected]"},
42 }
43 want := `"one" <[email protected]>, <[email protected]>, "three" <[email protected]>`
44 got := stringutil.JoinAddress(input)
45 if got != want {
46 t.Errorf("got: %q, want: %q", got, want)
47 }
48 }