5c252957b4fc272831627d071d62b98f68fc92aa
[catagits/HTML-Zoom.git] / t / to_fh.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use HTML::Zoom;
5 use Test::More tests => 12;
6
7 ok my $zoom = HTML::Zoom->from_html(<<HTML);
8 <html>
9   <head>
10     <title>Hi!</title>
11   </head>
12   <body id="content-area">
13     <h1>Test</h1>
14     <div>
15       <p class="first-para">Some stuff</p>
16       <p class="boday-para">More stuff</p>
17     </div>
18     <p id="footer">Copryright 2222</p>
19   </body>
20 </html>
21 HTML
22
23 ok my $fh = $zoom->to_fh,
24   'got filehandle';
25
26 ok my $html = $zoom->to_html,
27   'got html';
28
29 ok my $lines = join('', $zoom->to_fh->getlines),
30   'got joined lines';
31
32 is $html, $lines,
33   'straight html is same as lines';
34
35 {
36   $fh->read(my $buff, 2);
37
38   ok $buff,
39     'got a populated buffer';
40
41   is $buff, '<h',
42     'got expected info in buffer';
43 }
44
45 {
46   $fh->read(my $buff, 4);
47
48   ok $buff,
49     'got a populated buffer';
50
51   is $buff, 'tml>',
52     'got expected info in buffer';
53 }
54
55 {
56   $fh->read(my $buff, 4, 14);
57
58   ok $buff,
59     'got a populated buffer';
60
61   is $buff, '<tit',
62     'got expected info in buffer';
63 }
64
65 {
66   my @lines;
67   while($fh->read(my $buff, 15)) {
68     push @lines, $buff;
69   }
70
71   is $#lines, 15,
72     'correct number of lines';
73 }