Compiler/Test.pm

filter: Statementstmt 90.7% 78 / 86 Branchbran 50.0% 5 / 10 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.9% 20 / 22 Podpod 0.0% 0 / 1 totaltotal 81.2% 104 / 128 CC 10 SCAR 13.9
CC
10
Cov
82%
build_and_test
11.9
_test_run_result_is
2.1
_test_run_dump_lexer
2.0
CRAP 4.0
« Compiler/Lexer.pm ↑ Summary Compiler/Target/HTML.pm »
1 package Markdown::Compiler::Test;
2 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use Test::Deep;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use Test::Differences;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Markdown::Compiler;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use Markdown::Compiler::Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use Markdown::Compiler::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use Markdown::Compiler::Target::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 18 push our @ISA, qw( Exporter );
16 18 push our @EXPORT, qw( build_and_test _test_dump_lexer _test_dump_parser _test_dump_html );
17  
18 18 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
19 18 shift->export_to_level(1);
20
21 18 my $target = caller;
22  
23 18 warnings->import::into($target);
24 18 strict->import::into($target);
25 18 Test::More->import::into($target);
26 18 Test::Deep->import::into($target);
27 }
28  
29 # build_and_test
30 #
31 # source can be:
32 # 1. string ->
33 # 2. hash ->
34 # 3. code ->
35 #
36 # expect can be:
37 # code_name => arguments ( &_test_run_$code_name($compiler,$arguments) )
38 66 ▶sub build_and_test {
Subroutine build_and_test: called CC=8 SCAR=24.7
Pod undocumented
39 66 my ( $name, $source, $expects ) = @_;
40 66 my ( undef, $file, $line ) = caller;
41  
42 66 ▶ if ( ref($source) and ( ref($source) ne 'CODE' or ref($source) ne 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $source and ref $source ne "CODE" || ref $source ne "HASH") 0 66 66
Condition16%1/6
ref $source and ref $source ne "CODE" || ref $source ne "HASH"
!ll&&!rl&&r
6600
ref $source ne "CODE" or ref $source ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $source and ref $source ne "CODE" || ref $source ne "HASH"
ref $source ref $source ne "CODE" ref $source ne "HASH"
Truth table25%1/4
A and B or C
A= ref $sourceB= ref $source ne "CODE"C= ref $source ne "HASH"
ABCresult
0XX0
1000
11X1
1011
43 0 die "Error: Invalid type for \$source @ $file:$line. Must be HASH, CODE or plain string.\n";
44 }
45  
46 my $compiler = ref($source) eq 'HASH'
47 0 ▶ ? Markdown::Compiler->new( %{$source} )
Branch: 2 branches
BranchTrueFalseTotal
ref $source eq 'HASH' ? : 0 66 66
ref $source eq 'CODE' ? : 0 66 66
48 : ref($source) eq 'CODE'
49 ? $source->()
50 : Markdown::Compiler->new( source => $source );
51  
52 66 foreach my $expect ( @{$expects} ) {
53 74 my $method_name = shift @{$expect};
54  
55 74 ▶ my $test = __PACKAGE__->can( "_test_run_$method_name" )
Branch: 1 branch
BranchTrueFalseTotal
my $test = __PACKAGE__->can("_test_run_$method_name") or die "Invalid test function: $method_name \@ ${file}:$line\n" 74 0 74
56 or die "Invalid test function: $method_name @ $file:$line\n";
57  
58 74 $test->($compiler, $name, $file, $line, @{$expect});
59 }
60  
61 66 return $compiler;
62 }
63  
64 3 ▶sub _test_run_dump_lexer {
Subroutine _test_run_dump_lexer: called CC=2 SCAR=6.9
65 3 my ( $compiler, $name, $file, $line, @args ) = @_;
66  
67 3 foreach my $token ( @{$compiler->lexer->tokens} ) {
68 46 ( my $content = $token->content ) =~ s/\n//g;
69 46 printf( "%20s | %s\n", $content, $token->type );
70 }
71 }
72  
73 3 ▶sub _test_run_dump_parser {
Subroutine _test_run_dump_parser: called CC=1 SCAR=0.0
74 3 my ( $compiler, $name, $file, $line, @args ) = @_;
75  
76 3 my $tree = $compiler->parser->tree;
77  
78 3 print Dumper($tree);
79 }
80  
81 0 ▶sub _test_run_dump_result {
Subroutine _test_run_dump_result: not called CC=1 SCAR=6.9
82 0 my ( $compiler, $name, $file, $line, @args ) = @_;
83  
84 0 print "=== HTML ===\n" . $compiler->result . "\n=== END ===\n\n";
85 }
86  
87 # Paragraph
88 # String
89 # String
90 # String => [ content => 'foo', children => '' ],
91 #
92 #
93 #
94 #
95 #
96 #
97 0 ▶sub _test_run_assert_parse_tree {
Subroutine _test_run_assert_parse_tree: not called CC=1 SCAR=6.9
98 0 my ( $compiler, $name, $file, $line, @args ) = @_;
99  
100 0 my $tree = $compiler->parser->tree;
101  
102 0 print Dumper($tree);
103 }
104  
105 1 ▶sub _test_run_assert_parser {
Subroutine _test_run_assert_parser: called CC=1 SCAR=0.0
106 1 my ( $compiler, $name, $file, $line, $match ) = @_;
107  
108 1 my $tree = $compiler->parser->tree;
109  
110 1 cmp_deeply( $tree, $match, sprintf( "%s:%d: %s", $file, $line, $name ) );
111 }
112  
113 1 ▶sub _test_run_assert_lexer {
Subroutine _test_run_assert_lexer: called CC=1 SCAR=0.0
114 1 my ( $compiler, $name, $file, $line, $match ) = @_;
115  
116 1 my @stream = map { ref($_) } @{$compiler->parser->stream};
117  
118 1 cmp_deeply( \@stream, $match, sprintf( "%s:%d: %s", $file, $line, $name ) );
119 }
120  
121  
122 # This one I need to think through!
123 64 ▶sub _test_run_result_is {
Subroutine _test_run_result_is: called CC=2 SCAR=7.6
124 64 my ( $compiler, $name, $file, $line, $match ) = @_;
125  
126 64 ▶ if ( ref($match) eq 'REGEXP' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $match eq 'REGEXP') { } 0 64 64
127 0 ok( $compiler->result =~ $match, sprintf( "%s:%d: %s", $file, $line, $name ) );
128 } else {
129 64 eq_or_diff ( $compiler->result, $match, sprintf( "%s:%d: %s", $file, $line, $name ) );
130 }
131 }
132  
133 2 ▶sub _test_run_metadata_is {
Subroutine _test_run_metadata_is: called CC=1 SCAR=0.0
134 2 my ( $compiler, $name, $file, $line, $match ) = @_;
135  
136 2 cmp_deeply( $compiler->metadata, $match, sprintf( "%s:%d: %s", $file, $line, $name ) );
137 }
138  
139  
140 18 1;
« Compiler/Lexer.pm ↑ Summary Compiler/Target/HTML.pm »