Login
Fixed spelling errors
[gknop/Perl-Critic.git] / t / 08_document.t
CommitLineData
b22c8627
JRT
1#############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7
8use strict;
9use warnings;
7d1077fa 10use Test::More tests => 8;
b22c8627
JRT
11
12#-----------------------------------------------------------------------------
13
14use_ok('Perl::Critic::Document');
15can_ok('Perl::Critic::Document', 'new');
16can_ok('Perl::Critic::Document', 'find');
17
18{
19 my $code = q{'print 'Hello World';}; #Has 6 PPI::Element
20 my $ppi_doc = PPI::Document->new( \$code );
21 my $pc_doc = Perl::Critic::Document->new( $ppi_doc );
22 isa_ok($pc_doc, 'Perl::Critic::Document');
23
24
25 my $nodes_ref = $pc_doc->find('PPI::Element');
26 is( scalar @{ $nodes_ref }, 6, 'Search by class name');
27
28 $nodes_ref = $pc_doc->find( sub{ return 1 } );
29 is( scalar @{ $nodes_ref }, 6, 'Search by wanted() handler');
30
7d1077fa
CD
31 $nodes_ref = $pc_doc->find( q{Element} );
32 is( scalar @{ $nodes_ref }, 6, 'Search by shortened class name');
33
34 {
35 # Ignore "Cannot create search condition for 'PPI::': Not a PPI::Element"
d91a8cdf
CD
36 local $SIG{__WARN__} = sub {
37 $_[0] =~ m/\QCannot create search condition for\E/ || warn @_
38 };
7d1077fa
CD
39 $nodes_ref = $pc_doc->find( q{} );
40 is( $nodes_ref, undef, 'Search by empty class name');
41 }
b22c8627 42}