line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Markdown::Compiler::Test; |
2
|
18
|
|
|
18
|
|
6419
|
use warnings; |
|
18
|
|
|
|
|
115
|
|
|
18
|
|
|
|
|
570
|
|
3
|
18
|
|
|
18
|
|
94
|
use strict; |
|
18
|
|
|
|
|
30
|
|
|
18
|
|
|
|
|
304
|
|
4
|
18
|
|
|
18
|
|
10298
|
use Test::More; |
|
18
|
|
|
|
|
1061609
|
|
|
18
|
|
|
|
|
157
|
|
5
|
18
|
|
|
18
|
|
15285
|
use Test::Deep; |
|
18
|
|
|
|
|
170357
|
|
|
18
|
|
|
|
|
113
|
|
6
|
18
|
|
|
18
|
|
14569
|
use Test::Differences; |
|
18
|
|
|
|
|
301206
|
|
|
18
|
|
|
|
|
1271
|
|
7
|
18
|
|
|
18
|
|
8166
|
use Import::Into; |
|
18
|
|
|
|
|
42854
|
|
|
18
|
|
|
|
|
546
|
|
8
|
18
|
|
|
18
|
|
134
|
use Exporter; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
683
|
|
9
|
18
|
|
|
18
|
|
7668
|
use Markdown::Compiler; |
|
18
|
|
|
|
|
135
|
|
|
18
|
|
|
|
|
666
|
|
10
|
18
|
|
|
18
|
|
132
|
use Markdown::Compiler::Lexer; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
364
|
|
11
|
18
|
|
|
18
|
|
84
|
use Markdown::Compiler::Parser; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
331
|
|
12
|
18
|
|
|
18
|
|
79
|
use Markdown::Compiler::Target::HTML; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
311
|
|
13
|
18
|
|
|
18
|
|
88
|
use Data::Dumper::Concise; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
15976
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
push our @ISA, qw( Exporter ); |
16
|
|
|
|
|
|
|
push our @EXPORT, qw( build_and_test _test_dump_lexer _test_dump_parser _test_dump_html ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
18
|
|
|
18
|
|
1954
|
shift->export_to_level(1); |
20
|
|
|
|
|
|
|
|
21
|
18
|
|
|
|
|
50
|
my $target = caller; |
22
|
|
|
|
|
|
|
|
23
|
18
|
|
|
|
|
150
|
warnings->import::into($target); |
24
|
18
|
|
|
|
|
3567
|
strict->import::into($target); |
25
|
18
|
|
|
|
|
2622
|
Test::More->import::into($target); |
26
|
18
|
|
|
|
|
6929
|
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
|
|
|
|
|
|
|
sub build_and_test { |
39
|
66
|
|
|
66
|
0
|
2547
|
my ( $name, $source, $expects ) = @_; |
40
|
66
|
|
|
|
|
236
|
my ( undef, $file, $line ) = caller; |
41
|
|
|
|
|
|
|
|
42
|
66
|
0
|
0
|
|
|
217
|
if ( ref($source) and ( ref($source) ne 'CODE' or ref($source) ne 'HASH' ) ) { |
|
|
|
33
|
|
|
|
|
43
|
0
|
|
|
|
|
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
|
66
|
50
|
|
|
|
1462
|
? Markdown::Compiler->new( %{$source} ) |
|
0
|
50
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
: ref($source) eq 'CODE' |
49
|
|
|
|
|
|
|
? $source->() |
50
|
|
|
|
|
|
|
: Markdown::Compiler->new( source => $source ); |
51
|
|
|
|
|
|
|
|
52
|
66
|
|
|
|
|
33118
|
foreach my $expect ( @{$expects} ) { |
|
66
|
|
|
|
|
156
|
|
53
|
74
|
|
|
|
|
19118
|
my $method_name = shift @{$expect}; |
|
74
|
|
|
|
|
153
|
|
54
|
|
|
|
|
|
|
|
55
|
74
|
50
|
|
|
|
680
|
my $test = __PACKAGE__->can( "_test_run_$method_name" ) |
56
|
|
|
|
|
|
|
or die "Invalid test function: $method_name @ $file:$line\n"; |
57
|
|
|
|
|
|
|
|
58
|
74
|
|
|
|
|
161
|
$test->($compiler, $name, $file, $line, @{$expect}); |
|
74
|
|
|
|
|
206
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
66
|
|
|
|
|
75408
|
return $compiler; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _test_run_dump_lexer { |
65
|
3
|
|
|
3
|
|
10
|
my ( $compiler, $name, $file, $line, @args ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
6
|
foreach my $token ( @{$compiler->lexer->tokens} ) { |
|
3
|
|
|
|
|
59
|
|
68
|
46
|
|
|
|
|
890
|
( my $content = $token->content ) =~ s/\n//g; |
69
|
46
|
|
|
|
|
116
|
printf( "%20s | %s\n", $content, $token->type ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _test_run_dump_parser { |
74
|
3
|
|
|
3
|
|
21
|
my ( $compiler, $name, $file, $line, @args ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
69
|
my $tree = $compiler->parser->tree; |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
19
|
print Dumper($tree); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _test_run_dump_result { |
82
|
0
|
|
|
0
|
|
0
|
my ( $compiler, $name, $file, $line, @args ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
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
|
|
|
|
|
|
|
sub _test_run_assert_parse_tree { |
98
|
0
|
|
|
0
|
|
0
|
my ( $compiler, $name, $file, $line, @args ) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
my $tree = $compiler->parser->tree; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
print Dumper($tree); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _test_run_assert_parser { |
106
|
1
|
|
|
1
|
|
3
|
my ( $compiler, $name, $file, $line, $match ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
22
|
my $tree = $compiler->parser->tree; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
31
|
cmp_deeply( $tree, $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _test_run_assert_lexer { |
114
|
1
|
|
|
1
|
|
3
|
my ( $compiler, $name, $file, $line, $match ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
3
|
my @stream = map { ref($_) } @{$compiler->parser->stream}; |
|
3
|
|
|
|
|
107
|
|
|
1
|
|
|
|
|
31
|
|
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
11
|
cmp_deeply( \@stream, $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# This one I need to think through! |
123
|
|
|
|
|
|
|
sub _test_run_result_is { |
124
|
64
|
|
|
64
|
|
172
|
my ( $compiler, $name, $file, $line, $match ) = @_; |
125
|
|
|
|
|
|
|
|
126
|
64
|
50
|
|
|
|
172
|
if ( ref($match) eq 'REGEXP' ) { |
127
|
0
|
|
|
|
|
0
|
ok( $compiler->result =~ $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
128
|
|
|
|
|
|
|
} else { |
129
|
64
|
|
|
|
|
1079
|
eq_or_diff ( $compiler->result, $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _test_run_metadata_is { |
134
|
2
|
|
|
2
|
|
7
|
my ( $compiler, $name, $file, $line, $match ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
2
|
|
|
|
|
38
|
cmp_deeply( $compiler->metadata, $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |