Skip to content

Commit

Permalink
Add test for parser and render options
Browse files Browse the repository at this point in the history
  • Loading branch information
nwellnhof committed Oct 22, 2017
1 parent 3e8b3cc commit 73bc866
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ t/07_tree_manip.t
t/08_create_helpers.t
t/09_version.t
t/10_wrappers.t
t/11_options.t
t/20_errors.t
t/30_leakcheck.t
t/author-pod-syntax.t
Expand Down
52 changes: 52 additions & 0 deletions t/11_options.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use strict;
use warnings;

use Encode;
use Test::More tests => 9;

BEGIN {
use_ok('CommonMark', ':opt');
}

my ($md, $expected);

$md = "aaa\n\nbbb";
$expected = <<'EOF';
<p data-sourcepos="1:1-1:3">aaa</p>
<p data-sourcepos="3:1-3:3">bbb</p>
EOF
is(CommonMark->markdown_to_html($md, OPT_SOURCEPOS), $expected, 'SOURCEPOS');

$md = "a\nb";
is(CommonMark->markdown_to_html($md, OPT_HARDBREAKS), "<p>a<br />\nb</p>\n",
'HARDBREAKS');
is(CommonMark->markdown_to_html($md, OPT_NOBREAKS), "<p>a b</p>\n",
'NOBREAKS');
is(CommonMark->markdown_to_html($md), "<p>a\nb</p>\n",
'without HARDBREAKS or NOBREAKS');

$md = <<'EOF';
<script>alert('XSS')</script>
a <b/> [link](javascript:alert('XSS'))
EOF
$expected = <<'EOF';
<!-- raw HTML omitted -->
<p>a <!-- raw HTML omitted --> <a href="">link</a></p>
EOF
is(CommonMark->markdown_to_html($md, OPT_SAFE), $expected, 'SAFE');

$md = "a\xC0b";
Encode::_utf8_on($md);
is(CommonMark->markdown_to_html($md, OPT_VALIDATE_UTF8), "<p>a\x{FFFD}b</p>\n",
'VALIDATE_UTF8');
my $html = CommonMark->markdown_to_html($md);
Encode::_utf8_off($html);
is($html, "<p>a\xC0b</p>\n", 'without VALIDATE_UTF8');

$md = q{"a" -- 'b' --- c};
$expected = <<"EOF";
<p>\x{201C}a\x{201D} \x{2013} \x{2018}b\x{2019} \x{2014} c</p>
EOF
is(CommonMark->markdown_to_html($md, OPT_SMART), $expected, 'SMART');

0 comments on commit 73bc866

Please sign in to comment.