logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Test::XML::Twig - Test XML::Twig handlers

Author

       Dominic Mitchell, <cpan2 (at) semantico.com>

Description

       This module is for testing XML::Twig handlers.

Functions

       All functions are exported.

       get_twig ( INPUT [, ARGS ] )
           Return  a parsed twig of INPUT, or undef on parse failure.  Optionally, ARGS may be supplied as a set
           of hash-like parameters to be passed into the twig constructor.

       test_twig_handler ( HANDLER, INPUT, EXPECTED, TESTNAME [, COND ] )
           Parse INPUT, using HANDLER as a twig_handler (i.e: it gets called  after  the  parse  tree  has  been
           built).   Tests  that  the  result  is the same as EXPECTED (which can be either a string of XML or a
           quoted regex).  HANDLER must be a code ref.

           Optionally, COND can be supplied.  Instead of the handler being  called  with  the  root  element  of
           INPUT, COND will be used with first_child() to select an alternative element.

           Returns true / false depending upon test success.

       test_twig_handlers ( ARGS, INPUT, EXPECTED, TESTNAME )
           This  is  similar  to test_twig_handler(), but with more flexibility.  The first argument, ARGS, is a
           hash reference which can be used to specify any of the ordinary  parameters  to  twig's  constructor.
           This lets you test things like start_tag_handlers, as well as multiple twig_handlers together.

Name

       Test::XML::Twig - Test XML::Twig handlers

See Also

       Test::More, Test::XML, XML::Twig.

Synopsis

         use Test::XML::Twig tests => 2;
         use My::Twig qw( handler );

         test_twig_handler(
             \&handler,
             '<foo/>', '<bar/>',
             'turns foo to bar',
         );

         test_twig_handlers(
             { twig_handlers => { 'foo' => \&handler } },
             '<foo/>', '<bar/>',
             'turns foo into bar',
         );