]> Sergey Matveev's repositories - public-inbox.git/blob - t/view.t
view: add view module to be used for rendering HTML
[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 $s = Email::Simple->create(
12                 header => [
13                         From => 'a@example.com',
14                         To => 'b@example.com',
15                         'Content-Type' => 'text/plain',
16                         'Message-ID' => '<hello@example.com>',
17                         Subject => 'this is a subject',
18                 ],
19                 body => "hello world\n",
20         );
21         $s = Email::MIME->new($s->as_string);
22         my $html = PublicInbox::View->as_html($s);
23
24         # ghetto
25         like($html, qr/<a href="hello%40/s, "MID link present");
26         like($html, qr/hello world\b/, "body present");
27 }
28
29 # multipart crap
30 {
31         my $parts = [
32                 Email::MIME->create(
33                         attributes => { content_type => 'text/plain', },
34                         body => 'hi',
35                 ),
36                 Email::MIME->create(
37                         attributes => { content_type => 'text/plain', },
38                         body => 'bye',
39                 )
40         ];
41         my $mime = Email::MIME->create(
42                 header_str => [
43                         From => 'a@example.com',
44                         Subject => 'blargh',
45                         'Message-ID' => '<blah@xeample.com>',
46                         'In-Reply-To' => '<irp@xeample.com>',
47                         ],
48                 parts => $parts,
49         );
50
51         my $html = PublicInbox::View->as_html($mime);
52         print $html;
53 }
54
55 done_testing();