File Coverage

t/PerlySense-BookmarkConfig.t
Criterion Covered Total %
statement 60 60 100.0
branch 2 4 50.0
condition n/a
subroutine 11 11 100.0
pod n/a
total 73 75 97.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2 1     1   104083 use strict;
  1         2  
  1         69  
3              
4 1     1   467 use Test::More tests => 16;
  1         17160  
  1         8  
5 1     1   1203 use Test::Exception;
  1         2677  
  1         4  
6              
7 1     1   604 use Data::Dumper;
  1         9643  
  1         81  
8              
9              
10 1     1   392 use lib "lib";
  1         536  
  1         4  
11              
12 1     1   83486 use_ok("Devel::PerlySense");
  1         932  
  1         2  
  1         2  
  1         6  
13 1     1   272 use_ok("Devel::PerlySense::BookmarkConfig");
  1         74  
  1         1  
  1         2  
  1         5  
14              
15              
16              
17 1         195 ok(my $oPerlySense = Devel::PerlySense->new(), "new PerlySense");
18              
19              
20 1         196 note("Bad bookmark config");
21              
22 1         48 $oPerlySense->rhConfig->{bookmark} = [ {
23             moniker => "",
24             rex => "",
25             }, ];
26             throws_ok(
27 1     1   49 sub { $oPerlySense->oBookmarkConfig->raDefinition },
28 1         81 qr/Bad Bookmark definition: No 'moniker' specified'/,
29             "Missing moniker dies ok",
30             );
31              
32 1         298 $oPerlySense->rhConfig->{bookmark} = [ {
33             moniker => "Broken",
34             rex => "fds/",
35             }, ];
36             throws_ok(
37 1     1   37 sub { $oPerlySense->oBookmarkConfig->raDefinition },
38 1         37 qr/syntax error/i,
39             "Bad Perl syntax dies ok",
40             );
41              
42 1         202 $oPerlySense->rhConfig->{bookmark} = [ {
43             moniker => "Broken",
44             rex => "'not a rex object'",
45             }, ];
46             throws_ok(
47 1     1   39 sub { $oPerlySense->oBookmarkConfig->raDefinition },
48 1         36 qr/doesn't result in a regex/i,
49             "Not a rex dies ok",
50             );
51              
52              
53              
54              
55 1         198 note("Proper bookmark config");
56              
57 1         37 my $dirData = "t/data/project-lib";
58 1         3 my $fileOrigin = "$dirData/Game/Object/Worm/ShaiHulud.pm";
59 1         3 $oPerlySense->setFindProject(dir => $fileOrigin);
60              
61            
62 1         9 $oPerlySense->rhConfig->{bookmark} = [
63             {
64             moniker => "Todo",
65             rex => 'qr/\# \s* TODO: \s* ( .+ )/x',
66             },
67             {
68             moniker => "Debugging",
69             rex => [
70             'qr/DB::single/',
71             'qr/debug\(/x',
72             ],
73             },
74             ];
75              
76              
77 1         54 ok(my $oBookmarkConfig = $oPerlySense->oBookmarkConfig, " BookmarkConfig");
78 1         295 isa_ok($oBookmarkConfig, "Devel::PerlySense::BookmarkConfig");
79              
80              
81              
82 1         238 is(scalar @{$oBookmarkConfig->raDefinition}, 2, " found 2 definitions");
  1         5  
83              
84 1         203 ok(my $todo_definition = $oBookmarkConfig->raDefinition->[0], "Got Todo");
85 1         250 isa_ok($todo_definition, "Devel::PerlySense::Bookmark::Definition");
86 1         251 is($todo_definition->moniker, "Todo", "Correct moniker");
87              
88              
89              
90              
91 1         184 my @aMatchResult;
92              
93 1         3 note("Find matches");
94              
95              
96             throws_ok(
97 1     1   53 sub { $oBookmarkConfig->aMatchResult(file => "missing_file.pm") },
98 1         50 qr/Could not read source file/,
99             );
100              
101              
102              
103 1         210 @aMatchResult = $oBookmarkConfig->aMatchResult(file => $fileOrigin);
104              
105 2         73 is_deeply(
106 1 50       3 [ map { $_->oDefinition->moniker } @aMatchResult ],
107             [ "Todo", "Debugging" ],
108             "Got correct moniker for both match results",
109             ) or note Dumper(\@aMatchResult);
110              
111 1         534 my $oMatchResultTodo = $aMatchResult[0];
112 1         28 is($oMatchResultTodo->oDefinition->moniker, "Todo", " Correct moniker");
113 1         188 my @aMatch = @{$oMatchResultTodo->raMatch};
  1         26  
114 1 50       8 is(scalar @aMatch, 3, " Found the correct number of matches") or note Dumper(\@aMatchResult);
115              
116              
117              
118              
119             __END__