File: 12encode.t

package info (click to toggle)
libstring-print-perl 0.96-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184 kB
  • sloc: perl: 781; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 766 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
#!/usr/bin/env perl
# Output encoding (to HTML)

use warnings;
use strict;
use utf8;
use Test::More tests => 7;

use String::Print;

my $f = String::Print->new(encode_for => 'HTML');
isa_ok($f, 'String::Print');

# encode HTML, all
is $f->sprinti('Me & You'), 'Me & You';
is $f->sprinti('< {a} >', a => 'Me & You'), '&lt; Me &amp; You &gt;';

# exclude HTML encoding for names =~ /html$/i
is $f->sprinti('<{a_html}>', a_html => 'Me &amp; You'), '&lt;Me &amp; You&gt;';
is $f->sprinti('<{aHTML}>', aHTML => 'Me &amp; You'), '&lt;Me &amp; You&gt;';

# disable encoding
$f->encodeFor(undef);
is $f->sprinti('< {a} >', a => 'Me & You'), '< Me & You >';

# enable encoding
$f->encodeFor('HTML');
is $f->sprinti('< {a} >', a => 'Me & You'), '&lt; Me &amp; You &gt;';