Shlomi Fish avatar Shlomi Fish committed 42319c1

Test for invalid XML.

Comments (0)

Files changed (3)

XML-GrammarBase/MANIFEST

 t/00-load.t
 t/data/screenplay-xml/xml/with-tags-inside-paragraphs.xml
 t/data/fiction-xml.rng
+t/data/fiction-xml-invalid-test.xml
 t/data/fiction-xml-test.xml
 t/pod-coverage.t
 t/pod.t

XML-GrammarBase/t/data/fiction-xml-invalid-test.xml

+<?xml version='1.0' encoding='utf-8'?>
+<document xmlns="http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/" xmlns:xlink="http://www.w3.org/1999/xlink" version="0.2">
+    <head>
+    </head>
+    <body xml:id="index">
+    <title>David vs. Goliath - Part I</title>
+    <section xml:id="top">
+    <title>The Top Section</title>
+    <!-- David has Green hair here -->
+    <foobar_non_existing_tag />
+    <p>
+    King <span xlink:href="http://en.wikipedia.org/wiki/David">David</span> and Goliath were standing by each other.
+    </p>
+    <p>
+    David said unto Goliath: "I will shoot you. I <b>swear</b> I will"
+    </p>
+    <section xml:id="goliath">
+    <title>Goliath's Response</title>
+    <!-- Goliath has to reply to that. -->
+    <p>
+    Goliath was not amused.
+    </p>
+    <p>
+    He said to David: "Oh, really. <i>David</i>, the red-headed!".
+    </p>
+    <p>
+    David started listing Goliath's disadvantages:
+    </p>
+    <blockquote xml:lang="fr-FR" xml:id="my_blockquote">
+    <ol>
+    <li>
+    <p>
+    You're slow.
+    </p>
+    </li>
+    <li>
+    <p>
+    You're big.
+    </p>
+    </li>
+    <li>
+    <p>
+    You're stupid.
+    </p>
+    </li>
+    </ol>
+    <p>
+    Goliath was insulted and told David he should use bullets for the
+    points, instead:
+    </p>
+    <ul>
+    <li>
+    <p>
+    David.
+    </p>
+    </li>
+    <li>
+    <p>
+    Saul.
+    </p>
+    </li>
+    <li>
+    <p>
+    Jonathan.
+    </p>
+    </li>
+    <li>
+    <p>
+    Michal.
+    </p>
+    </li>
+    <li>
+    <p>
+    Meyrav.
+    </p>
+    </li>
+    </ul>
+    </blockquote>
+    </section>
+    </section>
+</body>
+</document>

XML-GrammarBase/t/rng.t

 use strict;
 use warnings;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 
 package MyGrammar::RNG;
 
 
 package main;
 
+sub _slurp
+{
+    my $filename = shift;
+
+    open my $in, '<', $filename
+        or die "Cannot open '$filename' for slurping - $!";
+
+    binmode $in, ':encoding(utf8)';
+
+    local $/;
+    my $contents = <$in>;
+
+    close($in);
+
+    return $contents;
+}
+
 {
     my $rng = MyGrammar::RNG->new();
 
     is ($@, '', 'No exception was thrown.');
 }
 
-sub _slurp
-{
-    my $filename = shift;
-
-    open my $in, '<', $filename
-        or die "Cannot open '$filename' for slurping - $!";
-
-    binmode $in, ':encoding(utf8)';
-
-    local $/;
-    my $contents = <$in>;
-
-    close($in);
-
-    return $contents;
-}
 
 {
     my $rng = MyGrammar::RNG->new();
     # TEST
     is ($@, '', 'No exception was thrown.');
 }
+
+{
+    my $rng = MyGrammar::RNG->new();
+
+    my $xml_parser = XML::LibXML->new();
+    $xml_parser->validation(0);
+
+    my $dom = $xml_parser->parse_file(
+        File::Spec->catfile(
+            File::Spec->curdir(), "t", "data", "fiction-xml-invalid-test.xml"
+        )
+    );
+    eval {
+        $rng->rng_validate_dom($dom);
+    };
+
+    # TEST
+    ok ($@, 'An invalid XML exception was thrown.');
+}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.