1# 06parseliteral.t -- ...
2#
3# $Id: 21parsestring.t,v 1.1 2006/03/06 08:51:59 tbe Exp $
4
5use strict;
6use warnings;
7use Test::More tests => 13;
8use Test::Exception;
9use File::Spec qw();
10
11use constant NO_DOCTYPE   => File::Spec->catfile('samples', 'no-doctype.xml');
12use constant TEST_CATALOG => File::Spec->catfile('samples', 'test.soc');
13
14BEGIN { use_ok('SGML::Parser::OpenSP') };
15require_ok('SGML::Parser::OpenSP');
16my $p = SGML::Parser::OpenSP->new;
17isa_ok($p, 'SGML::Parser::OpenSP');
18
19#########################################################
20## Parse using ->parse_string().
21#########################################################
22
23sub TestHandler1::new { bless{ok1=>0,ok2=>0,ok3=>0,ok4=>0,ok5=>0,
24                              ok6=>0,ok7=>0,ok8=>0,ok9=>0,oka=>0},shift }
25sub TestHandler1::start_element {
26    my $s = shift;
27    my $e = shift;
28
29    return unless defined $s;
30    return unless defined $e;
31
32    $s->{ok1}++ if UNIVERSAL::isa($s, 'TestHandler1');
33
34    # Name
35    $s->{ok2}++ if exists $e->{Name};
36    $s->{ok3}++ if $e->{Name} =~ /no-doctype/i;
37
38    # Attributes
39    $s->{ok4}++ if exists $e->{Attributes};
40    $s->{ok5}++ if UNIVERSAL::isa($e->{Attributes}, "HASH");
41    $s->{ok6}++ if scalar(keys(%{$_[1]->{Attributes}})) == 0;
42
43    # Included
44    $s->{ok7}++ if exists $e->{Included};
45    $s->{ok8}++ if $e->{Included} == 0;
46
47    # ContentType
48    $s->{ok9}++ if exists $e->{ContentType};
49}
50
51my $h1 = TestHandler1->new;
52
53$p->handler($h1);
54lives_ok { $p->parse_string("<no-doctype></no-doctype>") }
55  'parsing with parse_string()';
56
57ok($h1->{ok1}, 'self to handler');
58ok($h1->{ok2}, 'has name');
59ok($h1->{ok3}, 'proper name');
60ok($h1->{ok4}, 'has attrs');
61ok($h1->{ok5}, 'attrs hash ref');
62ok($h1->{ok6}, 'proper attrs');
63ok($h1->{ok7}, 'has included');
64ok($h1->{ok8}, 'included == 0');
65ok($h1->{ok9}, 'has content type');
66