File: More.t

package info (click to toggle)
libhtml-formatexternal-perl 26-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 408 kB
  • ctags: 115
  • sloc: perl: 2,397; sh: 164; makefile: 10
file content (163 lines) | stat: -rw-r--r-- 5,218 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

# Copyright 2008, 2009, 2010, 2013 Kevin Ryde

# This file is part of HTML-FormatExternal.
#
# HTML-FormatExternal is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your option) any
# later version.
#
# HTML-FormatExternal is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with HTML-FormatExternal.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;
use 5.008;
use Encode;
use HTML::FormatExternal;
use Test::More tests => 29;

use lib 't';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings() }

use HTML::FormatText::Elinks;
use HTML::FormatText::Links;
use HTML::FormatText::Lynx;
use HTML::FormatText::Netrik;
use HTML::FormatText::Vilistextum;
use HTML::FormatText::W3m;
use HTML::FormatText::Zen;

# uncomment this to run the ### lines
# use Smart::Comments;

#------------------------------------------------------------------------------
# vilistextum version 2.6.9 complains
#   "?? getopt returned character code 0%o %c??\n"
# if -u, -c or -y used when no --enable-multibyte
#
my $vilistextum_have_multibyte = do {
  require File::Spec;
  require IPC::Run;
  my $str;
  eval { IPC::Run::run(['vilistextum','-u'],
                       '<',File::Spec->devnull,
                       '>',\$str,
                       '2>&1') };
  defined $str && $str !~ /getopt/
    ? 1 : 0
  };
diag "vilistextum_have_multibyte is $vilistextum_have_multibyte";


#------------------------------------------------------------------------------
# links: U+263A input becomes ":-)" in latin1 output
#
SKIP: {
  my $class = 'HTML::FormatText::Links';
  $class->program_version or skip "$class not available", 1;
  diag $class;

  my $input_charset = 'utf-8';
  my $output_charset = 'latin-1';
  my $html = "<html><body>\x{263A}</body></html>";
  $html = Encode::encode ($input_charset, $html);
  my $str = $class->format_string
    ($html,
     input_charset => $input_charset,
     output_charset => $output_charset);
  like ($str, qr/\Q:-)/,
        "$class U+263A smiley $input_charset -> $output_charset");
}

# lynx undocumented 'justify' option
#
SKIP: {
  my $class = 'HTML::FormatText::Lynx';
  $class->program_version or skip "$class not available", 1;
  diag $class;

  my $html = "<html><body>x y z aaaa</body></html>";
  $html = Encode::encode ('utf-8', $html);
  my $str = $class->format_string
    ($html,
     leftmargin => 0,
     rightmargin => 7,
     justify => 1);
  like ($str, qr/^x  y  z$/m, "$class justify option");
}

foreach my $class ('HTML::FormatText::Elinks',
                   'HTML::FormatText::Links',
                   'HTML::FormatText::Lynx',
                   # 'HTML::FormatText::Netrik',  # no charsets
                   'HTML::FormatText::Vilistextum',
                   'HTML::FormatText::W3m',
                   # 'HTML::FormatText::Zen',  # no charsets
                  ) {
 SKIP: {
    diag $class;
    $class->program_full_version
      or skip "$class program not available", 3;

    my $input_charset = 'utf-8';
    my $output_charset = 'iso-8859-1';
    my $html = "<html><body>\x{B0}</body>\n</html>";
    $html = Encode::encode ($input_charset, $html);
    is (length($html), 12+2+15);
    my $str = $class->format_string
      ($html,
       input_charset => $input_charset,
       output_charset => $output_charset);
    my $degree_bytes = "\x{B0}";
    $degree_bytes = Encode::encode ($output_charset, $degree_bytes);
    is (length($degree_bytes), 1);
    like ($str, qr/\Q$degree_bytes/,
          "$class degree sign $input_charset -> $output_charset");
    ### $str
  }
}

foreach my $class ('HTML::FormatText::Elinks',
                   # 'HTML::FormatText::Links',  # no utf-8 output
                   'HTML::FormatText::Lynx',
                   # 'HTML::FormatText::Netrik',  # no charsets
                   'HTML::FormatText::Vilistextum',
                   'HTML::FormatText::W3m',
                   # 'HTML::FormatText::Zen',  # no charsets
                  ) {
 SKIP: {
    diag $class;
    $class->program_full_version or skip "$class program not available", 3;

    if ($class eq 'HTML::FormatText::Vilistextum'
        && ! $vilistextum_have_multibyte) {
      skip "vilistextum not built with multibyte", 3;
    }

    my $input_charset = 'iso-8859-1';
    my $output_charset = 'utf-8';
    my $html = "<html><body>\x{B0}</body>\n</html>";
    $html = Encode::encode ($input_charset, $html);
    is (length($html), 12+1+15);
    my $str = $class->format_string
      ($html,
       input_charset => $input_charset,
       output_charset => $output_charset);
    my $degree_bytes = "\x{B0}";
    $degree_bytes = Encode::encode ($output_charset, $degree_bytes);
    is (length($degree_bytes), 2);
    like ($str, qr/\Q$degree_bytes/,
          "$class degree sign $input_charset -> $output_charset");
  }
}

exit 0;