The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Markdent - High level test functions for Markdent

VERSION

version 0.15

SYNOPSIS

  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

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

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

  Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Dave Rolsky.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.