aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/email/reply_test.go
blob: 8ceb08f98b511852dcdba857016de7d0b5e2eecb (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package email

import (
	"fmt"
	"testing"
)

func TestFormReply(t *testing.T) {
	for i, test := range formReplyTests {
		t.Run(fmt.Sprint(i), func(t *testing.T) {
			result := FormReply(test.email, test.reply)
			if test.result != result {
				t.Logf("expect:\n%s", test.result)
				t.Logf("got:\n%s", result)
				t.Fail()
			}
		})
	}
}

var formReplyTests = []struct {
	email  *Email
	reply  string
	result string
}{
	{
		email: &Email{
			Body: `line1
line2
#syz foo
line3
`},
		reply: "this is reply",
		result: `> line1
> line2
> #syz foo

this is reply

> line3
`,
	},
	{
		email: &Email{
			Body: `
#syz-fix
line2
`},
		reply: "this is reply",
		result: `>
> #syz-fix

this is reply

> line2
`,
	},
	{
		email: &Email{
			Body: `
#syz: fix
line2
`},
		reply: "this is reply",
		result: `>
> #syz: fix

this is reply

> line2
`,
	},
	{
		email: &Email{
			Body: `> line1
> line2
#syz foo
line3
`},
		reply: "this is reply\n",
		result: `>> line1
>> line2
> #syz foo

this is reply

> line3
`,
	},
	{
		email: &Email{
			Body: `line1
line2
#syz foo`},
		reply: "this is reply 1\nthis is reply 2",
		result: `> line1
> line2
> #syz foo

this is reply 1
this is reply 2

`,
	},
	{
		email: &Email{
			Body: `line1
line2
`},
		reply: "this is reply",
		result: `> line1
> line2

this is reply

`,
	},
	{
		email: &Email{
			Body: `line1
#syz foo
line2
#syz bar`,
			Commands: []*SingleCommand{
				{},
				{},
			},
		},
		reply: "this is reply 1\nthis is reply 2",
		result: `> line1
> #syz foo
> line2
> #syz bar

this is reply 1
this is reply 2

`,
	},
}