]> Sergey Matveev's repositories - public-inbox.git/blob - t/mime.t
mime: avoid SUPER usage in Email::MIME subclass
[public-inbox.git] / t / mime.t
1 # Copyright (C) 2017 all contributors <meta@public-inbox.org>
2 # This library is free software; you can redistribute it and/or modify
3 # it under the same terms as Perl itself.
4 # Artistic or GPL-1+ <https://www.gnu.org/licenses/gpl-1.0.txt>
5 use strict;
6 use warnings;
7 use Test::More;
8 use_ok 'PublicInbox::MIME';
9 use PublicInbox::MsgIter;
10
11 my $msg = PublicInbox::MIME->new(
12 'From:   Richard Hansen <hansenr@google.com>
13 To:     git@vger.kernel.org
14 Cc:     Richard Hansen <hansenr@google.com>
15 Subject: [PATCH 0/2] minor diff orderfile documentation improvements
16 Date:   Mon,  9 Jan 2017 19:40:29 -0500
17 Message-Id: <20170110004031.57985-1-hansenr@google.com>
18 X-Mailer: git-send-email 2.11.0.390.gc69c2f50cf-goog
19 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256;
20         boundary="94eb2c0bc864b76ba30545b2bca9"
21
22 --94eb2c0bc864b76ba30545b2bca9
23
24 Richard Hansen (2):
25   diff: document behavior of relative diff.orderFile
26   diff: document the pattern format for diff.orderFile
27
28  Documentation/diff-config.txt  | 5 ++++-
29  Documentation/diff-options.txt | 3 ++-
30  2 files changed, 6 insertions(+), 2 deletions(-)
31
32
33 --94eb2c0bc864b76ba30545b2bca9
34 Content-Type: application/pkcs7-signature; name="smime.p7s"
35 Content-Transfer-Encoding: base64
36 Content-Disposition: attachment; filename="smime.p7s"
37 Content-Description: (truncated) S/MIME Cryptographic Signature
38
39 dkTlB69771K2eXK4LcHSH/2LqX+VYa3K44vrx1ruzjXdNWzIpKBy0weFNiwnJCGofvCysM2RCSI1
40 --94eb2c0bc864b76ba30545b2bca9--
41
42 ');
43
44 my @parts = $msg->parts;
45 my $exp = 'Richard Hansen (2):
46   diff: document behavior of relative diff.orderFile
47   diff: document the pattern format for diff.orderFile
48
49  Documentation/diff-config.txt  | 5 ++++-
50  Documentation/diff-options.txt | 3 ++-
51  2 files changed, 6 insertions(+), 2 deletions(-)
52
53 ';
54
55 ok($msg->isa('Email::MIME'), 'compatible with Email::MIME');
56 is($parts[0]->body, $exp, 'body matches expected');
57
58
59 my $raw = q^Date:   Wed, 18 Jan 2017 13:28:32 -0500
60 From:   Santiago Torres <santiago@nyu.edu>
61 To:     Junio C Hamano <gitster@pobox.com>
62 Cc:     git@vger.kernel.org, peff@peff.net, sunshine@sunshineco.com,
63         walters@verbum.org, Lukas Puehringer <luk.puehringer@gmail.com>
64 Subject: Re: [PATCH v6 4/6] builtin/tag: add --format argument for tag -v
65 Message-ID: <20170118182831.pkhqu2np3bh2puei@LykOS.localdomain>
66 References: <20170117233723.23897-1-santiago@nyu.edu>
67  <20170117233723.23897-5-santiago@nyu.edu>
68  <xmqqmvepb4oj.fsf@gitster.mtv.corp.google.com>
69  <xmqqh94wb4y0.fsf@gitster.mtv.corp.google.com>
70 MIME-Version: 1.0
71 Content-Type: multipart/signed; micalg=pgp-sha256;
72         protocol="application/pgp-signature"; boundary="r24xguofrazenjwe"
73 Content-Disposition: inline
74 In-Reply-To: <xmqqh94wb4y0.fsf@gitster.mtv.corp.google.com>
75
76
77 --r24xguofrazenjwe
78 Content-Type: text/plain; charset=us-ascii
79 Content-Disposition: inline
80 Content-Transfer-Encoding: quoted-printable
81
82 your tree directly?=20
83
84 --r24xguofrazenjwe
85 Content-Type: application/pgp-signature; name="signature.asc"
86
87 -----BEGIN PGP SIGNATURE-----
88
89 =7wIb
90 -----END PGP SIGNATURE-----
91
92 --r24xguofrazenjwe--
93
94 ^;
95
96 $msg = PublicInbox::MIME->new($raw);
97 my $nr = 0;
98 msg_iter($msg, sub {
99         my ($part, $level, @ex) = @{$_[0]};
100         if ($ex[0] == 1) {
101                 is($part->body_str, "your tree directly? \r\n", 'body OK');
102         } elsif ($ex[0] == 2) {
103                 is($part->body, "-----BEGIN PGP SIGNATURE-----\n\n" .
104                                 "=7wIb\n" .
105                                 "-----END PGP SIGNATURE-----\n",
106                         'sig "matches"');
107         } else {
108                 fail "unexpected part\n";
109         }
110         $nr++;
111 });
112
113 is($nr, 2, 'got 2 parts');
114 is($msg->as_string, $raw,
115         'stringified sufficiently close to original');
116
117 done_testing();