File: 40ppi.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 (110 lines) | stat: -rw-r--r-- 2,693 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
110
#!/usr/bin/env perl
# Try Extract PPI

use warnings;
use strict;

use File::Temp   qw/tempdir/;
use Test::More;

use constant MSGIDS => 25;
use constant PLURAL_MSGIDS => 4;

BEGIN
{   eval "require PPI";
    plan skip_all => 'PPI not installed'
        if $@;

    plan tests => 10 + MSGIDS*4 + PLURAL_MSGIDS*1;
    use_ok('Log::Report::Extract::PerlPPI');
}

my $lexicon    = tempdir CLEANUP => 1;

my %expect_pos = ('' => 1);  # expect header
sub take($@)
{   my $result = shift;
    ok("$result", "$result");
    $expect_pos{$_}++ for @_;
}

###

my $ppi = Log::Report::Extract::PerlPPI->new(lexicon => $lexicon);

ok(defined $ppi, 'created parser');
isa_ok($ppi, 'Log::Report::Extract::PerlPPI');

$ppi->process( __FILE__ );   # yes, this file!
$ppi->write;

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

####

sub dummy($) {shift}

use Log::Report 'first-domain';  # cannot use variable textdomain
take("a0");
take(__"a1", 'a1');
take((__"a2"), 'a2');
take((__"a3a", "a3b"), 'a3a');
take(__("a4"), 'a4');
take(__ dummy('a7'));
take(__ dummy 'a8');
take(__(dummy 'a9'));

take((__x"b2"), 'b2');
take((__x"b3a", b2b => "b3c"), 'b3a');
take(__x("b4"), 'b4');
take(__x("b5a", b5b => "b5c"), 'b5a');
take(__x('b6a', b6b => "b6c"), 'b6a');
take(__x(qq{b7a}, b7b => "b7c"), 'b7a');
take(__x(q{b8a}, b8b => "b8c"), 'b8a');
take(__x(b9a => b9b => "b9c"), 'b9a');
take(__x(b10 => 1, 2), 'b10');

take((__n "c1", "c2", 1), "c1", "c2");
take((__n "c3", "c4", 0), "c3", "c4");
take(__n("c5", "c6", 1), "c5", "c6");
take(__n("c7", "c8", 0), "c7", "c8");

take(N__("d1"), "d1", "d1");

take(join(',', N__w("d2 d3")), "d2", "d3");
take(join(',', N__w("  d4 	d5 
 d6
d7")), "d4", "d5", "d6", "d7");  # line contains tab

### do not index these:

__x(+"e1");

### check that all tags were found in POT

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);
cmp_ok(scalar @pos, '==', MSGIDS, '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 $msgid");

    my $plural = $po->plural
        or next;
    ok(delete $expect_pos{$plural}, 'plural was expected');
}

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