diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2007-11-20 14:28:05 +0000 |
---|---|---|
committer | <> | 2013-08-08 17:01:04 +0000 |
commit | c97631728ce7d6d3f4692a56c3cda7476b42a968 (patch) | |
tree | 8c00053771ccae41a737eecd072dbb3cd8b06fdd /t/external_ent.t | |
download | perl-xml-parser-master.tar.gz |
Imported from /home/lorry/working-area/delta_perl-xml-parser/XML-Parser-2.36.tar.gz.HEADXML-Parser-2.36master
Diffstat (limited to 't/external_ent.t')
-rw-r--r-- | t/external_ent.t | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/t/external_ent.t b/t/external_ent.t new file mode 100644 index 0000000..6d62aff --- /dev/null +++ b/t/external_ent.t @@ -0,0 +1,70 @@ +BEGIN {print "1..5\n";} +END {print "not ok 1\n" unless $loaded;} +use XML::Parser; +$loaded = 1; +print "ok 1\n"; + +################################################################ +# Check default external entity handler + + +my $txt = ''; + +sub txt { + my ($xp, $data) = @_; + + $txt .= $data; +} + +my $docstring =<<'End_of_XML;'; +<!DOCTYPE foo [ + <!ENTITY a SYSTEM "a.ent"> + <!ENTITY b SYSTEM "b.ent"> + <!ENTITY c SYSTEM "c.ent"> +]> +<foo> +a = "&a;" +b = "&b;" + + +And here they are again in reverse order: +b = "&b;" +a = "&a;" + +</foo> +End_of_XML; + +open(ENT, '>a.ent') or die "Couldn't open a.ent for writing"; +print ENT "This ('&c;') is a quote of c"; +close(ENT); + +open(ENT, '>b.ent') or die "Couldn't open b.ent for writing"; +print ENT "Hello, I'm B"; +close(ENT); + +open(ENT, '>c.ent') or die "Couldn't open c.ent for writing"; +print ENT "Hurrah for C"; +close(ENT); + +my $p = new XML::Parser(Handlers => {Char => \&txt}); + +$p->parse($docstring); + +my %check = (a => "This ('Hurrah for C') is a quote of c", + b => "Hello, I'm B"); + +my $tstcnt = 2; + +while ($txt =~ /([ab]) = "(.*)"/g) { + my ($k, $v) = ($1, $2); + + unless ($check{$k} eq $v) { + print "not "; + } + print "ok $tstcnt\n"; + $tstcnt++; +} + +unlink('a.ent'); +unlink('b.ent'); +unlink('c.ent'); |