File: basics.t

package info (click to toggle)
libtext-quoted-perl 2.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 184 kB
  • sloc: perl: 1,536; makefile: 2
file content (192 lines) | stat: -rw-r--r-- 3,978 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;

use Test::More tests => 10;
BEGIN { use_ok('Text::Quoted') };

use Data::Dumper;

my $a = <<EOF;
> foo
> # Bar
> baz

quux
EOF

is_deeply(extract($a),
[[{text => 'foo',quoter => '>',raw => '> foo'},
  [{text => 'Bar',quoter => '> #',raw => '> # Bar'}],
  {text => 'baz',quoter => '>',raw => '> baz'}
 ],
 {text => '',empty => '1',quoter => '',raw => ''},
 {text => 'quux',quoter => '',raw => 'quux'}],
"Sample text is organized properly");

$a = <<EOF;

> foo
> > > baz
> > quux
> quuux
quuuux
EOF

my $a_dump = 
[
      { text => '', empty => '1', quoter => '', raw => '' },
      [
        { text => 'foo', quoter => '>', raw => '> foo' },
        [
          [
            { text => 'baz', quoter => '> > >',
              raw => '> > > baz' }
          ],
          { text => 'quux', quoter => '> >', raw => '> > quux' }
        ],
        { text => 'quuux', quoter => '>', raw => '> quuux' }
      ],
      { text => 'quuuux', quoter => '', raw => 'quuuux' }
    ];

is_deeply(extract($a), $a_dump, "Skipping levels works OK");

#########################
# handle nested comments with common >
$a = <<EOF;
> a
>> b
> c
EOF

$a_dump = 
    [
       [ 
         { 'text' => 'a', 'quoter' => '>', 'raw' => '> a' },
         [ { 'text' => 'b', 'quoter' => '>>', 'raw' => '>> b' } ],
         { 'text' => 'c', 'quoter' => '>', 'raw' => '> c' }
       ]
    ];

is_deeply(extract($a),$a_dump,"correctly parse >> delimiter");

#############
# when the quoter changes in the middle of things, don't get confused

$a = <<EOF;
> a
=> b
> c
EOF

$a_dump = 
    [
       [ { 'text' => 'a', 'quoter' => '>', 'raw' => '> a' } ],
       [ { 'text' => 'b', 'quoter' => '=>', 'raw' => '=> b' } ],
       [ { 'text' => 'c', 'quoter' => '>', 'raw' => '> c' } ]
    ];

is_deeply(extract($a),$a_dump,"correctly parse => delimiter");

#############
# when the quoter changes in the middle of things, don't get confused
# blank lines shouldn't affect it

$a = <<EOF;
> a

=> b

> c
EOF

$a_dump = 
    [
       [ { 'text' => 'a', 'quoter' => '>', 'raw' => '> a' } ],
       { 'text' => '', 'empty' => 1, 'quoter' => '', 'raw' => '' },
       [ { 'text' => 'b', 'quoter' => '=>', 'raw' => '=> b' } ],
       { 'text' => '', 'empty' => 1, 'quoter' => '', 'raw' => '' },
       [ { 'text' => 'c', 'quoter' => '>', 'raw' => '> c' } ]
    ];

is_deeply(extract($a),$a_dump,"correctly parse => delimiter with blank lines");

#############
# one of the real world quoter breakage examples was cpan>
# also, no text is required for the quoter to break things

$a = <<EOF;
>
cpan>
>
EOF

$a_dump = 
    [
       [ { 'text' => '', 'empty' => 1, 'quoter' => '>', 'raw' => '>' } ],
       [ { 'text' => '', 'empty' => 1, 'quoter' => 'cpan>', 'raw' => 'cpan>' } ],
       [ { 'text' => '', 'empty' => 1, 'quoter' => '>', 'raw' => '>' } ]
    ];

is_deeply(extract($a),$a_dump,"correctly parse cpan> delimiter with no text");

############
# just checking that when the cpan> quoter gets a space, we handle it properly

$a = <<EOF;
> a
cpan > b
> c
EOF

$a_dump = 
    [
       [ { 'text' => 'a', 'quoter' => '>', 'raw' => '> a' } ],
       { 'text' => 'cpan > b', 'quoter' => '', 'raw' => 'cpan > b' },
       [ { 'text' => 'c', 'quoter' => '>', 'raw' => '> c' } ],
    ];

is_deeply(extract($a),$a_dump,"correctly handles a non-delimiter");

Text::Quoted::set_quote_characters( qr/[!]/ );
$a = <<'EOF';
a
# b
c
! d
EOF

$a_dump = [
    {
        'text'   => "a\n# b\nc",
        'quoter' => '',
        'raw'    => "a\n# b\nc"
    },
    [
        {
            'text'   => "d",
            'quoter' => '!',
            'raw'    => "! d"
        },
    ]
];

is_deeply(extract($a),$a_dump,"customize quote char");

Text::Quoted::set_quote_characters( undef );
$a = <<'EOF';
a
# b
c
EOF

$a_dump = [
    {
        'text'   => "a\n# b\nc",
        'quoter' => '',
        'raw'    => "a\n# b\nc"
    },
];

is_deeply( extract($a), $a_dump, "customize quote char to exclude all" );