1// Copyright 2017 syzkaller project authors. All rights reserved.
2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4package email
5
6import (
7	"fmt"
8	"testing"
9)
10
11func TestFormReply(t *testing.T) {
12	for i, test := range formReplyTests {
13		t.Run(fmt.Sprint(i), func(t *testing.T) {
14			result := FormReply(test.email, test.reply)
15			if test.result != result {
16				t.Logf("expect:\n%s", test.result)
17				t.Logf("got:\n%s", result)
18				t.Fail()
19			}
20		})
21	}
22}
23
24var formReplyTests = []struct {
25	email  string
26	reply  string
27	result string
28}{
29	{
30		email: `line1
31line2
32#syz foo
33line3
34`,
35		reply: "this is reply",
36		result: `> line1
37> line2
38> #syz foo
39
40this is reply
41
42> line3
43`,
44	},
45	{
46		email: `> line1
47> line2
48#syz foo
49line3
50`,
51		reply: "this is reply\n",
52		result: `>> line1
53>> line2
54> #syz foo
55
56this is reply
57
58> line3
59`,
60	},
61	{
62		email: `line1
63line2
64#syz foo`,
65		reply: "this is reply 1\nthis is reply 2",
66		result: `> line1
67> line2
68> #syz foo
69
70this is reply 1
71this is reply 2
72
73`,
74	},
75	{
76		email: `line1
77line2
78`,
79		reply: "this is reply",
80		result: `> line1
81> line2
82
83this is reply
84
85`,
86	},
87}
88