]> Sergey Matveev's repositories - public-inbox.git/blob - t/view.t
view: API cleanup, remove "as_" prefix
[public-inbox.git] / t / view.t
1 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 use strict;
4 use warnings;
5 use Test::More;
6 use Email::MIME;
7 use PublicInbox::View;
8
9 # plain text
10 {
11         my $body = <<EOF;
12 So and so wrote:
13 > keep this inline
14
15 OK
16
17 > Long and wordy reply goes here and it is split across multiple lines.
18 > We generate links to a separate full page where quoted-text is inline.
19 > This is
20 >
21 > Currently 5 lines
22 > See MAX_INLINE_QUOTED
23
24 hello world
25 EOF
26         my $s = Email::Simple->create(
27                 header => [
28                         From => 'a@example.com',
29                         To => 'b@example.com',
30                         'Content-Type' => 'text/plain',
31                         'Message-ID' => '<hello@example.com>',
32                         Subject => 'this is a subject',
33                 ],
34                 body => $body,
35         );
36         $s = Email::MIME->new($s->as_string);
37         my $html = PublicInbox::View->msg_html($s);
38
39         # ghetto tests
40         like($html, qr!<a href="\.\./m/hello%40!s, "MID link present");
41         like($html, qr/hello world\b/, "body present");
42         like($html, qr/&gt; keep this inline/, "short quoted text is inline");
43         like($html, qr/<a name=[^>]+>&gt; Long and wordy/,
44                 "long quoted text is anchored");
45
46         # short page
47         my $pfx = "http://example.com/test/f";
48         my $short = PublicInbox::View->msg_html($s, $pfx);
49         like($short, qr!<a href="hello%40!s, "MID link present");
50         like($short, qr/\n&gt; keep this inline/,
51                 "short quoted text is inline");
52         like($short, qr/<a href="\Q$pfx\E#[^>]+>Long and wordy/,
53                 "long quoted text is made into a link");
54         ok(length($short) < length($html), "short page is shorter");
55 }
56
57 # multipart crap
58 {
59         my $parts = [
60                 Email::MIME->create(
61                         attributes => { content_type => 'text/plain', },
62                         body => 'hi',
63                 ),
64                 Email::MIME->create(
65                         attributes => { content_type => 'text/plain', },
66                         body => 'bye',
67                 )
68         ];
69         my $mime = Email::MIME->create(
70                 header_str => [
71                         From => 'a@example.com',
72                         Subject => 'blargh',
73                         'Message-ID' => '<blah@example.com>',
74                         'In-Reply-To' => '<irp@example.com>',
75                         ],
76                 parts => $parts,
77         );
78
79         my $html = PublicInbox::View->msg_html($mime);
80         like($html, qr/hi\n-+ part #2 -+\nbye\n/, "multipart split");
81 }
82
83 # multipart email with attached patch
84 {
85         my $parts = [
86                 Email::MIME->create(
87                         attributes => { content_type => 'text/plain', },
88                         body => 'hi, see attached patch',
89                 ),
90                 Email::MIME->create(
91                         attributes => {
92                                 content_type => 'text/plain',
93                                 filename => "foo.patch",
94                         },
95                         body => "--- a/file\n+++ b/file\n" .
96                                 "@@ -49, 7 +49,34 @@\n",
97                 ),
98         ];
99         my $mime = Email::MIME->create(
100                 header_str => [
101                         From => 'a@example.com',
102                         Subject => '[PATCH] asdf',
103                         'Message-ID' => '<patch@example.com>',
104                         ],
105                 parts => $parts,
106         );
107
108         my $html = PublicInbox::View->msg_html($mime);
109         like($html, qr!see attached patch\n-+ foo\.patch -+\n--- a/file\n!,
110                 "parts split with filename");
111 }
112
113 done_testing();