Klaus Eichner > XML-Parsepp-Testgen-0.02 > XML::Parsepp::Testgen

Download:
XML-Parsepp-Testgen-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

XML::Parsepp::Testgen - Generate testcases for XML::Parsepp

SYNOPSIS ^

XML::Parsepp::Testgen uses XML::Parser to generate testcases. xml_2_test converts from XML to testfiles. The input ist a list of XML documents, separated by the special line "#! ===". The output is a valid test script.

The inverse function is also available: test_2_xml takes a previously generated testfile and extracts the original XML.

  use XML::Parsepp::Testgen qw(xml_2_test test_2_xml);

xml_2_test ^

xml_2_test (string)

Here is an example to convert from a fixed string xml:

  use XML::Parsepp::Testgen qw(xml_2_test);

  my $xml =
    qq|#! Testdata for XML::Parsepp\n|.
    qq|#! Ver 0.01\n|.
    qq|<?xml version="1.0" encoding="ISO-8859-1"?>\n|.
    qq|<!DOCTYPE dialogue [\n|.
    qq|  <!ENTITY nom0 "<data>y<item>y &nom1; zz</data>">\n|.
    qq|  <!ENTITY nom1 "<abc>def</abc></item>">\n|.
    qq|]>\n|.
    qq|<root>&nom0;</root>\n|.
    qq|#! ===\n|.
    qq|<?xml version="1.0" encoding="ISO-8859-1"?>\n|.
    qq|<!DOCTYPE dialogue\n|.
    qq|[\n|.
    qq|  <!ENTITY nom1 "aa &nom2; tt &nom4; bb">\n|.
    qq|  <!ENTITY nom2 "c <xx>abba</xx> c tx <ab> &nom3; dd">\n|.
    qq|  <!ENTITY nom3 "dd </ab> <yy>&nom4;</yy> ee">\n|.
    qq|  <!ENTITY nom4 "gg">\n|.
    qq|]>\n|.
    qq|<root>hh &nom1; ii</root>\n|;

  print xml_2_test(\$xml);

xml_2_test (file name)

If your xml is in an external file, you can convert that, too:

  use XML::Parsepp::Testgen qw(xml_2_test);

  print xml_2_test('data.xml');

xml_2_test (file handle)

Or you have a file handle of a previously opened XML file:

  use XML::Parsepp::Testgen qw(xml_2_test);

  open my $fh, '<', 'data.xml' or die "Error: $!";

  print xml_2_test($fh);

  close $fh;

test_2_xml ^

test_2_xml (string)

Here is an example to convert from a fixed string test script:

  use XML::Parsepp::Testgen qw(test_2_xml);

  my $test =
    qq|use 5.014;\n|.
    qq|use warnings;\n|.
    qq|# Generate Tests for XML::Parsepp\n|.
    qq|# No of get_result is 2\n|.
    qq|get_result(\$XmlParser,\n|.
    qq|           q{<?xml version="1.0" encoding="ISO-8859-1"?>}.qq{\\n},\n|.
    qq|           q{<!DOCTYPE dialogue [}.qq{\\n},\n|.
    qq|           q{  <!ENTITY nom0 "<data>y<item>y &nom1; zz</data>">}.qq{\\n},\n|.
    qq|           q{  <!ENTITY nom1 "<abc>def</abc></item>">}.qq{\\n},\n|.
    qq|           q{]>}.qq{\\n},\n|.
    qq|           q{<root>&nom0;</root>}.qq{\\n},\n|.
    qq|);\n|.
    qq|get_result(\$XmlParser,\n|.
    qq|           q{<?xml version="1.0" encoding="ISO-8859-1"?>}.qq{\\n},\n|.
    qq|           q{<!DOCTYPE dialogue}.qq{\\n},\n|.
    qq|           q{[}.qq{\\n},\n|.
    qq|           q{  <!ENTITY nom1 "aa &nom2; tt &nom4; bb">}.qq{\\n},\n|.
    qq|           q{  <!ENTITY nom2 "c <xx>abba</xx> c tx <ab> &nom3; dd">}.qq{\\n},\n|.
    qq|           q{  <!ENTITY nom3 "dd </ab> <yy>&nom4;</yy> ee">}.qq{\\n},\n|.
    qq|           q{  <!ENTITY nom4 "gg">}.qq{\\n},\n|.
    qq|           q{]>}.qq{\\n},\n|.
    qq|           q{<root>hh &nom1; ii</root>}.qq{\\n},\n|.
    qq|);\n|.
    qq|\n|.
    qq|sub get_result {\n|.
    qq|}\n|;

  print test_2_xml(\$test);

test_2_xml (file name)

If your test script is in an external file, you can convert that, too:

  use XML::Parsepp::Testgen qw(test_2_xml);

  print test_2_xml('test.t');

xml_2_test (file handle)

Or you have a file handle of a previously opened test file:

  use XML::Parsepp::Testgen qw(test_2_xml);

  open my $fh, '<', 'test.t' or die "Error: $!";

  print test_2_xml($fh);

  close $fh;

AUTHOR ^

Klaus Eichner <klaus03@gmail.com>

COPYRIGHT AND LICENSE ^

Copyright (C) 2012 by Klaus Eichner

All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the artistic license 2.0, see http://www.opensource.org/licenses/artistic-license-2.0.php

SEE ALSO ^

XML::Parsepp, XML::Parser.

syntax highlighting: