1package message
2
3import (
4 "testing"
5)
6
7func TestThreadSubject(t *testing.T) {
8 check := func(s, expBase string, expResp bool) {
9 t.Helper()
10
11 base, isResp := ThreadSubject(s, false)
12 if base != expBase || isResp != expResp {
13 t.Fatalf("got base %q, resp %v, expected %q %v for subject %q", base, isResp, expBase, expResp, s)
14 }
15 }
16
17 check("test", "test", false)
18 check(" a b\tc\r\n d\t", "a b c d", false)
19 check("test (fwd) (fwd) ", "test", true)
20 check("re: test", "test", true)
21 check("fw: test", "test", true)
22 check("fwd: test", "test", true)
23 check("fwd [tag] Test", "fwd [tag] test", false)
24 check("[list] re: a b c\t", "a b c", true)
25 check("[list] fw: a b c", "a b c", true)
26 check("[tag1][tag2] [tag3]\t re: a b c", "a b c", true)
27 check("[tag1][tag2] [tag3]\t re: a \u0000b c", "", true)
28 check("[list] fw:[tag] a b c", "a b c", true)
29 check("[list] re: [list] fwd: a b c\t", "a b c", true)
30 check("[fwd: a b c]", "a b c", true)
31 check("[fwd: [fwd: a b c]]", "a b c", true)
32 check("[fwd: [list] re: a b c]", "a b c", true)
33 check("[nonlist]", "[nonlist]", false)
34 check("fwd [list]:", "", true)
35}
36