File Coverage

inc/My/Module/Test.pm
Criterion Covered Total %
statement 255 284 89.7
branch 91 126 72.2
condition 33 68 48.5
subroutine 40 41 97.5
pod 21 23 91.3
total 440 542 81.1


line stmt bran cond sub pod time code
1             package My::Module::Test;
2              
3 5     5   381474 use strict;
  5         8  
  5         148  
4 5     5   30 use warnings;
  5         16  
  5         216  
5              
6 5     5   18 use Exporter;
  5         7  
  5         297  
7              
8             our @ISA = ( qw{ Exporter } );
9              
10 5     5   2357 use PPIx::Regexp;
  5         15  
  5         196  
11 5     5   26 use PPIx::Regexp::Constant qw{ INFINITY };
  5         8  
  5         219  
12 5     5   2362 use PPIx::Regexp::Dumper;
  5         12  
  5         170  
13 5     5   27 use PPIx::Regexp::Element;
  5         7  
  5         125  
14 5     5   14 use PPIx::Regexp::Tokenizer;
  5         8  
  5         90  
15 5     5   16 use PPIx::Regexp::Util qw{ __choose_tokenizer_class __instance };
  5         7  
  5         255  
16 5     5   21 use Scalar::Util qw{ looks_like_number refaddr };
  5         7  
  5         182  
17 5     5   1955 use Test::More 0.88;
  5         237317  
  5         34  
18              
19             our $VERSION = '0.091';
20              
21 5     5   1452 use constant ARRAY_REF => ref [];
  5         7  
  5         16017  
22              
23             our @EXPORT_OK = qw{
24             cache_count
25             choose
26             klass
27             cmp_ok
28             content
29             count
30             diag
31             different
32             done_testing
33             dump_result
34             equals
35             error
36             fail
37             false
38             finis
39             format_want
40             invocant
41             is
42             navigate
43             note
44             ok
45             parse
46             pass
47             plan
48             ppi
49             raw_width
50             result
51             replace_characters
52             skip
53             tokenize
54             true
55             value
56             width
57             INFINITY
58             };
59              
60             our @EXPORT = @EXPORT_OK; ## no critic (ProhibitAutomaticExportation)
61              
62             push @EXPORT_OK, qw{ __quote };
63              
64             my (
65             $initial_class, # For static methods; set by parse() or tokenize()
66             $kind, # of thing; set by parse() or tokenize()
67             $nav, # Navigation used to get to current object, as a
68             # string.
69             $obj, # Current object:
70             # PPIx::Regexp::Tokenizer if set by tokenize(),
71             # PPIx::Regexp if set by parse(), or
72             # PPIx::Regexp::Element if set by navigate().
73             $parse, # Result of parse:
74             # array ref if set by tokenize(), or
75             # PPIx::Regexp object if set by parse()
76             %replace_characters, # Troublesome characters replaced in output
77             # before testing
78             $result, # Operation result.
79             );
80              
81             sub cache_count {
82 8     8 1 622 my ( $expect ) = @_;
83 8 100       25 defined $expect or $expect = 0;
84 8         12 $obj = undef;
85 8         13 $parse = undef;
86 8         21 _pause();
87 8         153 $result = PPIx::Regexp->__cache_size();
88             # cperl does not seem to like goto &xxx; it throws a deep recursion
89             # error if you do it enough times.
90 8         55 local $Test::Builder::Level = $Test::Builder::Level + 1;
91 8         96 return is( $result, $expect,
92             "Should be $expect leftover cache contents" );
93             }
94              
95             sub choose {
96 4710     4710 1 3030109 my @args = @_;
97 4710         9131 $obj = $parse;
98 4710         9861 return navigate( @args );
99             }
100              
101             sub klass {
102 4403     4403 1 165772 my ( $class ) = @_;
103 4403   66     9912 $result = ref $obj || $obj;
104             # cperl does not seem to like goto &xxx; it throws a deep recursion
105             # error if you do it enough times.
106 4403         6246 local $Test::Builder::Level = $Test::Builder::Level + 1;
107 4403 100       6199 if ( defined $class ) {
108 4341 50       10810 my $rslt = isa_ok( $obj, $class )
109             or diag " Instead, $kind $nav isa $result";
110 4341         1417665 return $rslt;
111             } else {
112 62   50     393 return is( ref $obj || undef, $class, "Class of $kind $nav" );
113             }
114             }
115              
116             sub content { ## no critic (RequireArgUnpacking)
117             # For some reason cperl seems to have no problem with this
118 3609     3609 1 35764 unshift @_, 'content';
119 3609         10486 goto &_method_result;
120             }
121              
122             sub count {
123 1392     1392 1 80836 my ( @args ) = @_;
124 1392         2080 my $expect = pop @args;
125             # cperl does not seem to like goto &xxx; it throws a deep recursion
126             # error if you do it enough times.
127 1392         2240 local $Test::Builder::Level = $Test::Builder::Level + 1;
128 1392 100       5927 if ( ARRAY_REF eq ref $parse ) {
    100          
    50          
129 203         278 $result = @{ $parse };
  203         341  
130 203         777 return is( $result, $expect, "Expect $expect tokens" );
131             } elsif ( ARRAY_REF eq ref $obj ) {
132 565         569 $result = @{ $obj };
  565         952  
133 565         1764 return is( $result, $expect, "Expect $expect tokens" );
134             } elsif ( $obj->can( 'children' ) ) {
135 624         1930 $result = $obj->children();
136 624         2171 return is( $result, $expect, "Expect $expect children" );
137             } else {
138 0         0 $result = $obj->can( 'children' );
139 0         0 return ok( $result, ref( $obj ) . "->can( 'children')" );
140             }
141             }
142              
143             sub different {
144 1     1 1 7 my @args = @_;
145 1 50       4 @args < 3 and unshift @args, $obj;
146 1         2 my ( $left, $right, $name ) = @args;
147             # cperl does not seem to like goto &xxx; it throws a deep recursion
148             # error if you do it enough times.
149 1         3 local $Test::Builder::Level = $Test::Builder::Level + 1;
150 1 50 33     10 if ( ! defined $left && ! defined $right ) {
    50 33        
    50 33        
    0 0        
    0 0        
151 0         0 return ok( undef, $name );
152             } elsif ( ! defined $left || ! defined $right ) {
153 0         0 return ok( 1, $name );
154             } elsif ( ref $left && ref $right ) {
155 1         5 return ok( refaddr( $left ) != refaddr( $right ), $name );
156             } elsif ( ref $left || ref $right ) {
157 0         0 return ok( 1, $name );
158             } elsif ( looks_like_number( $left ) && looks_like_number( $right ) ) {
159 0         0 return ok( $left != $right, $name );
160             } else {
161 0         0 return ok( $left ne $right, $name );
162             }
163             }
164              
165             sub dump_result {
166 5     5 1 1714 my ( $opt, @args ) = _parse_constructor_args( { test => 1 }, @_ );
167 5 50 0     11 if ( $opt->{test} ) {
    0          
    0          
    0          
168 5         14 my ( $expect, $name ) = splice @args, -2;
169 5         23 my $got = PPIx::Regexp::Dumper->new( $obj, @args )->string();
170             # cperl does not seem to like goto &xxx; it throws a deep
171             # recursion error if you do it enough times.
172 5         31 local $Test::Builder::Level = $Test::Builder::Level + 1;
173 5         17 return is( $got, $expect, $name );
174             } elsif ( __instance( $result, 'PPIx::Regexp::Tokenizer' ) ||
175             __instance( $result, 'PPIx::Regexp::Element' ) ) {
176 0         0 diag( PPIx::Regexp::Dumper->new( $obj, @args )->string() );
177 0         0 } elsif ( eval { require YAML; 1; } ) {
  0         0  
178 0         0 diag( "Result dump:\n", YAML::Dump( $result ) );
179 0         0 } elsif ( eval { require Data::Dumper; 1 } ) {
  0         0  
180 0         0 diag( "Result dump:\n", Data::Dumper::Dumper( $result ) );
181             } else {
182 0         0 diag( "Result dump unavailable.\n" );
183             }
184 0         0 return;
185             }
186              
187             sub equals {
188 19     19 1 64 my @args = @_;
189 19 100       39 @args < 3 and unshift @args, $obj;
190 19         23 my ( $left, $right, $name ) = @args;
191             # cperl does not seem to like goto &xxx; it throws a deep recursion
192             # error if you do it enough times.
193 19         24 local $Test::Builder::Level = $Test::Builder::Level + 1;
194 19 100 66     91 if ( ! defined $left && ! defined $right ) {
    50 33        
    50 33        
    0 0        
    0 0        
195 11         26 return ok( 1, $name );
196             } elsif ( ! defined $left || ! defined $right ) {
197 0         0 return ok( undef, $name );
198             } elsif ( ref $left && ref $right ) {
199 8         20 return ok( refaddr( $left ) == refaddr( $right ), $name );
200             } elsif ( ref $left || ref $right ) {
201 0         0 return ok( undef, $name );
202             } elsif ( looks_like_number( $left ) && looks_like_number( $right ) ) {
203 0         0 return ok( $left == $right, $name );
204             } else {
205 0         0 return ok( $left eq $right, $name );
206             }
207             }
208              
209             sub error { ## no critic (RequireArgUnpacking)
210 19     19 0 12510 unshift @_, 'error';
211 19         73 goto &_method_result;
212             }
213              
214             sub false {
215 52     52 1 21415 my ( $method, $args ) = @_;
216 52 100       157 ARRAY_REF eq ref $args
217             or $args = [ $args ];
218 52         82 my $class = ref $obj;
219             # cperl does not seem to like goto &xxx; it throws a deep recursion
220             # error if you do it enough times.
221 52         76 local $Test::Builder::Level = $Test::Builder::Level + 1;
222 52 50       226 if ( $obj->can( $method ) ) {
223 52         60 $result = $obj->$method( @{ $args } );
  52         165  
224 52         92 my $fmtd = _format_args( $args );
225 52         181 return ok( ! $result, "$class->$method$fmtd is false" );
226             } else {
227 0         0 $result = undef;
228 0         0 return ok( undef, "$class->$method() exists" );
229             }
230             }
231              
232             sub finis {
233 2     2 1 1257 $obj = $parse = $result = undef;
234 2         8 _pause();
235 2         34 $result = PPIx::Regexp::Element->__parent_keys();
236             # cperl does not seem to like goto &xxx; it throws a deep recursion
237             # error if you do it enough times.
238 2         10 local $Test::Builder::Level = $Test::Builder::Level + 1;
239 2         19 return is( $result, 0, 'Should be no leftover objects' );
240             }
241              
242             sub format_want {
243 1081     1081 1 1546 my ( $want ) = @_;
244 1081 100       1940 return _format_args( $want, bare => ref $want ? 0 : 1 );
245             }
246              
247             sub invocant {
248 0     0 1 0 return $obj;
249             }
250              
251             {
252              
253             my %array = map { $_ => 1 } qw{
254             children delimiters finish schildren start tokens type
255             };
256              
257             sub navigate {
258 4765     4765 1 31951 my @args = @_;
259 4765         5616 my $scalar = 1;
260             @args > 1
261             and ARRAY_REF eq ref $args[-1]
262 601         3072 and @{ $args[-1] } == 0
263 4765 100 100     19916 and $array{$args[-2]}
      100        
      100        
264             and $scalar = 0;
265 4765         6035 my @nav = ();
266 4765         8446 while ( @args ) {
267 8483 100       18398 if ( __instance( $args[0], 'PPIx::Regexp::Element' ) ) {
    100          
268 9         16 $obj = shift @args;
269             } elsif ( ARRAY_REF eq ref $obj ) {
270 1571         2211 my $inx = shift @args;
271 1571         1879 push @nav, $inx;
272 1571         3706 $obj = $obj->[$inx];
273             } else {
274 6903         8328 my $method = shift @args;
275 6903         7571 my $args = shift @args;
276 6903 100       12210 ARRAY_REF eq ref $args
277             or $args = [ $args ];
278 6903         9983 push @nav, $method, $args;
279 6903 50       20414 $obj->can( $method ) or return;
280 6903 100 100     14753 if ( @args || $scalar ) {
281 6341 100       5783 $obj = $obj->$method( @{ $args } ) or return;
  6341         14848  
282             } else {
283 562         669 $obj = [ $obj->$method( @{ $args } ) ];
  562         1736  
284             }
285             }
286             }
287 4692         8826 $nav = __quote( @nav );
288 4692         38400 $nav =~ s/ ' ( \w+ ) ' , /$1 =>/smxg;
289 4692         10795 $nav =~ s/ \[ \s+ \] /[]/smxg;
290 4692         6180 $result = $obj;
291 4692         11638 return $obj;
292             }
293              
294             }
295              
296             sub parse { ## no critic (RequireArgUnpacking)
297 307     307 1 698094 my ( $opt, $regexp, @args ) = _parse_constructor_args(
298             { test => 1 }, @_ );
299 307         547 $initial_class = 'PPIx::Regexp';
300 307         431 $kind = 'element';
301 307         1813 $result = $obj = $parse = PPIx::Regexp->new( $regexp, @args );
302 307         939 $nav = '';
303 307 100       839 $opt->{test} or return;
304             # cperl does not seem to like goto &xxx; it throws a deep recursion
305             # error if you do it enough times.
306 306         563 local $Test::Builder::Level = $Test::Builder::Level + 1;
307 306         1024 return isa_ok( $parse, 'PPIx::Regexp' );
308             }
309              
310             sub ppi { ## no critic (RequireArgUnpacking)
311 1     1 1 581 my @args = @_;
312 1         2 my $expect = pop @args;
313 1         2 $result = undef;
314 1 50       7 defined $obj and $result = $obj->ppi()->content();
315 1         17 my $safe;
316 1 50       2 if ( defined $result ) {
317 1         3 ($safe = $result) =~ s/([\\'])/\\$1/smxg;
318             } else {
319 0         0 $safe = 'undef';
320             }
321             # cperl does not seem to like goto &xxx; it throws a deep recursion
322             # error if you do it enough times.
323 1         3 local $Test::Builder::Level = $Test::Builder::Level + 1;
324 1         4 return is( $result, $expect, "$kind $nav ppi() content '$safe'" );
325             }
326              
327             sub raw_width {
328 282     282 1 118415 my ( $min, $max, $name ) = @_;
329 282 50       1442 defined $name
330             or $name = sprintf q<%s '%s'>, ref $obj, $obj->content();
331 282         502 local $Test::Builder::Level = $Test::Builder::Level + 1;
332 282         924 my @width = $obj->raw_width();
333 282   33     910 return is( $width[0], $min, "$name raw minimum witdh" ) && is(
334             $width[1], $max, "$name raw maximum width" );
335             }
336              
337             sub replace_characters {
338 2     2 0 26210 %replace_characters = @_;
339 2         3 return;
340             }
341              
342             sub result {
343 2     2 1 1716 return $result;
344             }
345              
346             sub tokenize { ## no critic (RequireArgUnpacking)
347 206     206 1 651083 my ( $opt, $regexp, @args ) = _parse_constructor_args(
348             { test => 1, tokens => 1 }, @_ );
349 206         491 my %args = @args;
350 206         843 $initial_class = __choose_tokenizer_class( $regexp, \%args );
351 206         364 $kind = 'token';
352 206         1188 $obj = $initial_class->new( $regexp, @args );
353 206 100 100     934 if ( $obj && $opt->{tokens} ) {
354 203         657 $parse = [ $obj->tokens() ];
355             } else {
356 3         5 $parse = [];
357             }
358 206         475 $result = $parse;
359 206         431 $nav = '';
360 206 100       570 $opt->{test} or return;
361 205         365 local $Test::Builder::Level = $Test::Builder::Level + 1;
362 205         737 return isa_ok( $obj, 'PPIx::Regexp::Tokenizer' );
363             }
364              
365             sub true { ## no critic (RequireArgUnpacking)
366 47     47 1 16812 my ( $method, $args ) = @_;
367 47 100       167 ARRAY_REF eq ref $args
368             or $args = [ $args ];
369 47         82 my $class = ref $obj;
370             # cperl does not seem to like goto &xxx; it throws a deep recursion
371             # error if you do it enough times.
372 47         68 local $Test::Builder::Level = $Test::Builder::Level + 1;
373 47 50       227 if ( $obj->can( $method ) ) {
374 47         55 $result = $obj->$method( @{ $args } );
  47         424  
375 47         99 my $fmtd = _format_args( $args );
376 47         164 return ok( $result, "$class->$method$fmtd is true" );
377             } else {
378 0         0 $result = undef;
379 0         0 return ok( undef, "$class->$method() exists" );
380             }
381             }
382              
383             sub value { ## no critic (RequireArgUnpacking)
384 1081     1081 1 475614 my ( $method, $args, $want, $name ) = @_;
385 1081 100       3162 ARRAY_REF eq ref $args
386             or $args = [ $args ];
387              
388 1081   66     2262 my $invocant = $obj || $initial_class;
389 1081   66     2754 my $class = ref $obj || $obj || $initial_class;
390             # cperl does not seem to like goto &xxx; it throws a deep recursion
391             # error if you do it enough times.
392 1081         1686 local $Test::Builder::Level = $Test::Builder::Level + 1;
393 1081 50       4686 if ( ! $invocant->can( $method ) ) {
394 0         0 return ok( undef, "$class->$method() exists" );
395             }
396              
397             $result = ARRAY_REF eq ref $want ?
398 3         12 [ $invocant->$method( @{ $args } ) ] :
399 1081 100       2227 $invocant->$method( @{ $args } );
  1078         3568  
400              
401 1081         2647 my $fmtd = _format_args( $args );
402 1081 100       2544 my $answer = format_want( $want, bare => ref $want ? 0 : 1 );
403 1081 50       2426 defined $name
404             or $name = "${class}->$method$fmtd is $answer";
405 1081 100       1467 if ( ref $result ) {
406 5         19 return is_deeply( $result, $want, $name );
407             } else {
408 1076         2225 return is( $result, $want, $name );
409             }
410             }
411              
412             sub width {
413 282     282 1 323802 my ( $min, $max, $name ) = @_;
414 282 50       1403 defined $name
415             or $name = sprintf q<%s '%s'>, ref $obj, $obj->content();
416 282         434 local $Test::Builder::Level = $Test::Builder::Level + 1;
417 282         822 my @width = $obj->width();
418 282   33     936 return is( $width[0], $min, "$name minimum witdh" ) && is(
419             $width[1], $max, "$name maximum width" );
420             }
421              
422             sub _format_args {
423 2261     2261   4026 my ( $args, %opt ) = @_;
424 2261 100       4458 ARRAY_REF eq ref $args
425             or $args = [ $args ];
426 2261         2204 my @rslt;
427 2261         2010 foreach my $arg ( @{ $args } ) {
  2261         3385  
428 1145 100       3373 if ( ! defined $arg ) {
    100          
429 277         455 push @rslt, 'undef';
430             } elsif ( looks_like_number( $arg ) ) {
431 631         1213 push @rslt, $arg;
432             } else {
433 237         346 push @rslt, $arg;
434 237         473 $rslt[-1] =~ s/ ' /\\'/smxg;
435 237         565 $rslt[-1] = "'$rslt[-1]'";
436             }
437             }
438 2261         3755 my $string = join ', ', @rslt;
439 2261 100       5251 $opt{bare} and return $string;
440 1185 100       2691 @rslt or return '()';
441 64         147 return "( $string )";
442             }
443              
444             sub _method_result { ## no critic (RequireArgUnpacking)
445 3628     3628   6850 my ( $method, @args ) = @_;
446 3628         4573 my $expect = pop @args;
447 3628         5372 $result = undef;
448 3628 100       15984 defined $obj and $result = $obj->$method();
449 3628         5535 my $safe;
450 3628 100       5386 if ( defined $result ) {
451 3564         10431 ($safe = $result) =~ s/([\\'])/\\$1/smxg;
452 3564         4810 $safe = "'$safe'";
453             } else {
454 64         112 $safe = 'undef';
455             }
456 3628         10020 @_ = _replace_characters( $result, $expect, "$kind $nav $method $safe" );
457 3628         9845 goto &is;
458             }
459              
460             sub _parse_constructor_args {
461 518     518   1605 my ( $opt, @args ) = @_;
462 518         994 my @rslt = ( $opt );
463 518         997 foreach my $arg ( @args ) {
464 581 100 66     2663 if ( $arg =~ m/ \A - -? (no)? (\w+) \z /smx &&
465             exists $opt->{$2} ) {
466 4         12 $opt->{$2} = !$1;
467             } else {
468 577         1232 push @rslt, $arg;
469             }
470             }
471 518         1725 return @rslt;
472             }
473              
474             sub _pause {
475 10 50   10   19 if ( eval { require Time::HiRes; 1 } ) { # Cargo cult programming.
  10         87  
  10         23  
476 10         1001945 Time::HiRes::sleep( 0.1 ); # Something like this is
477             } else { # in PPI's
478 0         0 sleep 1; # t/08_regression.t, and
479             } # who am I to argue?
480 10         193 return;
481             }
482              
483             # quote a string.
484             sub __quote {
485 11445     11445   277176 my @args = @_;
486 11445         10070 my @rslt;
487 11445         12567 foreach my $item ( @args ) {
488 21231 50       25195 if ( __instance( $item, 'PPIx::Regexp::Element' ) ) {
489 0         0 $item = $item->content();
490             }
491 21231 100       44484 if ( ! defined $item ) {
    100          
    100          
492 24         39 push @rslt, 'undef';
493             } elsif ( ARRAY_REF eq ref $item ) {
494 6751         6830 push @rslt, join( ' ', '[', __quote( @{ $item } ), ']' );
  6751         8539  
495             } elsif ( looks_like_number( $item ) ) {
496 7697         10572 push @rslt, $item;
497             } else {
498 6759         12238 $item =~ s/ ( [\\'] ) /\\$1/smxg;
499 6759         11549 push @rslt, "'$item'";
500             }
501             }
502 11445         34335 return join( ', ', @rslt );
503             }
504              
505             sub _replace_characters {
506 3628     3628   7017 my @arg = @_;
507 3628 100       6448 if ( keys %replace_characters ) {
508 12         18 foreach ( @arg ) {
509             $_ = join '',
510             # The following assumes I will never want to replace 0.
511 36 100       204 map { $replace_characters{$_} || $_ }
  391         698  
512             split qr<>;
513             }
514             }
515             wantarray
516 3628 50       6047 or return join '', @arg;
517 3628         8628 return @arg;
518             }
519              
520             1;
521              
522             __END__
523              
524             =head1 NAME
525              
526             My::Module::Test - support for testing PPIx::Regexp
527              
528             =head1 SYNOPSIS
529              
530             use lib qw{ inc };
531             use My::Module::Test;
532              
533             parse ( '/foo/' );
534             value ( failures => [], 0 );
535             klass ( 'PPIx::Regexp' );
536             choose ( child => 0 );
537             klass ( 'PPIx::Regexp::Token::Structure' );
538             content ( '' );
539             # and so on
540              
541             =head1 DETAILS
542              
543             This module is B<private> to the C<PPIx-Regexp> module. Its contents can
544             be changed without warning. This was always the intent, and this
545             paragraph should have been included in the POD much earlier than it
546             actually was.
547              
548             This module exports various subroutines in support of testing
549             C<PPIx::Regexp>. Most of these are tests, with C<Test::More> doing the
550             dirty work. A few simply set up data for tests.
551              
552             The whole test rig works by parsing (or tokenizing) a regular
553             expression, followed by a series of unit tests on the results of the
554             parse. Each set of unit tests is performed by selecting an object to
555             test using the C<choose> or C<navigate> subroutine, followed by the
556             tests to be performed on that object. A few tests do not test parse
557             objects, but rather the state of the system as a whole.
558              
559             The following subroutines are exported:
560              
561             =head2 cache_count
562              
563             cache_count( 1 );
564              
565             This test compares the number of objects in the C<new_from_cache> cache
566             to its argument, succeeding if they are equal. If no argument is passed,
567             the default is 0.
568              
569             =head2 choose
570              
571             choose( 2 ); # For tokenizer
572             choose( child => 1, child => 2, type => 0 ); # For full parse
573              
574             This subroutine does not itself represent a test. It chooses an object
575             from the parse tree for further testing. If testing a tokenizer, the
576             argument is the token number (from 0) to select. If testing a full
577             parse, the arguments are the navigation methods used to reach the
578             object to be tested, starting from the C<PPIx::Regexp> object. The
579             arguments to the methods are passed in an array reference, but if there
580             is a single argument it can be passed as a scalar, as in the example.
581              
582             =head2 klass
583              
584             klass( 'PPIx::Regexp::Token::Structure' );
585              
586             This test checks to see if the current object is of the given class, and
587             succeeds if it is. If the current object is C<undef>, the test fails.
588              
589             This test was C<class>, but that tends to conflict with object systems.
590              
591             =head2 content
592              
593             content( '\N{LATIN SMALL LETTER A}' );
594              
595             This test checks to see if the C<content> method of the current object
596             is equal to the given string. If the current object is C<undef>, the
597             test fails.
598              
599             =head2 cmp_ok
600              
601             This subroutine is exported from L<Test::More|Test::More>.
602              
603             =head2 count
604              
605             count( 42 );
606              
607             This test checks the number of objects returned by an operation that
608             returns more than one object. It succeeds if the number of objects
609             returned is equal to the given number.
610              
611             This test is valid only after C<tokenize>, or a C<choose> or C<navigate>
612             whose argument list ends in one of
613              
614             children => []
615             finish => []
616             start => []
617             type => []
618              
619             =head2 different
620              
621             different( $o1, $o2, 'Test name' );
622              
623             This test compares two things, succeeding if they are different.
624             References are compared by reference address and scalars by value
625             (numeric or string comparison as appropriate). If the first argument is
626             omitted it defaults to the current object.
627              
628             =head2 dump_result
629              
630             dump_result( tokens => 1, <<'EOD', 'Test tokenization dump' );
631             ... expected dump here ...
632             EOD
633              
634             This test performs the specified dump on the current object and succeeds
635             if the result matches the expectation. The name of the test is the last
636             argument, and the expected result is the next-to-last argument. All
637             other arguments are passed to
638             L<PPIx::Regexp::Dumper|PPIx::Regexp::Dumper>.
639              
640             Well, almost all other arguments are passed to the dumper. You can
641             specify C<--notest> to skip the test. In this case the result of the
642             last operation is dumped. L<PPIx::Regexp::Dumper|PPIx::Regexp::Dumper>
643             is used if appropriate; otherwise you get a L<YAML|YAML> dump if that is
644             available, or a L<Data::Dumper|Data::Dumper> dump if not. If no dumper
645             class can be found, a diagnostic is produced. You can also specify
646             C<--test>, but this is the default. This option is removed from the
647             argument list before the test name (etc) is determined.
648              
649             =head2 equals
650              
651             equals( $o1, $o2, 'Test name' );
652              
653             This test compares two things, succeeding if they are equal. References
654             are compared by reference address and scalars by value (numeric or string
655             comparison as appropriate). If the first argument is omitted it defaults
656             to the current object.
657              
658             =head2 format_want
659              
660             is $got, $want, 'Want ' . format_want( $want );
661              
662             This convenience subroutine formats the wanted result. If an ARRAY
663             reference, the contents are enclosed in parentheses.
664              
665             =head2 false
666              
667             false( significant => [] );
668              
669             This test succeeds if the given method, with the given arguments, called
670             on the current object, returns a false value.
671              
672             =head2 finis
673              
674             finis();
675              
676             This test should be last in a series, and no references to parse objects
677             should be held when it is run. It checks the number of objects in the
678             internal C<%parent> hash, and succeeds if it is zero.
679              
680             =head2 invocant
681              
682             invocant();
683              
684             Returns the current object.
685              
686             =head2 navigate
687              
688             navigate( snext_sibling => [] );
689              
690             Like C<choose>, this is not a test, but selects an object for testing.
691             Unlike C<choose>, selection starts from the current object, not the top
692             of the parse tree.
693              
694             =head2 parse
695              
696             parse( 's/foo/bar/g' );
697              
698             This test parses the given regular expression into a C<PPIx::Regexp>
699             object, and succeeds if a C<PPIx::Regexp> object was in fact generated.
700              
701             If you specify argument C<--notest>, the parse is done but no test is
702             performed. You would do this if you expected the parse to fail (e.g. you
703             are testing error handling). You can also explicitly specify C<--test>,
704             but this is the default.
705              
706             All other arguments are passed to the L<PPIx::Regexp|PPIx::Regexp>
707             constructor.
708              
709             =head2 plan
710              
711             This subroutine is exported from L<Test::More|Test::More>.
712              
713             =head2 ppi
714              
715             ppi( '$foo' );
716              
717             This test calls the current object's C<ppi()> method, and checks to see
718             if the content of the returned L<PPI::Document|PPI::Document> is equal
719             to the given string. If the current object is C<undef> or does not have
720             a C<ppi()> method, the test fails.
721              
722             =head2 raw_width
723              
724             raw_width( 0, undef, "Some title" );
725              
726             This tests invokes the raw_width() method on the current object. The
727             arguments are the expected minimum width, the expected maximum width,
728             and a test title. The title defaults to the class and content of the
729             current object.
730              
731             Two tests are actually run. The titles of these will have
732             C<' raw minimum width'> and C<' raw maximum width'> appended. This
733             subroutine returns true if both tests pass.
734              
735             =head2 result
736              
737             my $val = result();
738              
739             This subroutine returns the result of the most recent operation that
740             actually produces one. It should be called immediately after the
741             operation, mostly because I have not documented all the subroutines that
742             produce a result.
743              
744             =head2 tokenize
745              
746             tokenize( 'm/foo/smx' );
747              
748             This test tokenizes the given regular expression into a
749             C<PPIx::Regexp::Tokenizer> object, and succeeds if a
750             C<PPIx::Regexp::Tokenizer> object was in fact generated.
751              
752             If you specify argument C<--notest>, the parse is done but no test is
753             performed. You would do this if you expected the parse to fail (e.g. you
754             are testing error handling). You can also explicitly specify C<--test>,
755             but this is the default.
756              
757             If you specify argument C<--notokens>, the tokenizer is built, but the
758             tokens are not extracted. You would do this when you want a subsequent
759             operation to call C<tokens()>. You can also explicitly specify
760             C<--tokens>, but this is the default.
761              
762             All other arguments are passed to the
763             L<PPIx::Regexp::Tokenizer|PPIx::Regexp::Tokenizer> constructor.
764              
765             =head2 true
766              
767             true( significant => [] );
768              
769             This test succeeds if the given method, with the given arguments, called
770             on the current object, returns a true value.
771              
772             =head2 value
773              
774             value( max_capture_number => [], 3 );
775              
776             This test succeeds if the given method, with the given arguments, called
777             on the current object, returns the given value. If the wanted value is
778             a reference, C<is_deeply()> is used for the comparison; otherwise
779             C<is()> is used.
780              
781             If the current object is undefined, the given method is called on the
782             intended initial class, otherwise there would be no way to test the
783             errstr() method.
784              
785             The result of the method call is accessable via the L<result()|/result>
786             subroutine.
787              
788             An optional fourth argument specifies the name of the test. If this is
789             omitted or specified as C<undef>, a name is generated describing the
790             arguments.
791              
792             =head2 width
793              
794             width( 0, undef, "Some title" );
795              
796             This tests invokes the width() method on the current object. The
797             arguments are the expected minimum width, the expected maximum width,
798             and a test title. The title defaults to the class and content of the
799             current object.
800              
801             Two tests are actually run. The titles of these will have
802             C<' minimum width'> and C<' maximum width'> appended. This subroutine
803             returns true if both tests pass.
804              
805             =head1 SUPPORT
806              
807             Support is by the author. Please file bug reports at
808             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
809             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
810             electronic mail to the author.
811              
812             =head1 AUTHOR
813              
814             Thomas R. Wyant, III F<wyant at cpan dot org>
815              
816             =head1 COPYRIGHT AND LICENSE
817              
818             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
819              
820             This program is free software; you can redistribute it and/or modify it
821             under the same terms as Perl 5.10.0. For more details, see the full text
822             of the licenses in the directory LICENSES.
823              
824             This program is distributed in the hope that it will be useful, but
825             without any warranty; without even the implied warranty of
826             merchantability or fitness for a particular purpose.
827              
828             =cut
829              
830             # ex: set textwidth=72 :