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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
#!/usr/bin/env perl
# Try Lexicon PO modifications
use warnings;
use strict;
use utf8;
use Test::More tests => 29;
use_ok('Log::Report::Lexicon::PO');
use_ok('Log::Report::Lexicon::POT');
#
# Create header
#
$Log::Report::VERSION = 'SOME_VERSION';
my $pot = Log::Report::Lexicon::POT->new
( textdomain => 'log-report'
, version => '2.3'
, charset => 'UTF-8'
, date => 'DUMMY' # don't want this to change during test
);
is($pot->msgstr(''), <<'__HEADER');
Project-Id-Version: log-report 2.3
Report-Msgid-Bugs-To:
POT-Creation-Date: DUMMY
PO-Revision-Date: DUMMY
Last-Translator:
Language-Team:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Plural-Forms: nplurals=2; plural=(n!=1);
__HEADER
is($pot->msgid('')->toString, <<'__HEAD');
#. Header generated with Log::Report::Lexicon::POT SOME_VERSION
msgid ""
msgstr ""
"Project-Id-Version: log-report 2.3\n"
"Report-Msgid-Bugs-To:\n"
"POT-Creation-Date: DUMMY\n"
"PO-Revision-Date: DUMMY\n"
"Last-Translator:\n"
"Language-Team:\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n!=1);\n"
__HEAD
cmp_ok($pot->nrPlurals, "==", 2);
is($pot->header('mime-version'), '1.0');
is($pot->header('mime-version', '3.14'), '3.14');
is($pot->header('mime-version'), '3.14');
is($pot->header('mime-version', undef), undef);
is($pot->header('new-field', 'some value'), 'some value');
$pot->updated('NEWDATE');
is($pot->msgid('')->toString, <<'__HEAD');
#. Header generated with Log::Report::Lexicon::POT SOME_VERSION
msgid ""
msgstr ""
"Project-Id-Version: log-report 2.3\n"
"Report-Msgid-Bugs-To:\n"
"POT-Creation-Date: DUMMY\n"
"PO-Revision-Date: NEWDATE\n"
"Last-Translator:\n"
"Language-Team:\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n!=1);\n"
"new-field: some value\n"
__HEAD
#
# Create non-plural
#
my $po = Log::Report::Lexicon::PO->new
( msgid => 'aap'
, references => 'aap.pm:10'
);
is($po->toString, <<'__AAP', 'no translation');
#: aap.pm:10
msgid "aap"
msgstr ""
__AAP
$po->addReferences('monkey.pm:12 aap.pm:3');
$po->msgstr(0, 'monkey');
is($po->toString, <<'__AAP', 'with translation');
#: aap.pm:10 aap.pm:3 monkey.pm:12
msgid "aap"
msgstr "monkey"
__AAP
is($po->plural("apen"), 'apen', 'add plural');
ok($po->fuzzy(1), 'is fuzzy');
is($po->toString, <<'__AAP');
#: aap.pm:10 aap.pm:3 monkey.pm:12
#, fuzzy
msgid "aap"
msgid_plural "apen"
msgstr[0] "monkey"
msgstr[1] ""
__AAP
is($po->toString(nr_plurals => $pot->nrPlurals), <<'__AAP');
#: aap.pm:10 aap.pm:3 monkey.pm:12
#, fuzzy
msgid "aap"
msgid_plural "apen"
msgstr[0] "monkey"
msgstr[1] ""
__AAP
$po->msgstr(1, 'monkeys');
$po->fuzzy(0);
cmp_ok($po->removeReferencesTo('aap.pm'), '==', 1);
is($po->toString(nr_plurals => $pot->nrPlurals), <<'__AAP');
#: monkey.pm:12
msgid "aap"
msgid_plural "apen"
msgstr[0] "monkey"
msgstr[1] "monkeys"
__AAP
#
# Index
#
ok(!$pot->msgid('aap'));
is($pot->add($po), $po, 'add');
is($pot->msgid('aap'), $po);
is($pot->msgstr('aap', 0), 'monkeys');
is($pot->msgstr('aap', 1), 'monkey');
is($pot->msgstr('aap', 2), 'monkeys');
#
# disable/enable
#
cmp_ok($po->removeReferencesTo('monkey.pm'), "==", 0, 'rm last ref');
is($po->toString(nr_plurals => $pot->nrPlurals), <<'__AAP');
#~ msgid "aap"
#~ msgid_plural "apen"
#~ msgstr[0] "monkey"
#~ msgstr[1] "monkeys"
__AAP
$po->addReferences('noot.pm:12', 'aap.pm:42');
is($po->toString(nr_plurals => $pot->nrPlurals), <<'__AAP');
#: aap.pm:42 noot.pm:12
msgid "aap"
msgid_plural "apen"
msgstr[0] "monkey"
msgstr[1] "monkeys"
__AAP
#
# Write
#
my $text = '';
open TEXT, '>:utf8', \$text;
$pot->write(\*TEXT);
close TEXT;
is($text, <<'__ALL')
#. Header generated with Log::Report::Lexicon::POT SOME_VERSION
msgid ""
msgstr ""
"Project-Id-Version: log-report 2.3\n"
"Report-Msgid-Bugs-To:\n"
"POT-Creation-Date: DUMMY\n"
"PO-Revision-Date: NEWDATE\n"
"Last-Translator:\n"
"Language-Team:\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n!=1);\n"
"new-field: some value\n"
#: aap.pm:42 noot.pm:12
msgid "aap"
msgid_plural "apen"
msgstr[0] "monkey"
msgstr[1] "monkeys"
__ALL
|