]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0202/test.pl
i18n: add--interactive: mark plural strings
[thirdparty/git.git] / t / t0202 / test.pl
1 #!/usr/bin/perl
2 use 5.008;
3 use lib (split(/:/, $ENV{GITPERLLIB}));
4 use strict;
5 use warnings;
6 use POSIX qw(:locale_h);
7 use Test::More tests => 11;
8 use Git::I18N;
9
10 my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;
11
12 ok(1, "Testing Git::I18N with " .
13 ($has_gettext_library
14 ? (defined $Locale::Messages::VERSION
15 ? "Locale::Messages version $Locale::Messages::VERSION"
16 # Versions of Locale::Messages before 1.17 didn't have a
17 # $VERSION variable.
18 : "Locale::Messages version <1.17")
19 : "NO Perl gettext library"));
20 ok(1, "Git::I18N is located at $INC{'Git/I18N.pm'}");
21
22 {
23 my $exports = @Git::I18N::EXPORT;
24 ok($exports, "sanity: Git::I18N has $exports export(s)");
25 }
26 is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N exports everything by default");
27
28 # prototypes
29 {
30 # Add prototypes here when modifying the public interface to add
31 # more gettext wrapper functions.
32 my %prototypes = (qw(
33 __ $
34 __n $$$
35 ));
36 while (my ($sub, $proto) = each %prototypes) {
37 is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype");
38 }
39 }
40
41 # Test basic passthrough in the C locale
42 {
43 local $ENV{LANGUAGE} = 'C';
44 local $ENV{LC_ALL} = 'C';
45 local $ENV{LANG} = 'C';
46
47 my ($got, $expect) = (('TEST: A Perl test string') x 2);
48
49 is(__($got), $expect, "Passing a string through __() in the C locale works");
50
51 my ($got_singular, $got_plural, $expect_singular, $expect_plural) =
52 (('TEST: 1 file', 'TEST: n files') x 2);
53
54 is(__n($got_singular, $got_plural, 1), $expect_singular,
55 "Get singular string through __n() in C locale");
56 is(__n($got_singular, $got_plural, 2), $expect_plural,
57 "Get plural string through __n() in C locale");
58 }
59
60 # Test a basic message on different locales
61 SKIP: {
62 unless ($ENV{GETTEXT_LOCALE}) {
63 # Can't reliably test __() with a non-C locales because the
64 # required locales may not be installed on the system.
65 #
66 # We test for these anyway as part of the shell
67 # tests. Skipping these here will eliminate failures on odd
68 # platforms with incomplete locale data.
69
70 skip "GETTEXT_LOCALE must be set by lib-gettext.sh for exhaustive Git::I18N tests", 2;
71 }
72
73 # The is_IS UTF-8 locale passed from lib-gettext.sh
74 my $is_IS_locale = $ENV{is_IS_locale};
75
76 my $test = sub {
77 my ($got, $expect, $msg, $locale) = @_;
78 # Maybe this system doesn't have the locale we're trying to
79 # test.
80 my $locale_ok = setlocale(LC_ALL, $locale);
81 is(__($got), $expect, "$msg a gettext library + <$locale> locale <$got> turns into <$expect>");
82 };
83
84 my $env_C = sub {
85 $ENV{LANGUAGE} = 'C';
86 $ENV{LC_ALL} = 'C';
87 };
88
89 my $env_is = sub {
90 $ENV{LANGUAGE} = 'is';
91 $ENV{LC_ALL} = $is_IS_locale;
92 };
93
94 # Translation's the same as the original
95 my ($got, $expect) = (('TEST: A Perl test string') x 2);
96
97 if ($has_gettext_library) {
98 {
99 local %ENV; $env_C->();
100 $test->($got, $expect, "With", 'C');
101 }
102
103 {
104 my ($got, $expect) = ($got, 'TILRAUN: Perl tilraunastrengur');
105 local %ENV; $env_is->();
106 $test->($got, $expect, "With", $is_IS_locale);
107 }
108 } else {
109 {
110 local %ENV; $env_C->();
111 $test->($got, $expect, "Without", 'C');
112 }
113
114 {
115 local %ENV; $env_is->();
116 $test->($got, $expect, "Without", 'is');
117 }
118 }
119 }