Initialized from version 1.28 (2009/6/27).
This commit is contained in:
22
t/00-signature.t
Executable file
22
t/00-signature.t
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
print "1..1\n";
|
||||
|
||||
if (!-s 'SIGNATURE') {
|
||||
print "ok 1 # skip No signature file found\n";
|
||||
}
|
||||
elsif (!eval { require Module::Signature; 1 }) {
|
||||
print "ok 1 # skip ",
|
||||
"Next time around, consider install Module::Signature, ",
|
||||
"so you can verify the integrity of this distribution.\n";
|
||||
}
|
||||
elsif (!eval { require Socket; Socket::inet_aton('pgp.mit.edu') }) {
|
||||
print "ok 1 # skip Cannot connect to the keyserver\n";
|
||||
}
|
||||
else {
|
||||
(Module::Signature::verify() == Module::Signature::SIGNATURE_OK())
|
||||
or print "not ";
|
||||
print "ok 1 # Valid signature\n";
|
||||
}
|
||||
|
||||
__END__
|
150
t/01-basic.t
Executable file
150
t/01-basic.t
Executable file
@ -0,0 +1,150 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Basic test suite
|
||||
# Copyright (c) 2003-2008 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 22 }
|
||||
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
|
||||
# Basic test suite
|
||||
use Encode qw(decode);
|
||||
use vars qw($META $n $k1 $k2 $s1 $s2);
|
||||
|
||||
# bindtextdomain
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_ = $_->bindtextdomain("test");
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_, "$LOCALEDIR");
|
||||
|
||||
# textdomain
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_ = $_->textdomain;
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_, "test");
|
||||
|
||||
# read_mo
|
||||
$META = << "EOT";
|
||||
Project-Id-Version: test 1.1
|
||||
Report-Msgid-Bugs-To:
|
||||
POT-Creation-Date: 2008-02-19 12:31+0800
|
||||
PO-Revision-Date: 2008-02-19 12:31+0800
|
||||
Last-Translator: imacat <imacat\@mail.imacat.idv.tw>
|
||||
Language-Team: English <imacat\@mail.imacat.idv.tw>
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=US-ASCII
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Plural-Forms: nplurals=2; plural=n != 1;
|
||||
EOT
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext;
|
||||
$_ = catfile($LOCALEDIR, "en", "LC_MESSAGES", "test.mo");
|
||||
%_ = read_mo($_);
|
||||
@_ = sort keys %_;
|
||||
$n = scalar(@_);
|
||||
$k1 = $_[0];
|
||||
$k2 = $_[1];
|
||||
$s1 = $_{$k1};
|
||||
$s2 = $_{$k2};
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
# 6
|
||||
ok($n, 4);
|
||||
# 7
|
||||
ok($k1, "");
|
||||
# 8
|
||||
ok($k2, "Hello, world!");
|
||||
# 9
|
||||
ok($s1, $META);
|
||||
# 10
|
||||
ok($s2, "Hiya :)");
|
||||
|
||||
# English
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_[0] = $_->maketext("Hello, world!");
|
||||
$_[1] = $_->pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = $_->pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 11
|
||||
ok($r, 1);
|
||||
# 12
|
||||
ok($_[0], "Hiya :)");
|
||||
# 13
|
||||
ok($_[1], "Hiya :) under the File menu");
|
||||
# 14
|
||||
ok($_[2], "Hiya :) under the View menu");
|
||||
|
||||
# Traditional Chinese
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_[0] = $_->maketext("Hello, world!");
|
||||
$_[1] = $_->pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = $_->pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 15
|
||||
ok($r, 1);
|
||||
# 16
|
||||
ok($_[0], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 17
|
||||
ok($_[1], "<22>ɮ<C9AE><D7BF><EFBFBD><EFBFBD>U<EFBFBD><55><EFBFBD>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 18
|
||||
ok($_[2], "<22>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD><55><EFBFBD>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Simplified Chinese
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$_ = T_L10N->get_handle("zh-cn");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_[0] = $_->maketext("Hello, world!");
|
||||
$_[1] = $_->pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = $_->pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 19
|
||||
ok($r, 1);
|
||||
# 20
|
||||
ok($_[0], "<22><><EFBFBD>Һá<D2BA>");
|
||||
# 21
|
||||
ok($_[1], "<22><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>µĴ<C2B5><C4B4>Һá<D2BA>");
|
||||
# 22
|
||||
ok($_[2], "<22><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>µĴ<C2B5><C4B4>Һá<D2BA>");
|
143
t/02-big-endian.t
Executable file
143
t/02-big-endian.t
Executable file
@ -0,0 +1,143 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test the big endian MO files
|
||||
# Copyright (c) 2003-2009 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 10 }
|
||||
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
|
||||
# Check reading big-endian PO files
|
||||
use vars qw($skip $POfile $MOfile $hasctxt);
|
||||
# English
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test_be", $LOCALEDIR);
|
||||
$_->textdomain("test_be");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_, "Hiya :)");
|
||||
|
||||
# Traditional Chinese
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test_be", $LOCALEDIR);
|
||||
$_->textdomain("test_be");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Simplified Chinese
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-cn");
|
||||
$_->bindtextdomain("test_be", $LOCALEDIR);
|
||||
$_->textdomain("test_be");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
# 6
|
||||
ok($_, "<22><><EFBFBD>Һá<D2BA>");
|
||||
|
||||
# Native-built MO file
|
||||
{
|
||||
my $FH;
|
||||
$skip = 1;
|
||||
$POfile = catfile($FindBin::Bin, "test_native.po");
|
||||
$MOfile = catfile($LOCALEDIR, "en", "LC_MESSAGES", "test_native.mo");
|
||||
$_ = join "", `msgfmt --version 2>&1`;
|
||||
last unless $? == 0;
|
||||
last unless /GNU gettext/;
|
||||
last unless /GNU gettext.* (\d+)\.(\d+)/;
|
||||
# Gettext from 0.15 has msgctxt
|
||||
$hasctxt = $1 > 0 || ($1 == 0 && $2 >= 15);
|
||||
$_ = << "EOT";
|
||||
# English PO file for the test_native project.
|
||||
# Copyright (C) 2003-2009 imacat
|
||||
# This file is distributed under the same license as the commonlib package.
|
||||
# imacat <imacat\@mail.imacat.idv.tw>, 2003-%1\$04d.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: test_native 1.1\\n"
|
||||
"Report-Msgid-Bugs-To: \\n"
|
||||
"POT-Creation-Date: %1\$04d-%2\$02d-%3\$02d %4\$02d:%5\$02d+0800\\n"
|
||||
"PO-Revision-Date: %1\$04d-%2\$02d-%3\$02d %4\$02d:%5\$02d+0800\\n"
|
||||
"Last-Translator: imacat <imacat\@mail.imacat.idv.tw>\\n"
|
||||
"Language-Team: English <imacat\@mail.imacat.idv.tw>\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=US-ASCII\\n"
|
||||
"Content-Transfer-Encoding: 7bit\\n"
|
||||
"Plural-Forms: nplurals=2; plural=n != 1;\\n"
|
||||
|
||||
#: test_native.pl:100
|
||||
msgid "Hello, world!"
|
||||
msgstr "Hiya :)"
|
||||
EOT
|
||||
$_ .= << "EOT" if $hasctxt;
|
||||
|
||||
#: test_native.pl:103
|
||||
msgctxt "Menu|File|"
|
||||
msgid "Hello, world!"
|
||||
msgstr "Hiya :) under the File menu"
|
||||
|
||||
#: test_native.pl:106
|
||||
msgctxt "Menu|View|"
|
||||
msgid "Hello, world!"
|
||||
msgstr "Hiya :) under the View menu"
|
||||
EOT
|
||||
@_ = localtime;
|
||||
$_[5] += 1900;
|
||||
$_[4]++;
|
||||
$_ = sprintf $_, @_[5,4,3,2,1,0];
|
||||
open $FH, ">$POfile";
|
||||
print $FH $_;
|
||||
close $FH;
|
||||
`msgfmt -o "$MOfile" "$POfile"`;
|
||||
last unless $? == 0;
|
||||
$skip = 0;
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test_native", $LOCALEDIR);
|
||||
$_->textdomain("test_native");
|
||||
$_[0] = $_->maketext("Hello, world!");
|
||||
$_[1] = $_->pmaketext("Menu|File|", "Hello, world!") if $hasctxt;
|
||||
$_[2] = $_->pmaketext("Menu|View|", "Hello, world!") if $hasctxt;
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
# 7
|
||||
skip($skip, $r, 1);
|
||||
# 8
|
||||
skip($skip, $_[0], "Hiya :)");
|
||||
# 9
|
||||
skip($skip || !$hasctxt, $_[1], "Hiya :) under the File menu");
|
||||
# 10
|
||||
skip($skip || !$hasctxt, $_[2], "Hiya :) under the View menu");
|
||||
|
||||
# Garbage collection
|
||||
unlink $POfile;
|
||||
unlink $MOfile;
|
283
t/03-errors.t
Executable file
283
t/03-errors.t
Executable file
@ -0,0 +1,283 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite for the behavior when something goes wrong
|
||||
# Copyright (c) 2003-2009 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 29 }
|
||||
|
||||
use Encode qw();
|
||||
use FindBin;
|
||||
use File::Basename qw(basename);
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($THIS_FILE $LOCALEDIR $r);
|
||||
$THIS_FILE = basename($0);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
sub find_system_mo();
|
||||
|
||||
# find_system_mo: Find a safe system MO to be tested
|
||||
sub find_system_mo() {
|
||||
local ($_, %_);
|
||||
my %cands;
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
# Find all the system MO files
|
||||
%cands = qw();
|
||||
foreach my $dir (@Locale::Maketext::Gettext::Functions::SYSTEM_LOCALEDIRS) {
|
||||
my ($DH, @locales);
|
||||
next unless -d $dir;
|
||||
|
||||
@locales = qw();
|
||||
opendir $DH, $dir or die "$THIS_FILE: $dir: $!";
|
||||
while (defined($_ = readdir $DH)) {
|
||||
my $dir1;
|
||||
$dir1 = catfile($dir, $_, "LC_MESSAGES");
|
||||
push @locales, $_ if -d $dir1 && -r $dir1
|
||||
&& /^(?:en|zh_tw|zh_cn)$/i;
|
||||
}
|
||||
closedir $DH or die "$THIS_FILE: $dir: $!";
|
||||
|
||||
foreach my $loc (sort @locales) {
|
||||
my $dir1;
|
||||
$dir1 = catfile($dir, $loc, "LC_MESSAGES");
|
||||
opendir $DH, $dir1 or die "$THIS_FILE: $dir1: $!";
|
||||
while (defined($_ = readdir $DH)) {
|
||||
my ($file, $domain);
|
||||
$file = catfile($dir1, $_);
|
||||
next unless -f $file && -r $file && /^(.+)\.mo$/;
|
||||
$domain = $1;
|
||||
$cands{$file} = [$loc, $domain];
|
||||
}
|
||||
closedir $DH or die "$THIS_FILE: $dir1: $!";
|
||||
}
|
||||
}
|
||||
# Check each MO file, from the newest
|
||||
foreach my $file (sort { (stat $b)[9] <=> (stat $a)[9] } keys %cands) {
|
||||
my ($FH, $size, $content, $charset, $lang, $domain);
|
||||
$size = (stat $file)[7];
|
||||
open $FH, $file or die "$THIS_FILE: $file: $!";
|
||||
read $FH, $content, $size or die "$THIS_FILE: $file: $!";
|
||||
close $FH or die "$THIS_FILE: $file: $!";
|
||||
# Only take files whose meta information does not have special characters
|
||||
# that might be considered as code by Locale::Maketext
|
||||
next unless $content =~ /Project-Id-Version:([^\n\0\[\]~]+\n)+\0/;
|
||||
# Only take files that resolve to a valid character set
|
||||
next unless $content =~ /\s+charset=([^\n]+)/;
|
||||
$charset = $1;
|
||||
next unless defined Encode::resolve_alias($charset);
|
||||
# OK. We take this one
|
||||
($lang, $domain) = @{$cands{$file}};
|
||||
$lang = lc $lang;
|
||||
$lang =~ s/_/-/g;
|
||||
$lang = "i-default" if $lang eq "c";
|
||||
return ($lang, $domain);
|
||||
}
|
||||
# Not found
|
||||
return (undef, undef);
|
||||
}
|
||||
|
||||
# When something goes wrong
|
||||
use vars qw($dir $domain $lang $skip);
|
||||
# GNU gettext never fails!
|
||||
# bindtextdomain
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_ = $_->bindtextdomain("test");
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_, undef);
|
||||
|
||||
# textdomain
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_ = $_->textdomain;
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_, undef);
|
||||
|
||||
# No text domain claimed yet
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
# 6
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# Non-existing LOCALEDIR
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", "/dev/null");
|
||||
$_->textdomain("test");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 7
|
||||
ok($r, 1);
|
||||
# 8
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# Not-registered DOMAIN
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->textdomain("not_registered");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 9
|
||||
ok($r, 1);
|
||||
# 10
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# PO file not exists
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("no_such_domain", $LOCALEDIR);
|
||||
$_->textdomain("no_such_domain");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 11
|
||||
ok($r, 1);
|
||||
# 12
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# PO file invalid
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("bad", $LOCALEDIR);
|
||||
$_->textdomain("bad");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 13
|
||||
ok($r, 1);
|
||||
# 14
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# No such message
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_[0] = $_->maketext("[*,_1,non-existing message,non-existing messages]", 1);
|
||||
$_[1] = $_->maketext("[*,_1,non-existing message,non-existing messages]", 3);
|
||||
$_[2] = $_->pmaketext("Menu|View|", "[*,_1,non-existing message,non-existing messages]", 1);
|
||||
$_[3] = $_->pmaketext("Menu|View|", "[*,_1,non-existing message,non-existing messages]", 3);
|
||||
$_[4] = $_->pmaketext("Menu|None|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 15
|
||||
ok($r, 1);
|
||||
# 16
|
||||
ok($_[0], "1 non-existing message");
|
||||
# 17
|
||||
ok($_[1], "3 non-existing messages");
|
||||
# 18
|
||||
ok($_[2], "1 non-existing message");
|
||||
# 19
|
||||
ok($_[3], "3 non-existing messages");
|
||||
# 20
|
||||
ok($_[4], "Hello, world!");
|
||||
|
||||
# die_for_lookup_failures
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->die_for_lookup_failures(1);
|
||||
$_ = $_->maketext("non-existing message");
|
||||
return 1;
|
||||
};
|
||||
# To be refined - to know that we failed at maketext()
|
||||
# was ok($@, qr/maketext doesn't know how to say/);
|
||||
# 21
|
||||
ok($r, undef);
|
||||
|
||||
# multibyte keys
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->key_encoding("Big5");
|
||||
$_ = $_->maketext("<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
return 1;
|
||||
};
|
||||
# 22
|
||||
ok($r, 1);
|
||||
# 23
|
||||
ok($_, "<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", "/dev/null");
|
||||
$_->textdomain("test");
|
||||
$_->key_encoding("Big5");
|
||||
$_ = $_->maketext("<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
return 1;
|
||||
};
|
||||
# 24
|
||||
ok($r, 1);
|
||||
# 25
|
||||
ok($_, "<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
|
||||
# Call maketext before and after binding text domain
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->maketext("Hello, world!");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 26
|
||||
ok($r, 1);
|
||||
# 27
|
||||
ok($_, "Hiya :)");
|
||||
|
||||
# Search system locale directories
|
||||
($lang, $domain) = find_system_mo;
|
||||
$skip = defined $domain? 0: 1;
|
||||
print "($lang, $domain)\n";
|
||||
$r = eval {
|
||||
return if $skip;
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle($lang);
|
||||
$_->textdomain($domain);
|
||||
print "OK 1111\n";
|
||||
$_ = $_->maketext("");
|
||||
# Skip if $Lexicon{""} does not exists
|
||||
$skip = 1 if $_ eq "";
|
||||
return 1;
|
||||
};
|
||||
# 28
|
||||
skip($skip, $r, 1);
|
||||
# 29
|
||||
skip($skip, $_, qr/Project-Id-Version:/);
|
266
t/04-encodings.t
Executable file
266
t/04-encodings.t
Executable file
@ -0,0 +1,266 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite for different encodings
|
||||
# Copyright (c) 2003-2007 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 34 }
|
||||
|
||||
use Encode qw();
|
||||
use FindBin qw();
|
||||
use File::Spec::Functions qw(catdir);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
|
||||
# Different encodings
|
||||
# English
|
||||
# Find the default encoding
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_ = $_->encoding;
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_, "US-ASCII");
|
||||
|
||||
# Traditional Chinese
|
||||
# Find the default encoding
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_ = $_->encoding;
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_, "Big5");
|
||||
|
||||
# Turn to Big5
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->encoding("Big5");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
# 6
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Turn to UTF-8
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->encoding("UTF-8");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 7
|
||||
ok($r, 1);
|
||||
# 8
|
||||
ok($_, "大家好。");
|
||||
|
||||
# Turn to UTF-16LE
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->encoding("UTF-16LE");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 9
|
||||
ok($r, 1);
|
||||
# 10
|
||||
ok($_, "'Y<>[}Y0");
|
||||
|
||||
# Find the default encoding, in UTF-8
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
$_->textdomain("test_utf8");
|
||||
$_ = $_->encoding;
|
||||
return 1;
|
||||
};
|
||||
# 11
|
||||
ok($r, 1);
|
||||
# 12
|
||||
ok($_, "UTF-8");
|
||||
|
||||
# Turn to UTF-8
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
$_->textdomain("test_utf8");
|
||||
$_->encoding("UTF-8");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 13
|
||||
ok($r, 1);
|
||||
# 14
|
||||
ok($_, "大家好。");
|
||||
|
||||
# Turn to Big5
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
$_->textdomain("test_utf8");
|
||||
$_->encoding("Big5");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 15
|
||||
ok($r, 1);
|
||||
# 16
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Turn to UTF-16LE
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
$_->textdomain("test_utf8");
|
||||
$_->encoding("UTF-16LE");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 17
|
||||
ok($r, 1);
|
||||
# 18
|
||||
ok($_, "'Y<>[}Y0");
|
||||
|
||||
# Find the default encoding
|
||||
# Simplified Chinese
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-cn");
|
||||
$_->bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
$_->textdomain("test_utf8");
|
||||
$_ = $_->encoding;
|
||||
return 1;
|
||||
};
|
||||
# 19
|
||||
ok($r, 1);
|
||||
# 20
|
||||
ok($_, "UTF-8");
|
||||
|
||||
# Turn to GB2312
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-cn");
|
||||
$_->bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
$_->textdomain("test_utf8");
|
||||
$_->encoding("GB2312");
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 21
|
||||
ok($r, 1);
|
||||
# 22
|
||||
ok($_, "<22><><EFBFBD>Һá<D2BA>");
|
||||
|
||||
# Encode failure
|
||||
# FB_DEFAULT
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test2", $LOCALEDIR);
|
||||
$_->textdomain("test2");
|
||||
$_->encoding("GB2312");
|
||||
$_ = $_->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 23
|
||||
ok($r, 1);
|
||||
# 24
|
||||
ok($_, "<22><><EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>?<3F><>?<3F>֡<EFBFBD>");
|
||||
|
||||
# FB_CROAK
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test2", $LOCALEDIR);
|
||||
$_->textdomain("test2");
|
||||
$_->encoding("GB2312");
|
||||
$_->encode_failure(Encode::FB_CROAK);
|
||||
$_ = $_->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 25
|
||||
ok($r, undef);
|
||||
# 26
|
||||
ok($@, qr/does not map to/);
|
||||
|
||||
# FB_HTMLCREF
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test2", $LOCALEDIR);
|
||||
$_->textdomain("test2");
|
||||
$_->encoding("GB2312");
|
||||
$_->encode_failure(Encode::FB_HTMLCREF);
|
||||
$_ = $_->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 27
|
||||
ok($r, 1);
|
||||
# 28
|
||||
ok($_, "<22><><EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>麗<3B><>結<3B>֡<EFBFBD>");
|
||||
|
||||
# Return the unencoded UTF-8 text
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->encoding(undef);
|
||||
$_ = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 29
|
||||
ok($r, 1);
|
||||
# 30
|
||||
ok($_, "\x{5927}\x{5BB6}\x{597D}\x{3002}");
|
||||
# 31
|
||||
ok((Encode::is_utf8($_)? "utf8": "non-utf8"), "utf8");
|
||||
|
||||
# Return the unencoded UTF-8 text with auto lexicon
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->encoding(undef);
|
||||
$_ = $_->maketext("Big watermelon");
|
||||
return 1;
|
||||
};
|
||||
# 32
|
||||
ok($r, 1);
|
||||
# 33
|
||||
ok($_, "Big watermelon");
|
||||
# 34
|
||||
ok((Encode::is_utf8($_)? "utf8": "non-utf8"), "utf8");
|
157
t/05-switching.t
Executable file
157
t/05-switching.t
Executable file
@ -0,0 +1,157 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite for switching between different settings
|
||||
# Copyright (c) 2003-2008 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 25 }
|
||||
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
|
||||
# Switching between different settings
|
||||
use File::Copy qw(copy);
|
||||
use vars qw($lh1 $lh2 $dir $f $f1 $f2);
|
||||
|
||||
# 2 language handles of the same localization subclass
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$lh1 = T_L10N->get_handle("en");
|
||||
$lh1->bindtextdomain("test", $LOCALEDIR);
|
||||
$lh1->textdomain("test");
|
||||
$lh2 = T_L10N->get_handle("en");
|
||||
$lh2->bindtextdomain("test2", $LOCALEDIR);
|
||||
$lh2->textdomain("test2");
|
||||
$_[0] = $lh1->maketext("Hello, world!");
|
||||
$_[1] = $lh1->maketext("Every story has a happy ending.");
|
||||
$_[2] = $lh2->maketext("Hello, world!");
|
||||
$_[3] = $lh2->maketext("Every story has a happy ending.");
|
||||
$_[4] = $lh1->maketext("Hello, world!");
|
||||
$_[5] = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_[0], "Hiya :)");
|
||||
# 3
|
||||
ok($_[1], "Every story has a happy ending.");
|
||||
# 4
|
||||
ok($_[2], "Hello, world!");
|
||||
# 5
|
||||
ok($_[3], "Pray it.");
|
||||
# 6
|
||||
ok($_[4], "Hiya :)");
|
||||
# 7
|
||||
ok($_[5], "Every story has a happy ending.");
|
||||
|
||||
# Switch between domains
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->bindtextdomain("test2", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_[0] = $_->maketext("Hello, world!");
|
||||
$_[1] = $_->maketext("Every story has a happy ending.");
|
||||
$_->textdomain("test2");
|
||||
$_[2] = $_->maketext("Hello, world!");
|
||||
$_[3] = $_->maketext("Every story has a happy ending.");
|
||||
$_->textdomain("test");
|
||||
$_[4] = $_->maketext("Hello, world!");
|
||||
$_[5] = $_->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 8
|
||||
ok($r, 1);
|
||||
# 9
|
||||
ok($_[0], "Hiya :)");
|
||||
# 10
|
||||
ok($_[1], "Every story has a happy ending.");
|
||||
# 11
|
||||
ok($_[2], "Hello, world!");
|
||||
# 12
|
||||
ok($_[3], "Pray it.");
|
||||
# 13
|
||||
ok($_[4], "Hiya :)");
|
||||
# 14
|
||||
ok($_[5], "Every story has a happy ending.");
|
||||
|
||||
# Switch between encodings
|
||||
$r = eval {
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$_ = T_L10N->get_handle("zh-tw");
|
||||
$_->bindtextdomain("test", $LOCALEDIR);
|
||||
$_->textdomain("test");
|
||||
$_->encoding("Big5");
|
||||
$_[0] = $_->maketext("Hello, world!");
|
||||
$_->encoding("UTF-8");
|
||||
$_[1] = $_->maketext("Hello, world!");
|
||||
$_->encoding("Big5");
|
||||
$_[2] = $_->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 15
|
||||
ok($r, 1);
|
||||
# 16
|
||||
ok($_[0], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 17
|
||||
ok($_[1], "大家好。");
|
||||
# 18
|
||||
ok($_[2], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Reload the text
|
||||
$r = eval {
|
||||
$dir = catdir($LOCALEDIR, "en", "LC_MESSAGES");
|
||||
$f = catfile($dir, "test_reload.mo");
|
||||
$f1 = catfile($dir, "test.mo");
|
||||
$f2 = catfile($dir, "test2.mo");
|
||||
unlink $f;
|
||||
copy $f1, $f or die "ERROR: $f1 $f: $!";
|
||||
|
||||
require T_L10N;
|
||||
@_ = qw();
|
||||
$_ = T_L10N->get_handle("en");
|
||||
$_->bindtextdomain("test_reload", $LOCALEDIR);
|
||||
$_->textdomain("test_reload");
|
||||
$_[0] = $_->maketext("Hello, world!");
|
||||
$_[1] = $_->maketext("Every story has a happy ending.");
|
||||
unlink $f;
|
||||
copy $f2, $f or die "ERROR: $f2 $f: $!";
|
||||
$_[2] = $_->maketext("Hello, world!");
|
||||
$_[3] = $_->maketext("Every story has a happy ending.");
|
||||
$_->reload_text;
|
||||
$_[4] = $_->maketext("Hello, world!");
|
||||
$_[5] = $_->maketext("Every story has a happy ending.");
|
||||
|
||||
unlink $f;
|
||||
return 1;
|
||||
};
|
||||
# 19
|
||||
ok($r, 1);
|
||||
# 20
|
||||
ok($_[0], "Hiya :)");
|
||||
# 21
|
||||
ok($_[1], "Every story has a happy ending.");
|
||||
# 22
|
||||
ok($_[2], "Hiya :)");
|
||||
# 23
|
||||
ok($_[3], "Every story has a happy ending.");
|
||||
# 24
|
||||
ok($_[4], "Hello, world!");
|
||||
# 25
|
||||
ok($_[5], "Pray it.");
|
||||
|
||||
# Garbage collection
|
||||
unlink catfile($LOCALEDIR, "en", "LC_MESSAGES", "test_reload.mo");
|
317
t/06-racing.t
Executable file
317
t/06-racing.t
Executable file
@ -0,0 +1,317 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite for the hybrid racing condition
|
||||
# Copyright (c) 2003-2007 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 42 }
|
||||
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r $LOOKUP_FAILURE);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
|
||||
# Hybrid racing conditionr
|
||||
use vars qw($lh1 $lh2);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
require T_L10N;
|
||||
|
||||
$lh1 = T_L10N->get_handle("zh-tw");
|
||||
$lh1->fail_with(sub { $LOOKUP_FAILURE = 1; die; });
|
||||
$lh1->bindtextdomain("test", $LOCALEDIR);
|
||||
$lh1->textdomain("test");
|
||||
$lh1->encoding("Big5");
|
||||
$lh1->die_for_lookup_failures(0);
|
||||
|
||||
$lh2 = T_L10N->get_handle("zh-tw");
|
||||
$lh2->fail_with(sub { $LOOKUP_FAILURE = 1; die; });
|
||||
$lh2->bindtextdomain("test2", $LOCALEDIR);
|
||||
$lh2->textdomain("test2");
|
||||
$lh2->encoding("UTF-8");
|
||||
$lh2->die_for_lookup_failures(1);
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
|
||||
# Once
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 2
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($_, "Every story has a happy ending.");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 4
|
||||
ok($r, undef);
|
||||
# 5
|
||||
ok($LOOKUP_FAILURE, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 6
|
||||
ok($_, "故事都有美麗的結局。");
|
||||
|
||||
# Again
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 7
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 8
|
||||
ok($_, "Every story has a happy ending.");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 9
|
||||
ok($r, undef);
|
||||
# 10
|
||||
ok($LOOKUP_FAILURE, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 11
|
||||
ok($_, "故事都有美麗的結局。");
|
||||
|
||||
# Exchange everything!
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$lh1->bindtextdomain("test2", $LOCALEDIR);
|
||||
$lh1->textdomain("test2");
|
||||
$lh1->encoding("UTF-8");
|
||||
$lh1->die_for_lookup_failures(1);
|
||||
|
||||
$lh2->bindtextdomain("test", $LOCALEDIR);
|
||||
$lh2->textdomain("test");
|
||||
$lh2->encoding("Big5");
|
||||
$lh2->die_for_lookup_failures(0);
|
||||
return 1;
|
||||
};
|
||||
# 12
|
||||
ok($r, 1);
|
||||
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 13
|
||||
ok($r, undef);
|
||||
# 14
|
||||
ok($LOOKUP_FAILURE, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 15
|
||||
ok($_, "故事都有美麗的結局。");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 16
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 17
|
||||
ok($_, "Every story has a happy ending.");
|
||||
|
||||
# Exchange the text domains
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$lh1->textdomain("test");
|
||||
$lh2->textdomain("test2");
|
||||
return 1;
|
||||
};
|
||||
# 18
|
||||
ok($r, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 19
|
||||
ok($_, "大家好。");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 20
|
||||
ok($r, undef);
|
||||
# 21
|
||||
ok($LOOKUP_FAILURE, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 22
|
||||
ok($_, "Hello, world!");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 23
|
||||
ok($_, "<22>G<EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>R<EFBFBD><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>C");
|
||||
|
||||
# Exchange encodings
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$lh1->encoding("Big5");
|
||||
$lh2->encoding("UTF-8");
|
||||
return 1;
|
||||
};
|
||||
# 24
|
||||
ok($r, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 25
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 26
|
||||
ok($r, undef);
|
||||
# 27
|
||||
ok($LOOKUP_FAILURE, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 28
|
||||
ok($_, "Hello, world!");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 29
|
||||
ok($_, "故事都有美麗的結局。");
|
||||
|
||||
# Exchange lookup-failure behaviors
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$lh1->die_for_lookup_failures(0);
|
||||
$lh2->die_for_lookup_failures(1);
|
||||
return 1;
|
||||
};
|
||||
# 30
|
||||
ok($r, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 31
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 32
|
||||
ok($_, "Every story has a happy ending.");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
|
||||
# 33
|
||||
ok($r, undef);
|
||||
# 34
|
||||
ok($LOOKUP_FAILURE, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 35
|
||||
ok($_, "故事都有美麗的結局。");
|
||||
|
||||
# Switch to an non-existing domain
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$lh1->textdomain("Big5");
|
||||
$lh2->textdomain("GB2312");
|
||||
return 1;
|
||||
};
|
||||
# 36
|
||||
ok($r, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 37
|
||||
ok($_, "Hello, world!");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh1->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 38
|
||||
ok($_, "Every story has a happy ending.");
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 39
|
||||
ok($r, undef);
|
||||
# 40
|
||||
ok($LOOKUP_FAILURE, 1);
|
||||
$r = eval {
|
||||
undef $LOOKUP_FAILURE;
|
||||
$_ = $lh2->maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 41
|
||||
ok($r, undef);
|
||||
# 42
|
||||
ok($LOOKUP_FAILURE, 1);
|
275
t/07-f-basic.t
Executable file
275
t/07-f-basic.t
Executable file
@ -0,0 +1,275 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Basic test suite for the functional interface
|
||||
# Copyright (c) 2003-2008 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 41 }
|
||||
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
delete $ENV{$_}
|
||||
foreach qw(LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES LC_NUMERIC
|
||||
LC_MONETARY LC_TIME LANG);
|
||||
|
||||
# Basic test suite
|
||||
# bindtextdomain
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
$_ = bindtextdomain("test", $LOCALEDIR);
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_, $LOCALEDIR);
|
||||
|
||||
# textdomain
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
$_ = textdomain("test");
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_, "test");
|
||||
|
||||
# get_handle
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
|
||||
# maketext
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 6
|
||||
ok($r, 1);
|
||||
# 7
|
||||
ok($_, "Hiya :)");
|
||||
|
||||
# __ (shortcut to maketext)
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 8
|
||||
ok($r, 1);
|
||||
# 9
|
||||
ok($_, "Hiya :)");
|
||||
|
||||
# N_ (do nothing)
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_ = N_("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 10
|
||||
ok($r, 1);
|
||||
# 11
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# N_ (do nothing)
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
# <20><><EFBFBD>l<EFBFBD><6C><EFBFBD>A<EFBFBD>o<EFBFBD>ɤj<C9A4><6A><EFBFBD>ʡI :p <20>]From: <20>x<EFBFBD>W<EFBFBD>R<EFBFBD>E<EFBFBD><45><EFBFBD>^
|
||||
@_ = N_("Hello, world!", "Cool!", "Big watermelon");
|
||||
return 1;
|
||||
};
|
||||
# 12
|
||||
ok($r, 1);
|
||||
# 13
|
||||
ok($_[0], "Hello, world!");
|
||||
# 14
|
||||
ok($_[1], "Cool!");
|
||||
# 15
|
||||
ok($_[2], "Big watermelon");
|
||||
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_ = N_("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 16
|
||||
ok($r, 1);
|
||||
# 17
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# maketext
|
||||
# English
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 18
|
||||
ok($r, 1);
|
||||
# 19
|
||||
ok($_[0], "Hiya :)");
|
||||
# 20
|
||||
ok($_[1], "Hiya :) under the File menu");
|
||||
# 21
|
||||
ok($_[2], "Hiya :) under the View menu");
|
||||
|
||||
# Traditional Chinese
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 22
|
||||
ok($r, 1);
|
||||
# 23
|
||||
ok($_[0], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 24
|
||||
ok($_[1], "<22>ɮ<C9AE><D7BF><EFBFBD><EFBFBD>U<EFBFBD><55><EFBFBD>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 25
|
||||
ok($_[2], "<22>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD><55><EFBFBD>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Simplified Chinese
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-cn");
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 26
|
||||
ok($r, 1);
|
||||
# 27
|
||||
ok($_[0], "<22><><EFBFBD>Һá<D2BA>");
|
||||
# 28
|
||||
ok($_[1], "<22><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>µĴ<C2B5><C4B4>Һá<D2BA>");
|
||||
# 29
|
||||
ok($_[2], "<22><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>µĴ<C2B5><C4B4>Һá<D2BA>");
|
||||
|
||||
# maketext - by environment
|
||||
# English
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
$ENV{"LANG"} = "en";
|
||||
get_handle();
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 30
|
||||
ok($r, 1);
|
||||
# 31
|
||||
ok($_[0], "Hiya :)");
|
||||
# 32
|
||||
ok($_[1], "Hiya :) under the File menu");
|
||||
# 33
|
||||
ok($_[2], "Hiya :) under the View menu");
|
||||
|
||||
# Traditional Chinese
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
$ENV{"LANG"} = "zh-tw";
|
||||
get_handle();
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 34
|
||||
ok($r, 1);
|
||||
# 35
|
||||
ok($_[0], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 36
|
||||
ok($_[1], "<22>ɮ<C9AE><D7BF><EFBFBD><EFBFBD>U<EFBFBD><55><EFBFBD>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 37
|
||||
ok($_[2], "<22>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD><55><EFBFBD>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Simplified Chinese
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
$ENV{"LANG"} = "zh-cn";
|
||||
get_handle();
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = pmaketext("Menu|View|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 38
|
||||
ok($r, 1);
|
||||
# 39
|
||||
ok($_[0], "<22><><EFBFBD>Һá<D2BA>");
|
||||
# 40
|
||||
ok($_[1], "<22><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>µĴ<C2B5><C4B4>Һá<D2BA>");
|
||||
# 41
|
||||
ok($_[2], "<22><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>µĴ<C2B5><C4B4>Һá<D2BA>");
|
344
t/08-f-errors.t
Executable file
344
t/08-f-errors.t
Executable file
@ -0,0 +1,344 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite on the functional interface for the behavior when something goes wrong
|
||||
# Copyright (c) 2003-2008 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 39 }
|
||||
|
||||
use Encode qw();
|
||||
use FindBin;
|
||||
use File::Basename qw(basename);
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($THIS_FILE $LOCALEDIR $r);
|
||||
$THIS_FILE = basename($0);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
sub find_system_mo();
|
||||
|
||||
# find_system_mo: Find a safe system MO to be tested
|
||||
sub find_system_mo() {
|
||||
local ($_, %_);
|
||||
my %cands;
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
# Find all the system MO files
|
||||
%cands = qw();
|
||||
foreach my $dir (@Locale::Maketext::Gettext::Functions::SYSTEM_LOCALEDIRS) {
|
||||
my ($DH, @langs);
|
||||
next unless -d $dir;
|
||||
|
||||
@langs = qw();
|
||||
opendir $DH, $dir or die "$THIS_FILE: $dir: $!";
|
||||
while (defined($_ = readdir $DH)) {
|
||||
my $dir1;
|
||||
$dir1 = catfile($dir, $_, "LC_MESSAGES");
|
||||
push @langs, $_ if -d $dir1 && -r $dir1;
|
||||
}
|
||||
closedir $DH or die "$THIS_FILE: $dir: $!";
|
||||
|
||||
foreach my $lang (sort @langs) {
|
||||
my $dir1;
|
||||
$dir1 = catfile($dir, $lang, "LC_MESSAGES");
|
||||
opendir $DH, $dir1 or die "$THIS_FILE: $dir1: $!";
|
||||
while (defined($_ = readdir $DH)) {
|
||||
my ($file, $domain);
|
||||
$file = catfile($dir1, $_);
|
||||
next unless -f $file && -r $file && /^(.+)\.mo$/;
|
||||
$domain = $1;
|
||||
$cands{$file} = [$lang, $domain];
|
||||
}
|
||||
closedir $DH or die "$THIS_FILE: $dir1: $!";
|
||||
}
|
||||
}
|
||||
# Check each MO file, from the newest
|
||||
foreach my $file (sort { (stat $b)[9] <=> (stat $a)[9] } keys %cands) {
|
||||
my ($FH, $size, $content, $charset, $lang, $domain);
|
||||
$size = (stat $file)[7];
|
||||
open $FH, $file or die "$THIS_FILE: $file: $!";
|
||||
read $FH, $content, $size or die "$THIS_FILE: $file: $!";
|
||||
close $FH or die "$THIS_FILE: $file: $!";
|
||||
next unless $content =~ /Project-Id-Version:/;
|
||||
next unless $content =~ /\s+charset=([^\n]+)/;
|
||||
$charset = $1;
|
||||
next unless defined Encode::resolve_alias($charset);
|
||||
# OK. We take this one
|
||||
($lang, $domain) = @{$cands{$file}};
|
||||
$lang = lc $lang;
|
||||
$lang =~ s/_/-/g;
|
||||
$lang = "i-default" if $lang eq "c";
|
||||
return ($lang, $domain);
|
||||
}
|
||||
# Not found
|
||||
return (undef, undef);
|
||||
}
|
||||
|
||||
# When something goes wrong
|
||||
use vars qw($dir $domain $lang $skip);
|
||||
# GNU gettext never fails!
|
||||
# bindtextdomain
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
$_ = bindtextdomain("test");
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_, undef);
|
||||
|
||||
# textdomain
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
$_ = textdomain;
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_, undef);
|
||||
|
||||
# No text domain claimed yet
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
# 6
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# Non-existing LOCALEDIR
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", "/dev/null");
|
||||
textdomain("test");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 7
|
||||
ok($r, 1);
|
||||
# 8
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# Not-registered DOMAIN
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
textdomain("not_registered");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 9
|
||||
ok($r, 1);
|
||||
# 10
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# PO file not exists
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("no_such_domain", $LOCALEDIR);
|
||||
textdomain("no_such_domain");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 11
|
||||
ok($r, 1);
|
||||
# 12
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# PO file invalid
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("bad", $LOCALEDIR);
|
||||
textdomain("bad");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 13
|
||||
ok($r, 1);
|
||||
# 14
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# No such message
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_[0] = __("[*,_1,non-existing message,non-existing messages]", 1);
|
||||
$_[1] = __("[*,_1,non-existing message,non-existing messages]", 3);
|
||||
$_[2] = pmaketext("Menu|View|", "[*,_1,non-existing message,non-existing messages]", 1);
|
||||
$_[3] = pmaketext("Menu|View|", "[*,_1,non-existing message,non-existing messages]", 3);
|
||||
$_[4] = pmaketext("Menu|None|", "Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 15
|
||||
ok($r, 1);
|
||||
# 16
|
||||
ok($_[0], "1 non-existing message");
|
||||
# 17
|
||||
ok($_[1], "3 non-existing messages");
|
||||
# 18
|
||||
ok($_[2], "1 non-existing message");
|
||||
# 19
|
||||
ok($_[3], "3 non-existing messages");
|
||||
# 20
|
||||
ok($_[4], "Hello, world!");
|
||||
|
||||
# get_handle before textdomain
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
get_handle("en");
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 21
|
||||
ok($r, 1);
|
||||
# 22
|
||||
ok($_, "Hiya :)");
|
||||
|
||||
# bindtextdomain after textdomain
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
get_handle("en");
|
||||
textdomain("test2");
|
||||
bindtextdomain("test2", $LOCALEDIR);
|
||||
$_ = __("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 23
|
||||
ok($r, 1);
|
||||
# 24
|
||||
ok($_, "Pray it.");
|
||||
|
||||
# multibyte keys
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
key_encoding("Big5");
|
||||
$_ = maketext("<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
return 1;
|
||||
};
|
||||
# 25
|
||||
ok($r, 1);
|
||||
# 26
|
||||
ok($_, "<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", "/dev/null");
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
key_encoding("Big5");
|
||||
$_ = maketext("<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
return 1;
|
||||
};
|
||||
# 27
|
||||
ok($r, 1);
|
||||
# 28
|
||||
ok($_, "<22>]<5D><><EFBFBD>]<5D>w<EFBFBD>^");
|
||||
|
||||
# Maketext before and after binding text domain
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
__("Hello, world!");
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 29
|
||||
ok($r, 1);
|
||||
# 30
|
||||
ok($_, "Hiya :)");
|
||||
|
||||
# Switch to a domain that is not binded yet
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
get_handle("en");
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
textdomain("test2");
|
||||
$_ = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 31
|
||||
ok($r, 1);
|
||||
# 32
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# N_: different context - string to array
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
@_ = N_("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 33
|
||||
ok($r, 1);
|
||||
# 34
|
||||
ok($_[0], "Hello, world!");
|
||||
# 35
|
||||
ok($_[1], undef);
|
||||
|
||||
# N_: different context - array to string
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_ = N_("Hello, world!", "Cool!", "Big watermelon");
|
||||
return 1;
|
||||
};
|
||||
# 36
|
||||
ok($r, 1);
|
||||
# 37
|
||||
ok($_, "Hello, world!");
|
||||
|
||||
# Search system locale directories
|
||||
($lang, $domain) = find_system_mo;
|
||||
$skip = defined $domain? 0: 1;
|
||||
$r = eval {
|
||||
return if $skip;
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
textdomain($domain);
|
||||
get_handle($lang);
|
||||
$_ = maketext("");
|
||||
# Skip if $Lexicon{""} does not exists
|
||||
$skip = 1 if $_ eq "";
|
||||
return 1;
|
||||
};
|
||||
# 38
|
||||
skip($skip, $r, 1, $@);
|
||||
# 39
|
||||
skip($skip, $_, qr/Project-Id-Version:/);
|
282
t/09-f-encodings.t
Executable file
282
t/09-f-encodings.t
Executable file
@ -0,0 +1,282 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite on the functional interface for different encodings
|
||||
# Copyright (c) 2003-2007 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 34 }
|
||||
|
||||
use Encode qw();
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
|
||||
# Different encodings
|
||||
# English
|
||||
# Find the default encoding
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_ = encoding();
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_, "US-ASCII");
|
||||
|
||||
# Traditional Chinese
|
||||
# Find the default encoding
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
$_ = encoding();
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_, "Big5");
|
||||
|
||||
# Turn to Big5
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
encoding("Big5");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
# 6
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Turn to UTF-8
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
encoding("UTF-8");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 7
|
||||
ok($r, 1);
|
||||
# 8
|
||||
ok($_, "大家好。");
|
||||
|
||||
# Turn to UTF-16LE
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
encoding("UTF-16LE");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 9
|
||||
ok($r, 1);
|
||||
# 10
|
||||
ok($_, "'Y<>[}Y0");
|
||||
|
||||
# Find the default encoding, in UTF-8
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
textdomain("test_utf8");
|
||||
get_handle("zh-tw");
|
||||
$_ = encoding();
|
||||
return 1;
|
||||
};
|
||||
# 11
|
||||
ok($r, 1);
|
||||
# 12
|
||||
ok($_, "UTF-8");
|
||||
|
||||
# Turn to UTF-8
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
textdomain("test_utf8");
|
||||
get_handle("zh-tw");
|
||||
encoding("UTF-8");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 13
|
||||
ok($r, 1);
|
||||
# 14
|
||||
ok($_, "大家好。");
|
||||
|
||||
# Turn to Big5
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
textdomain("test_utf8");
|
||||
get_handle("zh-tw");
|
||||
encoding("Big5");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 15
|
||||
ok($r, 1);
|
||||
# 16
|
||||
ok($_, "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
|
||||
# Turn to UTF-16LE
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
textdomain("test_utf8");
|
||||
get_handle("zh-tw");
|
||||
encoding("UTF-16LE");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 17
|
||||
ok($r, 1);
|
||||
# 18
|
||||
ok($_, "'Y<>[}Y0");
|
||||
|
||||
# Find the default encoding
|
||||
# Simplified Chinese
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
textdomain("test_utf8");
|
||||
get_handle("zh-cn");
|
||||
$_ = encoding();
|
||||
return 1;
|
||||
};
|
||||
# 19
|
||||
ok($r, 1);
|
||||
# 20
|
||||
ok($_, "UTF-8");
|
||||
|
||||
# Turn to GB2312
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test_utf8", $LOCALEDIR);
|
||||
textdomain("test_utf8");
|
||||
get_handle("zh-cn");
|
||||
encoding("GB2312");
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 21
|
||||
ok($r, 1);
|
||||
# 22
|
||||
ok($_, "<22><><EFBFBD>Һá<D2BA>");
|
||||
|
||||
# Encode failure
|
||||
# FB_DEFAULT
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test2", $LOCALEDIR);
|
||||
textdomain("test2");
|
||||
get_handle("zh-tw");
|
||||
encoding("GB2312");
|
||||
$_ = maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 23
|
||||
ok($r, 1);
|
||||
# 24
|
||||
ok($_, "<22><><EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>?<3F><>?<3F>֡<EFBFBD>");
|
||||
|
||||
# FB_CROAK
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test2", $LOCALEDIR);
|
||||
textdomain("test2");
|
||||
get_handle("zh-tw");
|
||||
encoding("GB2312");
|
||||
encode_failure(Encode::FB_CROAK);
|
||||
$_ = maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 25
|
||||
ok($r, undef);
|
||||
# 26
|
||||
ok($@, qr/does not map to/);
|
||||
|
||||
# FB_HTMLCREF
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test2", $LOCALEDIR);
|
||||
textdomain("test2");
|
||||
get_handle("zh-tw");
|
||||
encoding("GB2312");
|
||||
encode_failure(Encode::FB_HTMLCREF);
|
||||
$_ = maketext("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 27
|
||||
ok($r, 1);
|
||||
# 28
|
||||
ok($_, "<22><><EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>麗<3B><>結<3B>֡<EFBFBD>");
|
||||
|
||||
# Return the unencoded UTF-8 text
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
encoding(undef);
|
||||
$_ = maketext("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 29
|
||||
ok($r, 1);
|
||||
# 30
|
||||
ok($_, "\x{5927}\x{5BB6}\x{597D}\x{3002}");
|
||||
# 31
|
||||
ok((Encode::is_utf8($_)? "utf8": "non-utf8"), "utf8");
|
||||
|
||||
# Return the unencoded UTF-8 text with auto lexicon
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-tw");
|
||||
encoding(undef);
|
||||
$_ = maketext("Big watermelon");
|
||||
return 1;
|
||||
};
|
||||
# 32
|
||||
ok($r, 1);
|
||||
# 33
|
||||
ok($_, "Big watermelon");
|
||||
# 34
|
||||
ok((Encode::is_utf8($_)? "utf8": "non-utf8"), "utf8");
|
416
t/10-f-switching.t
Executable file
416
t/10-f-switching.t
Executable file
@ -0,0 +1,416 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite on the functional interface for switching between different settings
|
||||
# Copyright (c) 2003-2008 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 63 }
|
||||
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir catfile);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
delete $ENV{$_}
|
||||
foreach qw(LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES LC_NUMERIC
|
||||
LC_MONETARY LC_TIME LANG);
|
||||
|
||||
# Switching between different settings
|
||||
use File::Copy qw(copy);
|
||||
use vars qw($dir1 $dir2 $dir3 $f1 $f11 $f12 $f2 $f21 $f3 $f31 $class);
|
||||
|
||||
# dmaketext in the middle
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
get_handle("en");
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
bindtextdomain("test2", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[2] = __("Every story has a happy ending.");
|
||||
$_[3] = pmaketext("Menu|File|", "Every story has a happy ending.");
|
||||
$_[4] = dmaketext("test2", "Hello, world!");
|
||||
$_[5] = dpmaketext("test2", "Menu|File|", "Hello, world!");
|
||||
$_[6] = dmaketext("test2", "Every story has a happy ending.");
|
||||
$_[7] = dpmaketext("test2", "Menu|File|", "Every story has a happy ending.");
|
||||
$_[8] = __("Hello, world!");
|
||||
$_[9] = pmaketext("Menu|File|", "Hello, world!");
|
||||
$_[10] = __("Every story has a happy ending.");
|
||||
$_[11] = pmaketext("Menu|File|", "Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_[0], "Hiya :)");
|
||||
# 3
|
||||
ok($_[1], "Hiya :) under the File menu");
|
||||
# 4
|
||||
ok($_[2], "Every story has a happy ending.");
|
||||
# 5
|
||||
ok($_[3], "Every story has a happy ending.");
|
||||
# 6
|
||||
ok($_[4], "Hello, world!");
|
||||
# 6
|
||||
ok($_[5], "Hello, world!");
|
||||
# 8
|
||||
ok($_[6], "Pray it.");
|
||||
# 9
|
||||
ok($_[7], "Pray it under the File menu");
|
||||
# 10
|
||||
ok($_[8], "Hiya :)");
|
||||
# 11
|
||||
ok($_[9], "Hiya :) under the File menu");
|
||||
# 12
|
||||
ok($_[10], "Every story has a happy ending.");
|
||||
# 13
|
||||
ok($_[11], "Every story has a happy ending.");
|
||||
|
||||
# Switch between domains
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
bindtextdomain("test2", $LOCALEDIR);
|
||||
get_handle("en");
|
||||
textdomain("test");
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = __("Every story has a happy ending.");
|
||||
textdomain("test2");
|
||||
$_[2] = __("Hello, world!");
|
||||
$_[3] = __("Every story has a happy ending.");
|
||||
textdomain("test");
|
||||
$_[4] = __("Hello, world!");
|
||||
$_[5] = __("Every story has a happy ending.");
|
||||
return 1;
|
||||
};
|
||||
# 14
|
||||
ok($r, 1);
|
||||
# 15
|
||||
ok($_[0], "Hiya :)");
|
||||
# 16
|
||||
ok($_[1], "Every story has a happy ending.");
|
||||
# 17
|
||||
ok($_[2], "Hello, world!");
|
||||
# 18
|
||||
ok($_[3], "Pray it.");
|
||||
# 19
|
||||
ok($_[4], "Hiya :)");
|
||||
# 20
|
||||
ok($_[5], "Every story has a happy ending.");
|
||||
|
||||
# Switch between languages
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_[0] = __("Hello, world!");
|
||||
get_handle("zh-tw");
|
||||
$_[1] = __("Hello, world!");
|
||||
get_handle("zh-cn");
|
||||
$_[2] = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 21
|
||||
ok($r, 1);
|
||||
# 22
|
||||
ok($_[0], "Hiya :)");
|
||||
# 23
|
||||
ok($_[1], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 24
|
||||
ok($_[2], "<22><><EFBFBD>Һá<D2BA>");
|
||||
|
||||
# Switch between languages - by environment
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
$ENV{"LANG"} = "en";
|
||||
get_handle();
|
||||
$_[0] = __("Hello, world!");
|
||||
$ENV{"LANG"} = "zh-tw";
|
||||
get_handle();
|
||||
$_[1] = __("Hello, world!");
|
||||
$ENV{"LANG"} = "zh-cn";
|
||||
get_handle();
|
||||
$_[2] = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 25
|
||||
ok($r, 1);
|
||||
# 26
|
||||
ok($_[0], "Hiya :)");
|
||||
# 27
|
||||
ok($_[1], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 28
|
||||
ok($_[2], "<22><><EFBFBD>Һá<D2BA>");
|
||||
|
||||
# Switch between different language methods
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_[0] = __("Hello, world!");
|
||||
$ENV{"LANG"} = "zh-tw";
|
||||
get_handle();
|
||||
$_[1] = __("Hello, world!");
|
||||
get_handle("zh-cn");
|
||||
$_[2] = __("Hello, world!");
|
||||
$ENV{"LANG"} = "en";
|
||||
get_handle();
|
||||
$_[3] = __("Hello, world!");
|
||||
return 1;
|
||||
};
|
||||
# 29
|
||||
ok($r, 1);
|
||||
# 30
|
||||
ok($_[0], "Hiya :)");
|
||||
# 31
|
||||
ok($_[1], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 32
|
||||
ok($_[2], "<22><><EFBFBD>Һá<D2BA>");
|
||||
# 33
|
||||
ok($_[3], "Hiya :)");
|
||||
|
||||
# Reuse of a same text domain class
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
$ENV{"LANG"} = "en";
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle();
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = __("Every story has a happy ending.");
|
||||
$_[2] = ref($Locale::Maketext::Gettext::Functions::LH);
|
||||
$_[2] =~ s/^(.+)::.*?$/$1/;
|
||||
|
||||
bindtextdomain("test2", $LOCALEDIR);
|
||||
textdomain("test2");
|
||||
get_handle("zh-tw");
|
||||
$_[3] = __("Hello, world!");
|
||||
$_[4] = __("Every story has a happy ending.");
|
||||
|
||||
bindtextdomain("test", "/dev/null");
|
||||
textdomain("test");
|
||||
get_handle("en");
|
||||
$_[5] = __("Hello, world!");
|
||||
$_[6] = __("Every story has a happy ending.");
|
||||
|
||||
bindtextdomain("test", $LOCALEDIR);
|
||||
textdomain("test");
|
||||
get_handle("zh-cn");
|
||||
$_[7] = __("Hello, world!");
|
||||
$_[8] = __("Every story has a happy ending.");
|
||||
$_[9] = ref($Locale::Maketext::Gettext::Functions::LH);
|
||||
$_[9] =~ s/^(.+)::.*?$/$1/;
|
||||
return 1;
|
||||
};
|
||||
# 34
|
||||
ok($r, 1);
|
||||
# 35
|
||||
ok($_[0], "Hiya :)");
|
||||
# 36
|
||||
ok($_[1], "Every story has a happy ending.");
|
||||
# 37
|
||||
ok($_[3], "Hello, world!");
|
||||
# 38
|
||||
ok($_[4], "<22>G<EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>R<EFBFBD><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>C");
|
||||
# 39
|
||||
ok($_[5], "Hello, world!");
|
||||
# 40
|
||||
ok($_[6], "Every story has a happy ending.");
|
||||
# 41
|
||||
ok($_[7], "<22><><EFBFBD>Һá<D2BA>");
|
||||
# 42
|
||||
ok($_[8], "Every story has a happy ending.");
|
||||
# 43
|
||||
ok($_[2], $_[9]);
|
||||
|
||||
# Language addition/removal
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
$dir1 = catdir($LOCALEDIR, "en", "LC_MESSAGES");
|
||||
$dir2 = catdir($LOCALEDIR, "zh_TW", "LC_MESSAGES");
|
||||
$dir3 = catdir($LOCALEDIR, "zh_CN", "LC_MESSAGES");
|
||||
$f1 = catfile($dir1, "test_dyn.mo");
|
||||
$f11 = catfile($dir1, "test.mo");
|
||||
$f2 = catfile($dir2, "test_dyn.mo");
|
||||
$f21 = catfile($dir2, "test.mo");
|
||||
$f3 = catfile($dir3, "test_dyn.mo");
|
||||
$f31 = catfile($dir3, "test.mo");
|
||||
unlink $f1;
|
||||
unlink $f2;
|
||||
unlink $f3;
|
||||
|
||||
bindtextdomain("test_dyn", $LOCALEDIR);
|
||||
textdomain("test_dyn");
|
||||
get_handle("zh-tw");
|
||||
$_[0] = __("Hello, world!");
|
||||
get_handle("zh-cn");
|
||||
$_[1] = __("Hello, world!");
|
||||
|
||||
copy $f21, $f2 or die "ERROR: $f21 $f2: $!";
|
||||
textdomain("test_dyn");
|
||||
get_handle("zh-tw");
|
||||
$_[2] = __("Hello, world!");
|
||||
get_handle("zh-cn");
|
||||
$_[3] = __("Hello, world!");
|
||||
|
||||
unlink $f2;
|
||||
copy $f31, $f3 or die "ERROR: $f31 $f3: $!";
|
||||
textdomain("test_dyn");
|
||||
get_handle("zh-tw");
|
||||
$_[4] = __("Hello, world!");
|
||||
get_handle("zh-cn");
|
||||
$_[5] = __("Hello, world!");
|
||||
|
||||
copy $f21, $f2 or die "ERROR: $f21 $f2: $!";
|
||||
textdomain("test_dyn");
|
||||
get_handle("zh-tw");
|
||||
$_[6] = __("Hello, world!");
|
||||
get_handle("zh-cn");
|
||||
$_[7] = __("Hello, world!");
|
||||
|
||||
unlink $f2;
|
||||
unlink $f3;
|
||||
textdomain("test_dyn");
|
||||
get_handle("zh-tw");
|
||||
$_[8] = __("Hello, world!");
|
||||
get_handle("zh-cn");
|
||||
$_[9] = __("Hello, world!");
|
||||
|
||||
unlink $f1;
|
||||
unlink $f2;
|
||||
unlink $f3;
|
||||
return 1;
|
||||
};
|
||||
# 44
|
||||
ok($r, 1);
|
||||
# 45
|
||||
ok($_[0], "Hello, world!");
|
||||
# 46
|
||||
ok($_[1], "Hello, world!");
|
||||
# 47
|
||||
ok($_[2], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 48
|
||||
ok($_[3], "Hello, world!");
|
||||
# 49
|
||||
ok($_[4], "Hello, world!");
|
||||
# 50
|
||||
ok($_[5], "<22><><EFBFBD>Һá<D2BA>");
|
||||
# 51
|
||||
ok($_[6], "<22>j<EFBFBD>a<EFBFBD>n<EFBFBD>C");
|
||||
# 52
|
||||
ok($_[7], "<22><><EFBFBD>Һá<D2BA>");
|
||||
# 53
|
||||
ok($_[8], "Hello, world!");
|
||||
# 54
|
||||
ok($_[9], "Hello, world!");
|
||||
|
||||
# Garbage collection - drop abandoned language handles
|
||||
$r = eval {
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
$dir1 = catdir($LOCALEDIR, "en", "LC_MESSAGES");
|
||||
$dir2 = catdir($LOCALEDIR, "zh_TW", "LC_MESSAGES");
|
||||
$dir3 = catdir($LOCALEDIR, "zh_CN", "LC_MESSAGES");
|
||||
$f1 = catfile($dir1, "test_dyn.mo");
|
||||
$f11 = catfile($dir1, "test.mo");
|
||||
$f2 = catfile($dir2, "test_dyn.mo");
|
||||
$f21 = catfile($dir2, "test.mo");
|
||||
$f3 = catfile($dir3, "test_dyn.mo");
|
||||
$f31 = catfile($dir3, "test.mo");
|
||||
unlink $f1;
|
||||
unlink $f2;
|
||||
unlink $f3;
|
||||
|
||||
copy $f11, $f1 or die "ERROR: $f11 $f1: $!";
|
||||
copy $f21, $f2 or die "ERROR: $f21 $f2: $!";
|
||||
textdomain("test_dyn");
|
||||
get_handle("en");
|
||||
get_handle("zh-tw");
|
||||
get_handle("zh-cn");
|
||||
$class = ref($Locale::Maketext::Gettext::Functions::LH);
|
||||
$class =~ s/^(.+)::.*?$/$1/;
|
||||
|
||||
unlink $f2;
|
||||
copy $f31, $f3 or die "ERROR: $f31 $f3: $!";
|
||||
textdomain("test_dyn");
|
||||
get_handle("en");
|
||||
get_handle("zh-tw");
|
||||
get_handle("zh-cn");
|
||||
@_ = grep /^$class/, keys %Locale::Maketext::Gettext::Functions::LHS;
|
||||
return 1;
|
||||
};
|
||||
# 55
|
||||
ok($r, 1);
|
||||
# 56
|
||||
ok(scalar(@_), 0);
|
||||
|
||||
# Reload the text
|
||||
$r = eval {
|
||||
$dir1 = catdir($LOCALEDIR, "en", "LC_MESSAGES");
|
||||
$f1 = catfile($dir1, "test_reload.mo");
|
||||
$f11 = catfile($dir1, "test.mo");
|
||||
$f12 = catfile($dir1, "test2.mo");
|
||||
unlink $f1;
|
||||
copy $f11, $f1 or die "ERROR: $f11 $f1: $!";
|
||||
use Locale::Maketext::Gettext::Functions;
|
||||
Locale::Maketext::Gettext::Functions::_reset();
|
||||
@_ = qw();
|
||||
bindtextdomain("test_reload", $LOCALEDIR);
|
||||
textdomain("test_reload");
|
||||
get_handle("en");
|
||||
$_[0] = __("Hello, world!");
|
||||
$_[1] = __("Every story has a happy ending.");
|
||||
unlink $f1;
|
||||
copy $f12, $f1 or die "ERROR: $f12 $f1: $!";
|
||||
$_[2] = __("Hello, world!");
|
||||
$_[3] = __("Every story has a happy ending.");
|
||||
reload_text;
|
||||
$_[4] = __("Hello, world!");
|
||||
$_[5] = __("Every story has a happy ending.");
|
||||
unlink $f1;
|
||||
return 1;
|
||||
};
|
||||
# 57
|
||||
ok($r, 1);
|
||||
# 58
|
||||
ok($_[0], "Hiya :)");
|
||||
# 59
|
||||
ok($_[1], "Every story has a happy ending.");
|
||||
# 60
|
||||
ok($_[2], "Hiya :)");
|
||||
# 61
|
||||
ok($_[3], "Every story has a happy ending.");
|
||||
# 62
|
||||
ok($_[4], "Hello, world!");
|
||||
# 63
|
||||
ok($_[5], "Pray it.");
|
||||
|
||||
# Garbage collection
|
||||
unlink catfile($LOCALEDIR, "en", "LC_MESSAGES", "test_dyn.mo");
|
||||
unlink catfile($LOCALEDIR, "zh_TW", "LC_MESSAGES", "test_dyn.mo");
|
||||
unlink catfile($LOCALEDIR, "zh_CN", "LC_MESSAGES", "test_dyn.mo");
|
||||
unlink catfile($LOCALEDIR, "en", "LC_MESSAGES", "test_reload.mo");
|
92
t/11-command-line.t
Executable file
92
t/11-command-line.t
Executable file
@ -0,0 +1,92 @@
|
||||
#! /usr/bin/perl -w
|
||||
# Test suite on the maketext script
|
||||
# Copyright (c) 2003-2007 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test;
|
||||
|
||||
BEGIN { plan tests => 10 }
|
||||
|
||||
use FindBin;
|
||||
use File::Spec::Functions qw(catdir catfile updir);
|
||||
use lib $FindBin::Bin;
|
||||
use vars qw($LOCALEDIR $r $maketext);
|
||||
$LOCALEDIR = catdir($FindBin::Bin, "locale");
|
||||
$maketext = catdir($FindBin::Bin, updir, "blib", "script", "maketext");
|
||||
|
||||
# The maketext script
|
||||
# Ordinary text unchanged
|
||||
$r = eval {
|
||||
delete $ENV{"LANG"};
|
||||
delete $ENV{"LANGUAGE"};
|
||||
delete $ENV{"TEXTDOMAINDIR"};
|
||||
delete $ENV{"TEXTDOMAIN"};
|
||||
@_ = `"$maketext" "Hello, world!"`;
|
||||
return 1;
|
||||
};
|
||||
# 1
|
||||
ok($r, 1);
|
||||
# 2
|
||||
ok($_[0], "Hello, world!");
|
||||
|
||||
# Specify the text domain by the -d argument
|
||||
# English
|
||||
$r = eval {
|
||||
$ENV{"LANG"} = "C";
|
||||
$ENV{"LANGUAGE"} = "C";
|
||||
$ENV{"TEXTDOMAINDIR"} = $LOCALEDIR;
|
||||
delete $ENV{"TEXTDOMAIN"};
|
||||
@_ = `"$maketext" -d test "Hello, world!"`;
|
||||
return 1;
|
||||
};
|
||||
# 3
|
||||
ok($r, 1);
|
||||
# 4
|
||||
ok($_[0], "Hiya :)");
|
||||
|
||||
# Specify the text domain by the environment variable
|
||||
# English
|
||||
$r = eval {
|
||||
$ENV{"LANG"} = "C";
|
||||
$ENV{"LANGUAGE"} = "C";
|
||||
$ENV{"TEXTDOMAINDIR"} = $LOCALEDIR;
|
||||
$ENV{"TEXTDOMAIN"} = "test";
|
||||
@_ = `"$maketext" "Hello, world!"`;
|
||||
return 1;
|
||||
};
|
||||
# 5
|
||||
ok($r, 1);
|
||||
# 6
|
||||
ok($_[0], "Hiya :)");
|
||||
|
||||
# The -s argument
|
||||
$r = eval {
|
||||
$ENV{"LANG"} = "C";
|
||||
$ENV{"LANGUAGE"} = "C";
|
||||
$ENV{"TEXTDOMAINDIR"} = $LOCALEDIR;
|
||||
$ENV{"TEXTDOMAIN"} = "test";
|
||||
@_ = `"$maketext" -s "Hello, world!"`;
|
||||
return 1;
|
||||
};
|
||||
# 7
|
||||
ok($r, 1);
|
||||
# 8
|
||||
ok($_[0], "Hiya :)\n");
|
||||
|
||||
# Maketext
|
||||
$r = eval {
|
||||
$ENV{"LANG"} = "C";
|
||||
$ENV{"LANGUAGE"} = "C";
|
||||
$ENV{"TEXTDOMAINDIR"} = $LOCALEDIR;
|
||||
$ENV{"TEXTDOMAIN"} = "test";
|
||||
@_ = `"$maketext" -s "[*,_1,directory,directories]" 5`;
|
||||
return 1;
|
||||
};
|
||||
# 9
|
||||
ok($r, 1);
|
||||
# 10
|
||||
ok($_[0], "5 directories\n");
|
5
t/99-pod.t
Executable file
5
t/99-pod.t
Executable file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/perl
|
||||
use Test::More;
|
||||
eval "use Test::Pod 1.00";
|
||||
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
|
||||
all_pod_files_ok();
|
24
t/T_L10N.pm
Normal file
24
t/T_L10N.pm
Normal file
@ -0,0 +1,24 @@
|
||||
# Test localization class and its subclasses
|
||||
# Copyright (c) 2003 imacat. All rights reserved. This program is free
|
||||
# software; you can redistribute it and/or modify it under the same terms
|
||||
# as Perl itself.
|
||||
|
||||
package T_L10N;
|
||||
use base qw(Locale::Maketext::Gettext);
|
||||
|
||||
return 1;
|
||||
|
||||
package T_L10N::en;
|
||||
use base qw(Locale::Maketext::Gettext);
|
||||
|
||||
return 1;
|
||||
|
||||
package T_L10N::zh_tw;
|
||||
use base qw(Locale::Maketext::Gettext);
|
||||
|
||||
return 1;
|
||||
|
||||
package T_L10N::zh_cn;
|
||||
use base qw(Locale::Maketext::Gettext);
|
||||
|
||||
return 1;
|
BIN
t/locale/C/LC_MESSAGES/test.mo
Normal file
BIN
t/locale/C/LC_MESSAGES/test.mo
Normal file
Binary file not shown.
1
t/locale/en/LC_MESSAGES/bad.mo
Normal file
1
t/locale/en/LC_MESSAGES/bad.mo
Normal file
@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
BIN
t/locale/en/LC_MESSAGES/test.mo
Normal file
BIN
t/locale/en/LC_MESSAGES/test.mo
Normal file
Binary file not shown.
BIN
t/locale/en/LC_MESSAGES/test2.mo
Normal file
BIN
t/locale/en/LC_MESSAGES/test2.mo
Normal file
Binary file not shown.
BIN
t/locale/en/LC_MESSAGES/test_be.mo
Normal file
BIN
t/locale/en/LC_MESSAGES/test_be.mo
Normal file
Binary file not shown.
BIN
t/locale/en/LC_MESSAGES/test_utf8.mo
Normal file
BIN
t/locale/en/LC_MESSAGES/test_utf8.mo
Normal file
Binary file not shown.
BIN
t/locale/zh_CN/LC_MESSAGES/test.mo
Normal file
BIN
t/locale/zh_CN/LC_MESSAGES/test.mo
Normal file
Binary file not shown.
BIN
t/locale/zh_CN/LC_MESSAGES/test_be.mo
Normal file
BIN
t/locale/zh_CN/LC_MESSAGES/test_be.mo
Normal file
Binary file not shown.
BIN
t/locale/zh_CN/LC_MESSAGES/test_utf8.mo
Normal file
BIN
t/locale/zh_CN/LC_MESSAGES/test_utf8.mo
Normal file
Binary file not shown.
BIN
t/locale/zh_TW/LC_MESSAGES/test.mo
Normal file
BIN
t/locale/zh_TW/LC_MESSAGES/test.mo
Normal file
Binary file not shown.
BIN
t/locale/zh_TW/LC_MESSAGES/test2.mo
Normal file
BIN
t/locale/zh_TW/LC_MESSAGES/test2.mo
Normal file
Binary file not shown.
BIN
t/locale/zh_TW/LC_MESSAGES/test_be.mo
Normal file
BIN
t/locale/zh_TW/LC_MESSAGES/test_be.mo
Normal file
Binary file not shown.
BIN
t/locale/zh_TW/LC_MESSAGES/test_utf8.mo
Normal file
BIN
t/locale/zh_TW/LC_MESSAGES/test_utf8.mo
Normal file
Binary file not shown.
Reference in New Issue
Block a user