Debian Codegraph @

t/28-cmd-headers.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use lib './inc';
4 use IO::Catch;
5
6 our $_STDOUT_;
7 tie *STDOUT, 'IO::Catch', '_STDOUT_' or die $!;
8
9 # Disable all ReadLine functionality
10 $ENV{PERL_RL} = 0;
11 delete $ENV{PAGER}
12 if $ENV{PAGER};
13 $ENV{PERL_HTML_DISPLAY_CLASS}="HTML::Display::Dump";
14
15 use Test::More tests => 8;
16
17 use_ok('WWW::Mechanize::Shell');
18 my $s = WWW::Mechanize::Shell->new( 'test', rcfile => undef, warnings => undef );
19 isa_ok $s, 'WWW::Mechanize::Shell';
20
21 sub cleanup() {
22 # clean up $_STDOUT_ so it fits on one line
23 #diag $_STDOUT_;
24 $_STDOUT_ =~ s/[\r\n]+/|/g;
25 $_STDOUT_ =~ s!(?<=:)(\s+)!(">" x (length($1)/2))!eg;
26 };
27
28 SKIP: {
29
30 $s->agent->{base} = 'http://example.com';
31 $s->agent->update_html(<<HTML);
32 <html>
33 <head><base href="http://example.com" />
34 <title>An HTML page</title>
35 </head>
36 <body>
37 <h1>(H1.1)</h1>
38 <h2>(H2)</h2>
39 <h3>(H3.1)</h3>
40 <h3>(H3.2)</h3>
41 <h4>(H4)</h4>
42 <h1>(H1.2)</h1>
43 <h5>(H5)</h5>
44 <h1></h1>
45 <h1> Some spaces before this</h1>
46 <h1>
47 A newline in
48 this</h1>
49 <h2>
50 <h3>
51 </body>
52 </html>
53 HTML
54 $s->cmd('headers');
55 cleanup;
56 is($_STDOUT_,"h1:(H1.1)|h2:>(H2)|h3:>>(H3.1)|h3:>>(H3.2)|h4:>>>(H4)|h1:(H1.2)|h5:>>>>(H5)|h1:<no text>|h1:Some spaces before this|h1:A newline in this|h2:><empty tag>|h3:>><empty tag>|", "The default works");
57 undef $_STDOUT_;
58
59 $s->cmd('headers 12345');
60 cleanup;
61 is($_STDOUT_,"h1:(H1.1)|h2:>(H2)|h3:>>(H3.1)|h3:>>(H3.2)|h4:>>>(H4)|h1:(H1.2)|h5:>>>>(H5)|h1:<no text>|h1:Some spaces before this|h1:A newline in this|h2:><empty tag>|h3:>><empty tag>|", "Explicitly specifying the default works as well");
62 undef $_STDOUT_;
63
64 $s->cmd('headers 1');
65 cleanup;
66 is($_STDOUT_,"h1:(H1.1)|h1:(H1.2)|h1:<no text>|h1:Some spaces before this|h1:A newline in this|", "H1 headers works as well");
67 undef $_STDOUT_;
68
69 $s->cmd('headers 23');
70 cleanup;
71 is($_STDOUT_,"h2:>(H2)|h3:>>(H3.1)|h3:>>(H3.2)|h2:><empty tag>|h3:>><empty tag>|", "Restricting to a subset works too");
72 undef $_STDOUT_;
73
74 $s->cmd('headers 25');
75 cleanup;
76 is($_STDOUT_,"h2:>(H2)|h5:>>>>(H5)|h2:><empty tag>|", "A noncontingous subset as well");
77 undef $_STDOUT_;
78
79 $s->cmd('headers 52');
80 cleanup;
81 is($_STDOUT_,"h2:>(H2)|h5:>>>>(H5)|h2:><empty tag>|", "Even in a weirdo order");
82 undef $_STDOUT_;
83
84 };