line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Markdown::Compiler::Test; |
2
|
17
|
|
|
17
|
|
8221
|
use warnings; |
|
17
|
|
|
|
|
128
|
|
|
17
|
|
|
|
|
650
|
|
3
|
17
|
|
|
17
|
|
89
|
use strict; |
|
17
|
|
|
|
|
29
|
|
|
17
|
|
|
|
|
370
|
|
4
|
17
|
|
|
17
|
|
11634
|
use Test::More; |
|
17
|
|
|
|
|
1197631
|
|
|
17
|
|
|
|
|
153
|
|
5
|
17
|
|
|
17
|
|
17007
|
use Test::Deep; |
|
17
|
|
|
|
|
191398
|
|
|
17
|
|
|
|
|
116
|
|
6
|
17
|
|
|
17
|
|
16554
|
use Test::Differences; |
|
17
|
|
|
|
|
335186
|
|
|
17
|
|
|
|
|
1251
|
|
7
|
17
|
|
|
17
|
|
8790
|
use Import::Into; |
|
17
|
|
|
|
|
48928
|
|
|
17
|
|
|
|
|
582
|
|
8
|
17
|
|
|
17
|
|
134
|
use Exporter; |
|
17
|
|
|
|
|
48
|
|
|
17
|
|
|
|
|
849
|
|
9
|
17
|
|
|
17
|
|
8407
|
use Markdown::Compiler; |
|
17
|
|
|
|
|
67
|
|
|
17
|
|
|
|
|
666
|
|
10
|
17
|
|
|
17
|
|
136
|
use Markdown::Compiler::Lexer; |
|
17
|
|
|
|
|
37
|
|
|
17
|
|
|
|
|
621
|
|
11
|
17
|
|
|
17
|
|
131
|
use Markdown::Compiler::Parser; |
|
17
|
|
|
|
|
60
|
|
|
17
|
|
|
|
|
500
|
|
12
|
17
|
|
|
17
|
|
94
|
use Markdown::Compiler::Target::HTML; |
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
297
|
|
13
|
17
|
|
|
17
|
|
83
|
use Data::Dumper::Concise; |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
17880
|
|
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
|
17
|
|
|
17
|
|
1753
|
shift->export_to_level(1); |
20
|
|
|
|
|
|
|
|
21
|
17
|
|
|
|
|
60
|
my $target = caller; |
22
|
|
|
|
|
|
|
|
23
|
17
|
|
|
|
|
159
|
warnings->import::into($target); |
24
|
17
|
|
|
|
|
3818
|
strict->import::into($target); |
25
|
17
|
|
|
|
|
2960
|
Test::More->import::into($target); |
26
|
17
|
|
|
|
|
7845
|
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
|
65
|
|
|
65
|
0
|
2733
|
my ( $name, $source, $expects ) = @_; |
40
|
65
|
|
|
|
|
276
|
my ( undef, $file, $line ) = caller; |
41
|
|
|
|
|
|
|
|
42
|
65
|
0
|
0
|
|
|
219
|
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
|
65
|
50
|
|
|
|
1493
|
? Markdown::Compiler->new( %{$source} ) |
|
0
|
50
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
: ref($source) eq 'CODE' |
49
|
|
|
|
|
|
|
? $source->() |
50
|
|
|
|
|
|
|
: Markdown::Compiler->new( source => $source ); |
51
|
|
|
|
|
|
|
|
52
|
65
|
|
|
|
|
34382
|
foreach my $expect ( @{$expects} ) { |
|
65
|
|
|
|
|
170
|
|
53
|
73
|
|
|
|
|
22791
|
my $method_name = shift @{$expect}; |
|
73
|
|
|
|
|
155
|
|
54
|
|
|
|
|
|
|
|
55
|
73
|
50
|
|
|
|
697
|
my $test = __PACKAGE__->can( "_test_run_$method_name" ) |
56
|
|
|
|
|
|
|
or die "Invalid test function: $method_name @ $file:$line\n"; |
57
|
|
|
|
|
|
|
|
58
|
73
|
|
|
|
|
175
|
$test->($compiler, $name, $file, $line, @{$expect}); |
|
73
|
|
|
|
|
201
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
65
|
|
|
|
|
65768
|
return $compiler; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _test_run_dump_lexer { |
65
|
3
|
|
|
3
|
|
13
|
my ( $compiler, $name, $file, $line, @args ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
8
|
foreach my $token ( @{$compiler->lexer->tokens} ) { |
|
3
|
|
|
|
|
71
|
|
68
|
46
|
|
|
|
|
1093
|
( my $content = $token->content ) =~ s/\n//g; |
69
|
46
|
|
|
|
|
137
|
printf( "%20s | %s\n", $content, $token->type ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _test_run_dump_parser { |
74
|
3
|
|
|
3
|
|
14
|
my ( $compiler, $name, $file, $line, @args ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
77
|
my $tree = $compiler->parser->tree; |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
20
|
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
|
|
|
|
|
26
|
my $tree = $compiler->parser->tree; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
35
|
cmp_deeply( $tree, $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _test_run_assert_lexer { |
114
|
1
|
|
|
1
|
|
4
|
my ( $compiler, $name, $file, $line, $match ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
3
|
my @stream = map { ref($_) } @{$compiler->parser->stream}; |
|
3
|
|
|
|
|
19
|
|
|
1
|
|
|
|
|
34
|
|
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
10
|
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
|
|
185
|
my ( $compiler, $name, $file, $line, $match ) = @_; |
125
|
|
|
|
|
|
|
|
126
|
64
|
50
|
|
|
|
176
|
if ( ref($match) eq 'REGEXP' ) { |
127
|
0
|
|
|
|
|
0
|
ok( $compiler->result =~ $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
128
|
|
|
|
|
|
|
} else { |
129
|
64
|
|
|
|
|
1250
|
eq_or_diff ( $compiler->result, $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _test_run_metadata_is { |
134
|
1
|
|
|
1
|
|
4
|
my ( $compiler, $name, $file, $line, $match ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
23
|
cmp_deeply( $compiler->parser->metadata, $match, sprintf( "%s:%d: %s", $file, $line, $name ) ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |