File: 41templ.t

package info (click to toggle)
liblog-report-lexicon-perl 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 440 kB
  • sloc: perl: 2,673; makefile: 9
file content (109 lines) | stat: -rw-r--r-- 2,249 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env perl
# Try Extract templates

use warnings;
use strict;

use File::Temp   qw/tempdir/;

use Test::More;

use Log::Report;  # mode => 'DEBUG';
use Log::Report::Lexicon::POT;
use Log::Report::Extract::Template;

use constant MSGIDS => 12;

# see after __END__
my @expect_pos = split /\n/, <<'_EXPECT';
first
second
third
fourth
fifth
six six six
%d seven
eight
nine
tenth
{a} eleven
twelve {b}
_EXPECT

chomp $expect_pos[-1];
cmp_ok(scalar @expect_pos, '==', MSGIDS);
my %expect_pos = map { ($_ => 1) } @expect_pos;
$expect_pos{''} = 1;  # header

BEGIN {
   plan tests => 15 + MSGIDS*3;
}

my $lexicon = tempdir CLEANUP => 1;

my $extr = Log::Report::Extract::Template->new
 ( lexicon => $lexicon
 , domain  => 'my-domain'
 , pattern => 'TT2-loc'
 );

ok(defined $extr, 'created parser');
isa_ok($extr, 'Log::Report::Extract::Template');

my $found = $extr->process( __FILE__ );   # yes, this file!
cmp_ok($found, '==', MSGIDS);

$extr->write;

my @potfns = $extr->index->list('my-domain');
cmp_ok(scalar @potfns, '==', 1, "one file created");
my $potfn = shift @potfns;
ok(defined $potfn);
ok(-s $potfn, "produced file $potfn has size");

#system "cat $potfn";

my $pot = Log::Report::Lexicon::POT->read($potfn, charset => 'utf-8');
ok(defined $pot, 'read translation table');
my @pos = $pot->translations('ACTIVE');
ok(@pos > 0);

# (+1 for the header)
cmp_ok(scalar @pos, '==', MSGIDS+1, 'correct number tests');
cmp_ok(scalar @pos, '==', scalar $pot->translations); # all active

my %msgids;
for my $po (@pos)
{   my $msgid = $po->msgid;
    ok(defined $msgid, "processing '$msgid'");
    ok(!defined $msgids{$msgid}, 'check not double');
    $msgids{$msgid}++;
    ok(delete $expect_pos{$msgid}, 'was expected');
}

cmp_ok(scalar keys %expect_pos, '==', 0, "all msgids found");
warn "NOT FOUND: $_\n" for keys %expect_pos;

__END__
Here, the example template starts
[%loc("first")%]
[%loc("second")%]
[%loc('third')%]
[% loc ( 'fourth' ) %]
   [%
   loc
   (
   'fifth'
   , params
   )
   %]
[%xloc('not found')%]
[%loc('six six six')%]
[% loc('%d seven|%d sevens', 7) %]
[% INCLUDE header.tt
   title = loc("eight") loc  ('nine'  )
   css   =loc( 'tenth' )
%]

[% '{a} eleven' | loc(a => 3) %]
[%| loc(b=>4) %]twelve {b}[%END%]