~ubuntu-branches/ubuntu/trusty/libintl-perl/trusty

« back to all changes in this revision

Viewing changes to tests/04russian_plural_function.t

  • Committer: Package Import Robot
  • Author(s): Peter Eisentraut
  • Date: 2013-06-29 21:23:42 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20130629212342-3te0y4h5x26hb79b
Tags: 1.23-1
* New upstream release
* Updated standards version
* Changed to Debhelper level 9
* Added build-arch and build-indep targets
* Fixed application of Debian build flags for hardening

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/local/bin/perl -w
 
2
 
 
3
# vim: syntax=perl
 
4
# vim: tabstop=4
 
5
 
 
6
use strict;
 
7
 
 
8
use Test;
 
9
 
 
10
use Locale::gettext_pp;
 
11
 
 
12
BEGIN {
 
13
        plan tests => 2006;
 
14
}
 
15
 
 
16
sub russian_plural {
 
17
    my $n = shift;
 
18
 
 
19
    my ($plural, $nplurals);
 
20
 
 
21
    $nplurals = 3;
 
22
    $plural = ($n % 10 == 1 && $n % 100 != 11 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
 
23
 
 
24
    return ($nplurals, $plural ? $plural : 0);
 
25
}
 
26
 
 
27
# This test uses private functions of Locale::gettext_pp.  Do NOT use this as
 
28
# an example for your own code.
 
29
 
 
30
my $code = 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2';
 
31
 
 
32
my $untainted = Locale::gettext_pp::__untaint_plural_header $code;
 
33
 
 
34
ok length $untainted;
 
35
 
 
36
my $plural_function = Locale::gettext_pp::__compile_plural_function $code;
 
37
 
 
38
ok $plural_function;
 
39
ok ref $plural_function;
 
40
ok 'CODE' eq ref $plural_function;
 
41
 
 
42
foreach my $n (0 .. 1000) {
 
43
    my ($got_nplurals, $got_plural) = $plural_function->($n);
 
44
    my ($wanted_nplurals, $wanted_plural) = russian_plural $n;
 
45
 
 
46
    ok $got_nplurals, $wanted_nplurals,
 
47
       "wanted $wanted_nplurals, got $got_nplurals nplurals for n = $n";
 
48
    ok $got_plural, $wanted_plural,
 
49
       "wanted plural form #$wanted_nplurals, got #$got_nplurals for n = $n";
 
50
 
 
51
 
 
52
    print "$n:$got_plural:$wanted_plural\n";
 
53
}
 
54