File: 03-search-has.t

package info (click to toggle)
libmail-authenticationresults-perl 2.20230112-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 364 kB
  • sloc: perl: 2,803; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 1,242 bytes parent folder | download | duplicates (3)
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
#!perl
use 5.008;
use strict;
use warnings FATAL => 'all';
use lib 't';
use Test::More;
use Test::Exception;

use lib 'lib';
use Mail::AuthenticationResults::Parser;

my $Parsed = Mail::AuthenticationResults::Parser->new()->parse( 'test.example.com;one=two three=four (comment) five=six' );

my $Found;

$Found = $Parsed->search({ 'isa' => 'entry', 'key' => 'one', 'has' => [ { 'isa' => 'subentry', 'key' => 'three' } ] });
is( $Found->as_string(), 'one=two three=four (comment) five=six', 'Found subentry' );

$Found = $Parsed->search({ 'isa' => 'entry', 'key' => 'one', 'has' => [ { 'isa' => 'subentry', 'key' => 'twenty' } ] });
is( scalar @{$Found->children() }, 0, 'Did not find missing subentry' );

$Found = $Parsed->search({ 'isa' => 'entry', 'key' => 'one', 'has' => [ { 'isa' => 'subentry', 'key' => 'twenty' }, { 'isa' => 'subentry', 'key' => 'three' } ] });
is( scalar @{$Found->children() }, 0, 'Did not find missing subentry in multi search' );

$Found = $Parsed->search({ 'isa' => 'entry', 'key' => 'one', 'has' => [ { 'isa' => 'subentry', 'key' => 'three', 'has' => [ { 'value' => 'four' } ] } ] });
is( $Found->as_string(), 'one=two three=four (comment) five=six', 'Found subentry with recursive search' );

done_testing();