File: 21saxini.t

package info (click to toggle)
libxml-sax-perl 0.99%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 556 kB
  • ctags: 218
  • sloc: perl: 2,374; sh: 127; xml: 121; makefile: 5
file content (63 lines) | stat: -rw-r--r-- 1,894 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;
use Test;
plan tests => 8;

use File::Path;
use Fatal qw(open close chdir mkpath);
use XML::SAX;
use vars qw(*FILE);

ok(@{XML::SAX->parsers}, 0);
ok(XML::SAX->add_parser(q(XML::SAX::PurePerl)));
ok(@{XML::SAX->parsers}, 1);

rmtree('t/lib', 0, 0);
mkpath('t/lib', 0, 0777);

push @INC, 't/lib';
write_file('t/lib/TestParserPackage.pm', <<EOT);
package TestParserPackage;
use XML::SAX::Base;
\@ISA = qw(XML::SAX::Base);
sub new { 
    return bless {}, shift
}
sub supported_features {
    return ('http://axkit.org/sax/frobnosticating');
}
1;
EOT

my $parser;

# Test we can get TestParserPackage out
write_file('t/lib/SAX.ini', 'ParserPackage = TestParserPackage');
$parser = XML::SAX::ParserFactory->parser();
ok(ref($parser), "TestParserPackage", "Parser was not TestParserPackage");

# Test we can get XML::SAX::PurePerl out
write_file('t/lib/SAX.ini', 'ParserPackage = XML::SAX::PurePerl');
$parser = XML::SAX::ParserFactory->parser();
ok(ref($parser), "XML::SAX::PurePerl", "Parser was not XML::SAX::PurePerl");

# Test we can ask for a frobnosticating parser, but not get it
write_file('t/lib/SAX.ini', 'http://axkit.org/sax/frobnosticating = 1');
$parser = XML::SAX::ParserFactory->parser();
ok(ref($parser), "XML::SAX::PurePerl", "Parser was not PurePerl (frobnosticating)");

# Test we can ask for a frobnosticating parser, and get it
XML::SAX->add_parser('TestParserPackage');
$parser = XML::SAX::ParserFactory->parser();
ok(ref($parser), "TestParserPackage", "Parser was not TestParserPackage (frobnosticating)");

# Test we can get a namespaces parser
write_file('t/lib/SAX.ini', 'http://xml.org/sax/features/namespaces = 1');
$parser = XML::SAX::ParserFactory->parser();
ok(ref($parser), "XML::SAX::PurePerl", "Parser was not PurePerl (namespaces)");

sub write_file {
    my ($file, $data) = @_;
    open(FILE, ">$file");
    print FILE $data, "\n";
    close FILE;
}