-
Notifications
You must be signed in to change notification settings - Fork 26
/
501-data-json.t
78 lines (61 loc) · 3.04 KB
/
501-data-json.t
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use strict;
use Test::More;
use lib qw(./lib ./blib/lib);
my $PackageName = 'Sisimai::Data::JSON';
my $MethodNames = {
'class' => ['dump'],
'object' => [],
};
use_ok $PackageName;
can_ok $PackageName, @{ $MethodNames->{'class'} };
MAKE_TEST: {
use Sisimai::Data;
use Sisimai::Mail;
use Sisimai::Message;
use JSON;
is $PackageName->dump('json'), undef;
my $file = './set-of-emails/maildir/bsd/lhost-sendmail-02.eml';
my $mail = Sisimai::Mail->new($file);
my $mesg = undef;
my $data = undef;
my $list = undef;
my $json = undef;
my $perl = undef;
while( my $r = $mail->read ){
$mesg = Sisimai::Message->new('data' => $r);
$data = Sisimai::Data->make('data' => $mesg, 'origin' => $mail->mail->path);
isa_ok $data, 'ARRAY';
for my $e ( @$data ) {
$json = $e->dump('json');
ok length $json, '->dump()';
utf8::encode $json if utf8::is_utf8 $json;
$perl = JSON::from_json($json, { 'utf8' => 1 });
isa_ok $perl, 'HASH';
is $e->token, $perl->{'token'}, 'token = '.$e->token;
is $e->lhost, $perl->{'lhost'}, 'lhost = '.$e->lhost;
is $e->rhost, $perl->{'rhost'}, 'rhost = '.$e->rhost;
is $e->alias, $perl->{'alias'}, 'alias = '.$e->alias;
is $e->listid, $perl->{'listid'}, 'listid = '.$e->listid;
is $e->reason, $perl->{'reason'}, 'reason = '.$e->reason;
is $e->subject, $perl->{'subject'};
is $e->timestamp->epoch, $perl->{'timestamp'}, 'timestamp->epoch = '.$e->timestamp->epoch;
is $e->replycode, $perl->{'replycode'};
is $e->addresser->address, $perl->{'addresser'}, 'addresser->address = '.$e->addresser->address;
is $e->addresser->host, $perl->{'senderdomain'}, 'senderdomain = '.$e->senderdomain;
is $e->recipient->address, $perl->{'recipient'}, 'recipient->address = '.$e->recipient->address;
is $e->recipient->host, $perl->{'destination'}, 'destination = '.$e->destination;
is $e->messageid, $perl->{'messageid'}, 'messageid = '.$e->messageid;
is $e->smtpagent, $perl->{'smtpagent'}, 'smtpagent = '.$e->smtpagent;
is $e->softbounce, $perl->{'softbounce'}, 'softbouce = '.$e->softbounce;
is $e->smtpcommand, $perl->{'smtpcommand'}, 'smtpcommand = '.$e->smtpcommand;
is $e->diagnosticcode, $perl->{'diagnosticcode'}, 'diagnosticcode = '.$e->diagnosticcode;
is $e->diagnostictype, $perl->{'diagnostictype'}, 'diagnostictype = '.$e->diagnostictype;
is $e->deliverystatus, $perl->{'deliverystatus'}, 'deliverystatus = '.$e->deliverystatus;
is $e->timezoneoffset, $perl->{'timezoneoffset'}, 'timezoneoffset = '.$e->timezoneoffset;
is $e->feedbacktype, $perl->{'feedbacktype'}, 'feedbacktype = '.$e->feedbacktype;
is $e->action, $perl->{'action'}, 'action = '.$e->action;
is $e->origin, $perl->{'origin'}, 'origin = '.$e->origin;
}
}
}
done_testing;