File Coverage

blib/lib/Test2/Tools/DOM.pm
Criterion Covered Total %
statement 71 71 100.0
branch 5 8 62.5
condition n/a
subroutine 20 20 100.0
pod 9 9 100.0
total 105 108 97.2


line stmt bran cond sub pod time code
1             # ABSTRACT: Tools to test HTML/XML-based DOM representations
2             package Test2::Tools::DOM;
3              
4 2     2   437749 use v5.20;
  2         21  
5 2     2   10 use warnings;
  2         2  
  2         62  
6 2     2   866 use experimental qw( lexical_subs signatures );
  2         5911  
  2         12  
7              
8 2     2   352 use Carp ();
  2         4  
  2         26  
9 2     2   10 use Test2::API ();
  2         3  
  2         38  
10 2     2   10 use Test2::Compare ();
  2         3  
  2         25  
11 2     2   10 use Test2::Compare::Wildcard ();
  2         2  
  2         44  
12 2     2   838 use Test2::Tools::DOM::Check ();
  2         5  
  2         74  
13              
14             our $VERSION = '0.002';
15              
16 2     2   12 use Exporter 'import';
  2         3  
  2         984  
17             our @EXPORT = qw(
18             all_text
19             at
20             attr
21             content
22             children
23             dom
24             find
25             tag
26             text
27             );
28              
29             sub dom :prototype(&) {
30 33     33 1 56484 Test2::Compare::build( 'Test2::Tools::DOM::Check', @_ );
31             }
32              
33 49     49   63 my sub call ( $name, $args, $expect ) {
  49         55  
  49         61  
  49         54  
  49         53  
34 49 50       94 Carp::croak 'Missing method name' unless $name;
35              
36 49 50       90 my $build = Test2::Compare::get_build
37             or Carp::croak 'No current build!';
38              
39 49 50       210 Carp::croak "'$build' is not a Test2::Tools::DOM::Check"
40             unless ref $build eq 'Test2::Tools::DOM::Check';
41              
42 49         105 my @caller = caller;
43 49         160 $build->add_call(
44             $name => $args,
45             Test2::Compare::Wildcard->new(
46             expect => $expect,
47             file => $caller[1],
48             lines => [ $caller[2] ],
49             ),
50             );
51             }
52              
53             # Calls with either only a check, or a key and a check
54 20     20   27 my sub multi ( $method, $want, $check = undef ) {
  20         27  
  20         28  
  20         27  
  20         22  
55 20 100       56 $check
56             ? call( $method => [ $want ] => $check )
57             : call( $method => [ ] => $want )
58             }
59              
60 1     1 1 19 sub all_text ( $check ) { call all_text => [ ] => $check }
  1         2  
  1         2  
  1         3  
61 10     10 1 331 sub at ( $want, $check ) { call at => [ $want ] => $check }
  10         14  
  10         14  
  10         12  
  10         22  
62 1     1 1 20 sub content ( $check ) { call content => [ ] => $check }
  1         2  
  1         3  
  1         3  
63 3     3 1 272 sub find ( $want, $check ) { call find => [ $want ] => $check }
  3         6  
  3         7  
  3         4  
  3         9  
64 12     12 1 204 sub tag ( $check ) { call tag => [ ] => $check }
  12         20  
  12         17  
  12         27  
65 2     2 1 39 sub text ( $check ) { call text => [ ] => $check }
  2         4  
  2         4  
  2         8  
66              
67 15     15 1 760 sub attr { multi attr => @_ }
68 5     5 1 414 sub children { multi children => @_ }
69              
70             1;