App-sdview

 view release on metacpan or  search on metacpan

t/11parser-markdown.t  view on Meta::CPAN


subtest "Alternate headings" => sub {
   my @p = App::sdview::Parser::Markdown->new->parse_string( <<"EOMARKDOWN" );
Heading
=======

The heading paragraph here.

Content
-------

The content with **bold** and `code` in it.
EOMARKDOWN

   is( scalar @p, 4, 'Received 4 paragraphs' );

   is( $p[0]->type, "head1", 'p[0] type' );
   is( $p[0]->text, "Heading", 'p[0] text' );

   is( $p[1]->type, "plain", 'p[1] type' );
   is( $p[1]->text, "The heading paragraph here.", 'p[1] text' );

   is( $p[2]->type, "head2", 'p[2] type' );
   is( $p[2]->text, "Content", 'p[2] text' );

   is( $p[3]->type, "plain", 'p[3] type' );
   is( $p[3]->text, "The content with bold and code in it.", 'p[3] text' );
};

subtest "Formatting" => sub {
   my @p = App::sdview::Parser::Markdown->new->parse_string( <<"EOMARKDOWN" );
**bold** __bold__

*italic* _italic_

`code` `code_with_unders`

[link](target://)

~~strikethrough~~
EOMARKDOWN

   is( scalar @p, 5, 'Received 5 paragraphs' );

   is( $p[0]->text, "bold bold", 'bold text' );
   ok( $p[0]->text->get_tag_at( 0, "bold" ), 'bold tag' );

   is( $p[1]->text, "italic italic", 'italic text' );
   ok( $p[1]->text->get_tag_at( 0, "italic" ), 'italic tag' );

   is( $p[2]->text, "code code_with_unders", 'code text' );
   ok( $p[2]->text->get_tag_at( 0, "monospace" ), 'code tag' );

   is( $p[3]->text, "link", 'link text' );
   is( $p[3]->text->get_tag_at( 0, "link" ), { uri => "target://" }, 'link tag' );

   is( $p[4]->text, "strikethrough", 'strikethrough text' );
   ok( $p[4]->text->get_tag_at( 0, "strikethrough" ), 'strikethrough tag' );
};

subtest "HTML entities get decoded" => sub {
   my @p = App::sdview::Parser::Markdown->new->parse_string( <<"EOMARKDOWN" );
Some content with non-breaking&nbsp;spaces in it.

Text &ndash; with HTML entities
EOMARKDOWN

   is( scalar @p, 2, 'Received 2 paragraphs' );

   is( $p[0]->type, "plain", 'p[0] type' );
   is( $p[0]->text, "Some content with non-breaking\xA0spaces in it.", 'p[0] text' );

   is( $p[1]->text, "Text \x{2013} with HTML entities", 'p[1] text' );
};

subtest "Verbatim language" => sub {
   my @p = App::sdview::Parser::Markdown->new->parse_string( <<"EOPOD" );
# EXAMPLE

```perl
use v5.14;
use warnings;
say "Hello, world";
```

EOPOD

   is( scalar @p, 2, 'Received 2 paragraphs' );

   is( $p[0]->text, "EXAMPLE", 'p[0] text' );

   is( $p[1]->text, qq(use v5.14;\nuse warnings;\nsay "Hello, world";), 'p[1] text' );
   is( $p[1]->language, "perl", 'p[1] language' );
};

subtest "Verbatim trimming" => sub {
   my @p = App::sdview::Parser::Markdown->new->parse_string( <<"EOPOD" );
# EXAMPLE

    use v5.14;
    use warnings;
    say "Hello, world";

EOPOD

   is( scalar @p, 2, 'Received 2 paragraphs' );

   is( $p[0]->text, "EXAMPLE", 'p[0] text' );

   is( $p[1]->text, qq(use v5.14;\nuse warnings;\nsay "Hello, world";), 'p[1] text' );
};

subtest "Bullet lists" => sub {
   my @p = App::sdview::Parser::Markdown->new->parse_string( <<"EOMARKDOWN" );
* First
* Second

   * Third
EOMARKDOWN

   is( scalar @p, 1, 'Received 1 paragraph' );



( run in 2.398 seconds using v1.01-cache-2.11-cpan-c221a9de4ec )