1#!perl
2use 5.008;
3use strict;
4use warnings FATAL => 'all';
5use lib 't';
6use Test::More;
7use Test::Exception;
8
9use lib 'lib';
10use Mail::AuthenticationResults::Parser;
11
12my $Parsed;
13
14lives_ok( sub{ $Parsed = Mail::AuthenticationResults::Parser->new()->parse( 'example.com;none' ) }, 'Simple none parses' );
15is( $Parsed->as_string, "example.com; none", 'as string is as expected' );
16is( scalar @{ $Parsed->children() }, 0, 'no children' );
17
18lives_ok( sub{ $Parsed = Mail::AuthenticationResults::Parser->new()->parse( 'example.com;' ) }, 'Missing none parses' );
19is( $Parsed->as_string, "example.com; none", 'as string is as expected' );
20is( scalar @{ $Parsed->children() }, 0, 'no children' );
21
22lives_ok( sub{ $Parsed = Mail::AuthenticationResults::Parser->new()->parse( 'example.com; (Nothing here) none' ) }, 'Commented none parses' );
23is( $Parsed->as_string, "example.com; (Nothing here) none", 'as string is as expected' );
24is( scalar @{ $Parsed->children() }, 1, '1 child' );
25
26# The following is against RFC, but we parse it anyway.
27lives_ok( sub{ $Parsed = Mail::AuthenticationResults::Parser->new()->parse( 'example.com; none (Nothing here)' ) }, 'Commented none wrong way around parses' );
28is( $Parsed->as_string, "example.com; (Nothing here) none", 'as string is as expected' );
29is( scalar @{ $Parsed->children() }, 1, '1 child' );
30
31dies_ok( sub{ $Parsed = Mail::AuthenticationResults::Parser->new()->parse( 'example.com; none dkim=pass' ) }, 'none with subentry dies' );
32dies_ok( sub{ $Parsed = Mail::AuthenticationResults::Parser->new()->parse( 'example.com; none none' ) }, 'double none dies' );
33
34done_testing();
35
36