1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
use strict;
use warnings;
use Symbol;
use Test::More tests => 11;
BEGIN {
use_ok('CommonMark');
}
{
package MyHandle;
sub TIEHANDLE { return bless({}, shift); }
}
my $handle = Symbol::gensym;
tie *$handle, 'MyHandle';
eval {
CommonMark->parse_file(*$handle);
};
like($@, qr/parse_file: file is not a file handle/,
'parse_file with tied handle dies');
{
package MyClass;
sub new { return bless({}, shift); }
}
my $obj = MyClass->new;
eval {
CommonMark::Node::get_type($obj);
};
like($@, qr/get_type: node is not of type CommonMark::Node/,
'get_type on wrong class dies');
my $doc = CommonMark->parse_document('*text*');
my $paragraph = $doc->first_child;
my $emph = $paragraph->first_child;
my $text = $emph->first_child;
SKIP: {
skip('Crashes for some reason', 3)
if $^O eq 'MSWin32' && $^V >= 5.018 && $^V < 5.022;
eval {
$text->insert_after($emph);
};
like($@, qr/insert_after: invalid operation/, 'insert_after dies');
eval {
$emph->set_list_tight(1);
};
like($@, qr/set_list_tight: invalid operation/, 'set_list_tight dies');
eval {
$paragraph->set_url('/url');
};
like($@, qr/set_url: invalid operation/, 'set_url dies');
}
eval {
$doc->render();
};
like($@, qr/must provide format/, 'render without format');
eval {
$doc->render(format => 'non_existent');
};
like($@, qr/invalid format/, 'render with invalid format');
eval {
my $paragraph = CommonMark->create_paragraph(
children => [
CommonMark->create_text(literal => 'text'),
],
text => 'text',
);
};
like($@, qr/can't set both children and text/,
'create_text with children and text');
eval {
my $doc = CommonMark->parse(smart => 1);
};
like($@, qr/must provide either string or file/, 'parse without input');
eval {
my $doc = CommonMark->parse(string => 'md', file => \*STDIN);
};
like($@, qr/can't provide both string and file/, 'parse with string and file');
|