### ----------------------------------------------------
### -- LibXML
### -- Licenses: Artistic-2.0
### -- Authors: David Warring
### -- File: t/02parse.t
### ----------------------------------------------------
### -- Chunk 2 of 2
 second time it must not fail.
    my $doc2   = $parser.parse: :string( $xmldoc );
    is $doc2.documentElement().string-value(), " test ";
}

subtest 'Perl ticket #7913', {
    my $xmldoc = q:to<EOXML>;
    <!DOCTYPE X SYSTEM "samples/ext_ent.dtd">
    <X>&foo;</X>
    EOXML
    my LibXML $parser .= new();

    $parser.load-ext-dtd = True;

    # first time it should work
    my $doc    = $parser.parse: :string( $xmldoc );
    is $doc.documentElement.string-value(), " test ";

    # lets see if load_ext_dtd = False works
    $parser.load-ext-dtd = False;
    $parser.expand-entities = True;
    my $doc2;
    dies-ok {
       $doc2 = $parser.parse: :string( $xmldoc );
    };

    $parser.validation = False;
    $parser.load-ext-dtd = False;
    my LibXML::Document $doc3;
    lives-ok {
       $doc3 = $parser.parse: :file( "samples/article_external_bad.xml" );
    };

    $parser.validation = True;
    $parser.load-ext-dtd = True;
    dies-ok {
       $doc3 = $parser.parse: :file( "samples/article_external_bad.xml" );
    };

}

subtest 'XML URI and baseURI', {

   my LibXML $parser .= new();

   my LibXML::Document $doc = $parser.parse: :string('<foo xml:base="foo.xml"/>'), :URI<bar.xml>;
   my LibXML::Element $el = $doc.documentElement;
   is $doc.URI, "bar.xml", "xml uris";
   is $doc.baseURI, "bar.xml", "xml uris";
   is $el.baseURI, "foo.xml", "xml uris";

   $doc.URI = "baz.xml";
   is $doc.URI, "baz.xml", "xml uris";
   is $doc.baseURI, "baz.xml", "xml uris";
   is $el.baseURI, "foo.xml", "xml uris";

   $doc.baseURI = "bag.xml";
   is $doc.URI, "bag.xml", "xml uris";
   is $doc.baseURI, "bag.xml", "xml uris";
   is $el.baseURI, "foo.xml", "xml uris";

   $el.baseURI = "bam.xml";
   is $doc.URI, "bag.xml", "xml uris";
   is $doc.baseURI, "bag.xml", "xml uris";
   is $el.baseURI, "bam.xml", "xml uris";

}

subtest 'HTML URI and baseURI', {

   my LibXML $parser .= new();

   my LibXML::Document $doc = $parser.parse: :html, :string('<html><head><base href="foo.html"></head><body></body></html>'), :URI<bar.html>;
   my $el = $doc.documentElement;
   is $doc.URI, "bar.html", "html uris";
   is $doc.baseURI, "foo.html", "html uris";
   is $el.baseURI, "foo.html", "html uris";

   $doc.URI = "baz.html";
   is $doc.URI, "baz.html", "html uris";
   is $doc.baseURI, "foo.html", "html uris";
   is $el.baseURI, "foo.html", "html uris";

}

subtest 'Perl fossil', {
    my LibXML $parser .= new();
    my $file = 't/data/chinese.xml';
    lives-ok {
        $parser.parse: :$file;
    };
    todo ":io test failing on Windows" if $*DISTRO.is-win;
    lives-ok {
        $parser.parse: :io($file);
    };
   
}


