Commits

Anonymous committed bfaca31

Test $parser->validation(1)

Comments (0)

Files changed (1)

 use XML::LibXML;
 ok(1);
 
-my $dtdstr = do {
-    local $/;
+my $dtdstr;
+{
+    local $/; local *DTD;
     open(DTD, 'example/test.dtd') || die $!;
-    my $str = <DTD>;
+    $dtdstr = <DTD>;
+    $dtdstr =~ s/\r//g;
+    $dtdstr =~ s/[\r\n]*$//;
     close DTD;
-    $str;
-};
+}
 ok($dtdstr);
 
 {
-# parse a DTD from a SYSTEM ID
-my $dtd = XML::LibXML::Dtd->new('ignore', 'example/test.dtd');
-ok($dtd);
+    # parse a DTD from a SYSTEM ID
+    my $dtd = XML::LibXML::Dtd->new('ignore', 'example/test.dtd');
+    ok($dtd);
+    my $newstr = $dtd->toString;
+    $newstr =~ s/\r//g;
+    $newstr =~ s/^.*?\n//;
+    $newstr =~ s/\n^.*\Z//m;
+    ok($newstr, $dtdstr);
 }
 
 {
-# parse a DTD from a string
-my $dtd = XML::LibXML::Dtd->parse_string($dtdstr);
-ok($dtd);
+    # parse a DTD from a string
+    my $dtd = XML::LibXML::Dtd->parse_string($dtdstr);
+    ok($dtd);
 }
 
 {
 }
 
 {
-# validate with the DTD
-my $dtd = XML::LibXML::Dtd->parse_string($dtdstr);
-ok($dtd);
-my $xml = XML::LibXML->new->parse_file('example/article.xml');
-ok($xml);
-ok($xml->is_valid($dtd));
-ok($xml->validate($dtd));
+    # validate with the DTD
+    my $dtd = XML::LibXML::Dtd->parse_string($dtdstr);
+    ok($dtd);
+    my $xml = XML::LibXML->new->parse_file('example/article.xml');
+    ok($xml);
+    ok($xml->is_valid($dtd));
+    eval { $xml->validate($dtd) }; # throws exception
+    ok( !$@ );
 }
 
 {
-# validate a bad document
-my $dtd = XML::LibXML::Dtd->parse_string($dtdstr);
-ok($dtd);
-my $xml = XML::LibXML->new->parse_file('example/article_bad.xml');
-ok(!$xml->is_valid($dtd));
-eval {
-    $xml->validate($dtd);
-    ok(0); # shouldn't get here
-};
-ok($@);
+    # validate a bad document
+    my $dtd = XML::LibXML::Dtd->parse_string($dtdstr);
+    ok($dtd);
+    my $xml = XML::LibXML->new->parse_file('example/article_bad.xml');
+    ok(!$xml->is_valid($dtd));
+    eval {
+        $xml->validate($dtd);
+        ok(0); # shouldn't get here
+    };
+    ok($@);
+
+    my $parser = XML::LibXML->new();
+    ok($parser->validation(1));
+    # this one is OK as it's well formed (no DTD)
+    $parser->parse_file('example/article_bad.xml');
+    eval {
+        $parser->parse_file('example/article_internal_bad.xml');
+    };
+    ok($@);
 }
 
 # this test fails under XML-LibXML-1.00 with a segfault because the
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.