File: 17splitmessage.t

package info (click to toggle)
libsgml-parser-opensp-perl 0.994-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 408 kB
  • sloc: perl: 225; makefile: 10
file content (204 lines) | stat: -rwxr-xr-x 4,410 bytes parent folder | download | duplicates (4)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# 17splitmessage.t -- ...
#
# $Id: 17splitmessage.t,v 1.2 2004/10/01 23:21:19 hoehrmann Exp $

use strict;
use warnings;
use Test::More tests => 18;
use Test::Exception;
use File::Spec qw();

use constant NO_DOCTYPE   => File::Spec->catfile('samples', 'no-doctype.xml');
use constant TEST_CATALOG => File::Spec->catfile('samples', 'test.soc');

BEGIN { use_ok('SGML::Parser::OpenSP') };
BEGIN { use_ok('SGML::Parser::OpenSP::Tools') };

require_ok('SGML::Parser::OpenSP');
require_ok('SGML::Parser::OpenSP::Tools');

my $p = SGML::Parser::OpenSP->new;
isa_ok($p, 'SGML::Parser::OpenSP');

#########################################################
## newlines in enum attribute
#########################################################

sub TestHandler12::new{bless{p=>$_[1],ok1=>0,ok2=>0,ok3=>0,ok4=>0,
                             ok5=>0,ok6=>0,ok7=>0,ok8=>0},shift}
sub TestHandler12::error
{
    my $s = shift;
    my $e = shift;
    my $p = $s->{p};
    
    return unless defined $s and
                  defined $e and
                  defined $p;
                  
    my $l = $p->get_location;
    
    return unless defined $l;
    $s->{ok1}++;
    my $m;
    
    eval
    {
        $m = $p->split_message($e);
    };
    
    return if $@;
    $s->{ok2}++;
    
    if ($m->{primary_message}{Number} == 122)
    {
        $s->{ok3}++ if $m->{primary_message}{ColumnNumber} == 8;
        $s->{ok4}++ if $m->{primary_message}{LineNumber} == 8;
        $s->{ok5}++ if $m->{primary_message}{Text} =~
          /.+\n.+/;
    }
    elsif ($m->{primary_message}{Number} == 131)
    {
        $s->{ok6}++ if $m->{primary_message}{ColumnNumber} == 13;
        $s->{ok7}++ if $m->{primary_message}{LineNumber} == 8;
        $s->{ok8}++ if $m->{primary_message}{Text} =~
        /.+\n.+/;
    }
}

my $h12 = TestHandler12->new($p);
$p->handler($h12);
$p->catalogs(TEST_CATALOG);
$p->show_error_numbers(1);

lives_ok { $p->parse("<LITERAL>" . <<"__DOC__");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p dir="&#xa;">...</p>
</body>
</html>
__DOC__
} 'newlines in enum attr values';

cmp_ok($h12->{ok1}, '>=', 2, 'two errors');
cmp_ok($h12->{ok2}, '>=', 2, 'two errors split');

ok($h12->{ok3}, 'correct col 122');
ok($h12->{ok4}, 'correct lin 122');
ok($h12->{ok5}, 'correct text 122');
ok($h12->{ok6}, 'correct col 131');
ok($h12->{ok7}, 'correct lin 131');
ok($h12->{ok8}, 'correct text 131');

$p->catalogs([]);
$p->show_error_numbers(0);

my @tests = (

### 1 ###

{
input => [
  q(<OSFD>0:116:49:1075801588.108:E: there is no attribute "XMLNS:UTILITY"),
  q(<OSFD>0),
  0,
  1,
  0,
],

output => {
  primary_message => {
    Number => '108',
    ColumnNumber => '49',
    Module => '1075801588',
    Severity => 'E',
    LineNumber => '116',
    Text => 'there is no attribute "XMLNS:UTILITY"'
  }
}
},

### 2 ###

{
input => [
  q(c:\\temp\\file:116:49:1075801588.108:E: there is no attribute "XMLNS:UTILITY"),
  q(c:\\temp\\file),
  0,
  1,
  0,
],

output => {
  primary_message => {
    Number => '108',
    ColumnNumber => '49',
    Module => '1075801588',
    Severity => 'E',
    LineNumber => '116',
    Text => 'there is no attribute "XMLNS:UTILITY"'
  }
}

},

### 3 ###

{
input => [
  q(c:\\temp\\file:116:49:E: there is no attribute "XMLNS:UTILITY"),
  q(c:\\temp\\file),
  0,
  0,
  0,
],

output => {
  primary_message => {
    ColumnNumber => '49',
    Severity => 'E',
    LineNumber => '116',
    Text => 'there is no attribute "XMLNS:UTILITY"'
  }
}

},

### 4 ###

{
input => [
  q(<OSFD>0:320:175:1075801588.338:W: cannot generate system identifier for general entity "AP"),
  q(<OSFD>0),
  0,
  1,
  0,
],

output => {
  primary_message => {
    Number => '338',
    ColumnNumber => '175',
    Module => '1075801588',
    Severity => 'W',
    LineNumber => '320',
    Text => 'cannot generate system identifier for general entity "AP"'
  }
}

},

);

foreach (@tests)
{
    my $inpu = $_->{input};
    my $outp = $_->{output};
    my $resu = SGML::Parser::OpenSP::Tools::split_message(@$inpu);
    is_deeply($resu, $outp);
}