Login
Remove backslash from end of last line in the tags target
[gknop/Perl-Critic.git] / t / 08_document.t
CommitLineData
faa35de4
JRT
1#!perl
2
6036a254 3##############################################################################
b22c8627
JRT
4# $URL$
5# $Date$
6# $Author$
7# $Revision$
8##############################################################################
9
10use strict;
11use warnings;
3d6744c8 12use Test::More tests => 18;
b22c8627
JRT
13
14#-----------------------------------------------------------------------------
15
16use_ok('Perl::Critic::Document');
17can_ok('Perl::Critic::Document', 'new');
18can_ok('Perl::Critic::Document', 'find');
3d6744c8
JRT
19can_ok('Perl::Critic::Document', 'find_first');
20can_ok('Perl::Critic::Document', 'find_any');
b22c8627
JRT
21
22{
23 my $code = q{'print 'Hello World';}; #Has 6 PPI::Element
24 my $ppi_doc = PPI::Document->new( \$code );
25 my $pc_doc = Perl::Critic::Document->new( $ppi_doc );
26 isa_ok($pc_doc, 'Perl::Critic::Document');
27
28
29 my $nodes_ref = $pc_doc->find('PPI::Element');
3d6744c8 30 is( scalar @{ $nodes_ref }, 6, 'find by class name');
b22c8627
JRT
31
32 $nodes_ref = $pc_doc->find( sub{ return 1 } );
3d6744c8 33 is( scalar @{ $nodes_ref }, 6, 'find by wanted() handler');
b22c8627 34
7d1077fa 35 $nodes_ref = $pc_doc->find( q{Element} );
3d6744c8
JRT
36 is( scalar @{ $nodes_ref }, 6, 'find by shortened class name');
37
38 #---------------------------
39
40 my $node = $pc_doc->find_first('PPI::Element');
41 is( ref $node, 'PPI::Statement', 'find_first by class name');
42
43 $node = $pc_doc->find_first( sub{ return 1 } );
44 is( ref $node, 'PPI::Statement', 'find_first by wanted() handler');
45
46 $node = $pc_doc->find_first( q{Element} );
47 is( ref $node, 'PPI::Statement', 'find_first by shortened class name');
48
49 #---------------------------
50
51 my $found = $pc_doc->find_any('PPI::Element');
52 is( $found, 1, 'find_any by class name');
53
54 $found = $pc_doc->find_any( sub{ return 1 } );
55 is( $found, 1, 'find_any by wanted() handler');
56
57 $found = $pc_doc->find_any( q{Element} );
58 is( $found, 1, 'find_any by shortened class name');
59
60 #-------------------------------------------------------------------------
7d1077fa
CD
61
62 {
63 # Ignore "Cannot create search condition for 'PPI::': Not a PPI::Element"
d91a8cdf
CD
64 local $SIG{__WARN__} = sub {
65 $_[0] =~ m/\QCannot create search condition for\E/ || warn @_
66 };
7d1077fa 67 $nodes_ref = $pc_doc->find( q{} );
3d6744c8
JRT
68 is( $nodes_ref, undef, 'find by empty class name');
69
70 $node = $pc_doc->find_first( q{} );
71 is( $node, undef, 'find_first by empty class name');
72
73 $found = $pc_doc->find_any( q{} );
74 is( $found, undef, 'find_any by empty class name');
75
7d1077fa 76 }
b22c8627 77}
737d3b65
CD
78
79# Local Variables:
80# mode: cperl
81# cperl-indent-level: 4
82# fill-column: 78
83# indent-tabs-mode: nil
84# c-indentation-style: bsd
85# End:
345c7562 86# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab :