3
use lib (split(/:/, $ENV{GITPERLLIB}));
6
use POSIX qw(:locale_h);
7
use Test::More tests => 13;
10
my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;
12
ok(1, "Testing Git::I18N with " .
14
? (defined $Locale::Messages::VERSION
15
? "Locale::Messages version $Locale::Messages::VERSION"
16
# Versions of Locale::Messages before 1.17 didn't have a
18
: "Locale::Messages version <1.17")
19
: "NO Perl gettext library"));
20
ok(1, "Git::I18N is located at $INC{'Git/I18N.pm'}");
23
my $exports = @Git::I18N::EXPORT;
24
ok($exports, "sanity: Git::I18N has $exports export(s)");
26
is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N exports everything by default");
30
# Add prototypes here when modifying the public interface to add
31
# more gettext wrapper functions.
37
while (my ($sub, $proto) = each %prototypes) {
38
is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype");
42
# Test basic passthrough in the C locale
44
local $ENV{LANGUAGE} = 'C';
45
local $ENV{LC_ALL} = 'C';
46
local $ENV{LANG} = 'C';
48
my ($got, $expect) = (('TEST: A Perl test string') x 2);
50
is(__($got), $expect, "Passing a string through __() in the C locale works");
52
my ($got_singular, $got_plural, $expect_singular, $expect_plural) =
53
(('TEST: 1 file', 'TEST: n files') x 2);
55
is(__n($got_singular, $got_plural, 1), $expect_singular,
56
"Get singular string through __n() in C locale");
57
is(__n($got_singular, $got_plural, 2), $expect_plural,
58
"Get plural string through __n() in C locale");
60
is(N__($got), $expect, "Passing a string through N__() in the C locale works");
63
# Test a basic message on different locales
65
unless ($ENV{GETTEXT_LOCALE}) {
66
# Can't reliably test __() with a non-C locales because the
67
# required locales may not be installed on the system.
69
# We test for these anyway as part of the shell
70
# tests. Skipping these here will eliminate failures on odd
71
# platforms with incomplete locale data.
73
skip "GETTEXT_LOCALE must be set by lib-gettext.sh for exhaustive Git::I18N tests", 2;
76
# The is_IS UTF-8 locale passed from lib-gettext.sh
77
my $is_IS_locale = $ENV{is_IS_locale};
80
my ($got, $expect, $msg, $locale) = @_;
81
# Maybe this system doesn't have the locale we're trying to
83
my $locale_ok = setlocale(LC_ALL, $locale);
84
is(__($got), $expect, "$msg a gettext library + <$locale> locale <$got> turns into <$expect>");
93
$ENV{LANGUAGE} = 'is';
94
$ENV{LC_ALL} = $is_IS_locale;
97
# Translation's the same as the original
98
my ($got, $expect) = (('TEST: A Perl test string') x 2);
100
if ($has_gettext_library) {
102
local %ENV; $env_C->();
103
$test->($got, $expect, "With", 'C');
107
my ($got, $expect) = ($got, 'TILRAUN: Perl tilraunastrengur');
108
local %ENV; $env_is->();
109
$test->($got, $expect, "With", $is_IS_locale);
113
local %ENV; $env_C->();
114
$test->($got, $expect, "Without", 'C');
118
local %ENV; $env_is->();
119
$test->($got, $expect, "Without", 'is');