Home | History | Annotate | Download | only in email
      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 
      4 package email
      5 
      6 import (
      7 	"fmt"
      8 	"testing"
      9 )
     10 
     11 func 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 
     24 var formReplyTests = []struct {
     25 	email  string
     26 	reply  string
     27 	result string
     28 }{
     29 	{
     30 		email: `line1
     31 line2
     32 #syz foo
     33 line3
     34 `,
     35 		reply: "this is reply",
     36 		result: `> line1
     37 > line2
     38 > #syz foo
     39 
     40 this is reply
     41 
     42 > line3
     43 `,
     44 	},
     45 	{
     46 		email: `> line1
     47 > line2
     48 #syz foo
     49 line3
     50 `,
     51 		reply: "this is reply\n",
     52 		result: `>> line1
     53 >> line2
     54 > #syz foo
     55 
     56 this is reply
     57 
     58 > line3
     59 `,
     60 	},
     61 	{
     62 		email: `line1
     63 line2
     64 #syz foo`,
     65 		reply: "this is reply 1\nthis is reply 2",
     66 		result: `> line1
     67 > line2
     68 > #syz foo
     69 
     70 this is reply 1
     71 this is reply 2
     72 
     73 `,
     74 	},
     75 	{
     76 		email: `line1
     77 line2
     78 `,
     79 		reply: "this is reply",
     80 		result: `> line1
     81 > line2
     82 
     83 this is reply
     84 
     85 `,
     86 	},
     87 }
     88