File: base_subject_test.go

package info (click to toggle)
golang-github-emersion-go-imap-sortthread 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 116 kB
  • sloc: makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,607 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
53
54
55
56
57
58
59
60
61
62
63
package sortthread

import "testing"

var baseSubjectTests = []struct {
	name       string
	subject    string
	expected   string
	isReplyFwd bool
}{
	{
		name:       "simple",
		subject:    "No Replacement",
		expected:   "No Replacement",
		isReplyFwd: false,
	},
	{
		name:       "reply",
		subject:    "Re: [ocf/puppet] Fix kerberos not booting up correctly [needs testing] (#781)",
		expected:   "[ocf/puppet] Fix kerberos not booting up correctly [needs testing] (#781)",
		isReplyFwd: true,
	},
	{
		name:       "forward",
		subject:    "Fwd: waifus",
		expected:   "waifus",
		isReplyFwd: true,
	},
	{
		name:       "forward_reply",
		subject:    "Fwd: Re: ugh",
		expected:   "ugh",
		isReplyFwd: true,
	},
	{
		name:       "forward_header_simple",
		subject:    "[FWD: simple [extraction]]",
		expected:   "simple [extraction]",
		isReplyFwd: true,
	},
	{
		name:       "foward_header_nested",
		subject:    "Re: [fwd: Re: [OCF] Service update during PG&E outage]",
		expected:   "[OCF] Service update during PG&E outage",
		isReplyFwd: true,
	},
}

func TestBaseSubject(t *testing.T) {
	for _, test := range baseSubjectTests {
		t.Run(test.name, func(t *testing.T) {
			baseSubject, isReplyFwd := GetBaseSubject(test.subject)
			if baseSubject != test.expected {
				t.Errorf("Got %s, Expected %s.", baseSubject, test.expected)
			}
			if !isReplyFwd && test.isReplyFwd {
				t.Errorf("Subject %s should be flagged as reply or forward", test.subject)
			} else if isReplyFwd && !test.isReplyFwd {
				t.Errorf("Subject %s was incorrectly flagged as reply or forward", test.subject)
			}
		})
	}
}