diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-07-05 19:45:56 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-07-05 19:45:56 +0200 |
| commit | 6fe1bcf384a34fdfc1704ff98ee5151a75d031a2 (patch) | |
| tree | ec0fc9cc5a17cdafacd6a04bb599865a2d959dbe /pkg/email/parser_test.go | |
| parent | 6231964849eb9362c20b82279d92da96fb556209 (diff) | |
pkg/email: add AddAddrContext/RemoveAddrContext
Replace extractBugID function with more general AddAddrContext/RemoveAddrContext.
Diffstat (limited to 'pkg/email/parser_test.go')
| -rw-r--r-- | pkg/email/parser_test.go | 81 |
1 files changed, 49 insertions, 32 deletions
diff --git a/pkg/email/parser_test.go b/pkg/email/parser_test.go index 7b2aa9a0f..d05a597be 100644 --- a/pkg/email/parser_test.go +++ b/pkg/email/parser_test.go @@ -23,16 +23,55 @@ func TestExtractCommand(t *testing.T) { } } -func TestExtractBugID(t *testing.T) { - for i, test := range extractBugIDTests { - t.Run(fmt.Sprint(i), func(t *testing.T) { - bugID, own := extractBugID(test.email, `"Foo Bar" <foo@bar.com>`) - if bugID != test.bugID || own != test.own { - t.Logf("expect: own=%v %q", test.own, test.bugID) - t.Logf("got : own=%v %q", test.own, bugID) - t.Fail() - } - }) +func TestAddRemoveAddrContext(t *testing.T) { + email := `"Foo Bar" <foo@bar.com>` + email00, context00, err := RemoveAddrContext(email) + if err != nil { + t.Fatal(err) + } + if email != email00 { + t.Fatalf("want: %q, got %q", email, email00) + } + if context00 != "" { + t.Fatalf("want context: %q, got %q", "", context00) + } + context1 := "context1" + email1, err := AddAddrContext(email, context1) + if err != nil { + t.Fatal(err) + } + want1 := `"Foo Bar" <foo+context1@bar.com>` + if want1 != email1 { + t.Fatalf("want: %q, got %q", want1, email1) + } + context2 := "context2" + email2, err := AddAddrContext(email1, context2) + if err != nil { + t.Fatal(err) + } + want2 := `"Foo Bar" <foo+context1+context2@bar.com>` + if want2 != email2 { + t.Fatalf("want: %q, got %q", want2, email2) + } + email1, context20, err := RemoveAddrContext(email2) + if err != nil { + t.Fatal(err) + } + if want1 != email1 { + t.Fatalf("want: %q, got %q", want1, email1) + } + if context2 != context20 { + t.Fatalf("want context: %q, got %q", context2, context20) + } + email0, context10, err := RemoveAddrContext(email1) + if err != nil { + t.Fatal(err) + } + if email != email0 { + t.Fatalf("want: %q, got %q", email, email0) + } + if context1 != context10 { + t.Fatalf("want context: %q, got %q", context1, context10) } } @@ -86,28 +125,6 @@ line 2 }, } -var extractBugIDTests = []struct { - email string - bugID string - own bool -}{ - { - `foo@bar.com`, - ``, - true, - }, - { - `foo+123@baz.com`, - ``, - false, - }, - { - `foo+123@bar.com`, - `123`, - true, - }, -} - var parseTests = []struct { email string res *Email |
