File Coverage

blib/lib/Test2/Tools/DOM.pm
Criterion Covered Total %
statement 69 69 100.0
branch 8 8 100.0
condition n/a
subroutine 21 21 100.0
pod 10 10 100.0
total 108 108 100.0


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   471746 use v5.20;
  2         55  
5 2     2   18 use warnings;
  2         6  
  2         138  
6 2     2   2424 use experimental qw( lexical_subs signatures );
  2         8693  
  2         14  
7              
8 2     2   456 use Carp ();
  2         3  
  2         66  
9 2     2   12 use Test2::API ();
  2         4  
  2         42  
10 2     2   9 use Test2::Compare ();
  2         4  
  2         30  
11 2     2   9 use Test2::Compare::Wildcard ();
  2         6  
  2         39  
12 2     2   1166 use Test2::Tools::DOM::Check ();
  2         11  
  2         100  
13              
14             our $VERSION = '0.100';
15              
16 2     2   26 use Exporter 'import';
  2         4  
  2         1426  
17             our @EXPORT = qw(
18             all_text
19             at
20             attr
21             content
22             children
23             dom
24             find
25             tag
26             text
27             val
28             );
29              
30             sub dom :prototype(&) {
31 44     44 1 867705 Test2::Compare::build( 'Test2::Tools::DOM::Check', @_ );
32             }
33              
34 60     60   107 my sub call ( $name, $args, $expect ) {
  60         105  
  60         87  
  60         96  
  60         82  
35 60 100       161 my $build = Test2::Compare::get_build
36             or Carp::croak "'$name' cannot be called in a context with no test build";
37              
38 59 100       578 Carp::croak "'$name' is not supported in a '$build' build"
39             unless ref $build eq 'Test2::Tools::DOM::Check';
40              
41 58         171 my @caller = caller;
42 58 100       375 $build->add_call(
43             @$args ? [ $name => @$args ] : $name,
44             Test2::Compare::Wildcard->new(
45             expect => $expect,
46             file => $caller[1],
47             lines => [ $caller[2] ],
48             ),
49             $name,
50             'scalar',
51             );
52             }
53              
54             # Calls with either only a check, or a key and a check
55             my sub multi {
56 24 100   24   123 @_ > 2
57             ? call( $_[0] => [ $_[1] ] => $_[2] )
58             : call( $_[0] => [ ] => $_[1] )
59             }
60              
61 1     1 1 25 sub all_text ( $check ) { call all_text => [ ] => $check }
  1         4  
  1         2  
  1         4  
62 10     10 1 477 sub at ( $want, $check ) { call at => [ $want ] => $check }
  10         22  
  10         17  
  10         38  
  10         40  
63 1     1 1 26 sub content ( $check ) { call content => [ ] => $check }
  1         2  
  1         3  
  1         3  
64 3     3 1 396 sub find ( $want, $check ) { call find => [ $want ] => $check }
  3         7  
  3         8  
  3         7  
  3         12  
65 14     14 1 15915 sub tag ( $check ) { call tag => [ ] => $check }
  14         29  
  14         23  
  14         44  
66 6     6 1 146 sub text ( $check ) { call text => [ ] => $check }
  6         11  
  6         12  
  6         20  
67 1     1 1 7 sub val ( $check ) { call val => [ ] => $check }
  1         2  
  1         3  
  1         4  
68              
69 18     18 1 1227 sub attr { multi attr => @_ }
70 6     6 1 655 sub children { multi children => @_ }
71              
72             1;