File: address_test.go

package info (click to toggle)
golang-github-protonmail-gluon 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,020 kB
  • sloc: sh: 55; makefile: 5
file content (52 lines) | stat: -rw-r--r-- 1,708 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package rfc5322

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestParseAddrSpec(t *testing.T) {
	inputs := map[string]string{
		`pete(his account)@silly.test(his host)`: `pete@silly.test`,
		`jdoe@machine.example`:                   `jdoe@machine.example`,
		`john.q.public@example.com`:              `john.q.public@example.com`,
		`user@example.com`:                       `user@example.com`,
		`user@[10.0.0.1]`:                        `user@[10.0.0.1]`,
		`hořejšek@mail.com `:                     `hořejšek@mail.com`,
	}

	for i, e := range inputs {
		t.Run(i, func(t *testing.T) {
			p := newTestRFCParser(i)
			v, err := parseAddrSpec(p)
			require.NoError(t, err)
			require.Equal(t, e, v)
		})
	}
}

func TestParseAngleAddr(t *testing.T) {
	inputs := map[string]string{
		`<pete(his account)@silly.test(his host)>`: `pete@silly.test`,
		`<jdoe@machine.example>`:                   `jdoe@machine.example`,
		`<john.q.public@example.com>`:              `john.q.public@example.com`,
		`<user@example.com>`:                       `user@example.com`,
		`<user@[10.0.0.1]>`:                        `user@[10.0.0.1]`,
		`<hořejšek@mail.com>`:                      `hořejšek@mail.com`,
		`<@foo.com:foo@bar.com>`:                   `foo@bar.com`,
		`<,@foo.com:foo@bar.com>`:                  `foo@bar.com`,
		`<  @foo.com:foo@bar.com>`:                 `foo@bar.com`,
		`<@foo.com,@bar.bar:foo@bar.com>`:          `foo@bar.com`,
		"<@foo.com,\r\n @bar.bar:foo@bar.com>":     `foo@bar.com`,
	}

	for i, e := range inputs {
		t.Run(i, func(t *testing.T) {
			p := newTestRFCParser(i)
			v, err := parseAngleAddr(p)
			require.NoError(t, err)
			require.Equal(t, e, v)
		})
	}
}