Test::Markdent - High level test functions for Markdent


Markdent documentation  | view source Contained in the Markdent distribution.

Index


NAME

Top

Test::Markdent - High level test functions for Markdent

VERSION

Top

version 0.17

SYNOPSIS

Top

  use Test::Markdent;

  my $text = <<'EOF';
  Some %*em text*%
  EOF

  my $expect = [
      { type => 'paragraph' },
      [
          {
              type => 'text',
              text => 'Some %',
          }, {
              type => 'emphasis',
          },
          [
              {
                  type => 'text',
                  text => 'em text',
              },
          ], {
              type => 'text',
              text => "%\n",
          },
      ],
  ];

  parse_ok( $text, $expect, 'emphasis markup surrounded by brackets' );

DESCRIPTION

Top

This module provides some helper functions for testing Markdent at a higher-level. In particular, it helps generate parse trees or HTML output from a parse.

FUNCTIONS

Top

This class exports the following functions:

parse_ok( $markdown, $tree, $description )

This function takes some Markdown text, an expected output tree, and a description of the test.

The tree is generated by using Markdent::Handler::MinimalTree, and then using Tree::Simple::Visitor::ToNestedArray to covert the tree to a data structure.

You can use the tree_from_handler function to get the tree. You may want to use Data::Dumper to examine a few trees to understand exactly what this looks like.

You can also pass an optional hash reference as the first parameter to this function. This hash reference will be used as parameters when creating the Markdent::Parser object.

This hash reference can also include a "handler_class" parameter, which you can use to override the default of Markdent::Handler::MinimalTree.

If you set the MARKDENT_TEST_VERBOSE environment variable to a true value, then this function will use Data::Dumper to output the tree with Test::More::diag().

html_output_ok( $markdown, $html, $description )

This function takes some Markdown text, the expected HTML output, and a description of the test.

Internally, this function uses HTML::Tidy to tidy both the Markdent-generated HTML and the HTML you pass in. This ensures that the test is comparing the HTML on a semantic level.

The comparison itself is done using eq_or_diff from Test::Differences.

You can also pass an optional hash reference as the first parameter to this function. This hash reference will be used as parameters when creating the Markdent::Parser object.

If you set the MARKDENT_TEST_VERBOSE environment variable to a true value, then this function will output the generated html (before tidying) with Test::More::diag().

tree_from_handler($handler)

Given a Markdent::Handler::MinimalTree object, this function returns a data structure built using Tree::Simple::Visitor::ToNestedArray.

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

Top


Markdent documentation  | view source Contained in the Markdent distribution.