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

NAME

MarpaX::Tester - Given a Marpa grammar and one or more test cases, generates output

VERSION

Version 0.02

SYNOPSIS

When working with parsers, I find test-driven development to be the quickest and most effective way of getting where I want to go. (Also when working with anything else, but we're talking about parsers right now.) This module does that.

    use MarpaX::Tester;

    my $r = MarpaX::Tester->new($grammar);
    my $results = $r->test($text);
    $results = $r->test([$text1, $text2]);
    

There's also a command-line utility to produce conveniently formatted versions for posting and gisting.

The results are a hashref; "grammar" is the text of the grammar in question, "status" is binary indicating OK or not OK at the grammar parsing level (i.e. has Marpa accepted the grammar itself), "error" is the error raised by Marpa, if the status is false. If the error has a line and column specified (not all errors do), then the text of the grammar will have an extra line inserted pointing at the error with a '........^' format.

Either way, "ver" is the Marpa version used to generate this test.

(These are already available immediately after the grammar is defined, of course, and can be retrieved at that stage with <$r-status>> and <$r-result>>, but to keep things dead simple, you can still throw your test cases at an invalid grammar - they just won't be parsed, obviously.)

So if there is a parse error, you get a structure like this:

   {
       grammar => '...',
       status  => 0,
       error   => '...',
   }
   

If the grammar succeeds in compiling, then results are in "results", either a hashref or an array of hashrefs, like this:

   {
       grammar => '...',
       status  => 1,
       results => {
                     test   => '...',
                     status => 0,
                     error  => '...',
                  },
   }
   

or conversely like this:

   {
       grammar => '...',
       status  => 1,
       results => {
                     test      => '...',
                     status    => 1,
                     parse     => '...',
                     parse_val => ...
                  },
   }
   

And if you pass in a list of tests, you'll get this:

   {
       grammar => '...',
       status  => 1,
       results => [
                    {
                        test   => '...',
                        status => 0,
                        error  => '...',
                    },
                    {
                        test      => '...',
                        status    => 1,
                        parse     => '...',
                        parse_val => ...,
                    }
                  ],
   }

In successful tests, you get both the parse_val (the actual value returned from the parse) and the Data::Dumper text version in "parse". This makes it easy for the command-line utility to use the Template Toolkit to format the results.

METHODS

new

Given a string, makes a grammar and recognizer and stashes them for later use, or saves the error after convenient formatting.

test

Tests one or more texts and returns the results in the structure described above.

status

Returns the BNF parse status of the original grammar (I know, two levels of parsing make it hard to distinguish - this is the status of the grammar specification itself, not the status of your test cases).

result

Returns the last result from the test object - either the parse error or the last test set.

AUTHOR

Michael Roberts, <michael at vivtek.com>

BUGS

Please report any bugs or feature requests to bug-marpax-tester at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MarpaX-Tester. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc MarpaX::Tester

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2014 Michael Roberts.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.