File: 12filters.t

package info (click to toggle)
liblog-report-template-perl 1.03-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 204 kB
  • sloc: perl: 732; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download
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
#!/usr/bin/env perl
# Test the additional filters.
use warnings;
use strict;

use Test::More;

use_ok 'Log::Report::Template';

my $templater = Log::Report::Template->new;
isa_ok $templater, 'Log::Report::Template';

sub fill($$)
{   my ($input, $filter) = @_;
	my $templ = qq{[% "$input" | $filter %]};

    my $output = '';
    $templater->process(\$templ, {}, \$output)
		or die $templater->error;
    $output;
}

### cols

is fill("a", "cols"), "<td>a</td>", 'cols default';
is fill("a\tb\tc", "cols"), "<td>a</td><td>b</td><td>c</td>";

is fill("a", "cols('th')"), "<th>a</th>", 'cols first form';
is fill("a\tb\tc", "cols('th', 'td')"), "<th>a</th><td>b</td><td>c</td>";

is fill("a", "cols('<td align=left>\$1</td>')"), "<td align=left>a</td>"
  , 'cols second form';
is fill("a\tb\tc", "cols('\$3\$1')"), "ca";


### br

is fill("a\n", "br"), "a<br>\n", 'br';
is fill("a\nb\n", "br"), "a<br>\nb<br>\n", 'br simple';
is fill("  \t\na\n\n  \n\nb  \n\n", "br"), "a<br>\nb<br>\n", 'br cleanup';

done_testing;