1 // testing musl internal __pleval api used in dcngettext
5 unsigned long __pleval(const char *, unsigned long);
7 static void t(const char *s
, unsigned long n
, unsigned long want
)
9 unsigned long got
= __pleval(s
, n
);
11 t_error("__pleval(\"%s\",%lu) failed: got %lu want %lu\n", s
, n
, got
, want
);
14 // evals the expr with the compiler: gettext plural rules follow c syntax
16 unsigned long n, _w; \
17 for (n=0; n<200; n++) { \
27 // recursion depth limit check
28 memset(buf
, '!', 200);
29 memcpy(buf
+200, "n;", 3);
32 memcpy(buf
+51, "n;", 3);
35 memcpy(buf
+50, "n;", 3);
49 T(n
== 1 || n
== 2 ||n
%9==7;);
50 T((n
==1)+!n
+(n
==3););
51 T(n
- 13 - 5 + n
* 3 / 7 - 8;);
52 T(n
+n
>n
==n
-n
<n
?n
/(n
||!!!n
):0-n
;);
53 T((n
<=3>=0)+n
+n
+n
-n
-n
*1*1*1/1%12345678;);
54 T(5<6-4*n
&&n
%3==n
-1;);
57 // the following plural rules are from
58 // http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
62 T((n
==0 ? 0 : n
==1 ? 1 : n
==2 ? 2 : n
%100>=3 && n
%100<=10 ? 3 : n
%100>=11 ? 4 : 5););
63 T((n
%10==1 && n
%100!=11 ? 0 : n
%10>=2 && n
%10<=4 && (n
%100<10 || n
%100>=20) ? 1 : 2););
64 T((n
==1) ? 0 : (n
>=2 && n
<=4) ? 1 : 2;);
65 T((n
==1) ? 0 : n
%10>=2 && n
%10<=4 && (n
%100<10 || n
%100>=20) ? 1 : 2;);
66 T((n
==1 ? 0 : n
%10>=2 && n
%10<=4 && (n
%100<10 || n
%100>=20) ? 1 : 2););
67 T((n
==1) ? 0 : (n
==2) ? 1 : (n
!= 8 && n
!= 11) ? 2 : 3;);
68 T((n
==1 ? 0 : (n
==0 || (n
%100 > 0 && n
%100 < 20)) ? 1 : 2););
69 T((n
==1) ? 0 : n
==2 ? 1 : n
<7 ? 2 : n
<11 ? 3 : 4;);
70 T((n
==1 || n
==11) ? 0 : (n
==2 || n
==12) ? 1 : (n
> 2 && n
< 20) ? 2 : 3;);
71 T((n
%10!=1 || n
%100==11););
73 T((n
==1) ? 0 : (n
==2) ? 1 : (n
== 3) ? 2 : 3;);
74 T((n
%10==1 && n
%100!=11 ? 0 : n
!= 0 ? 1 : 2););
75 T((n
==0 ? 0 : n
==1 ? 1 : 2););
76 T((n
==1 ? 0 : n
==0 || ( n
%100>1 && n
%100<11) ? 1 : (n
%100>10 && n
%100<20 ) ? 2 : 3););
77 T((n
==1) ? 0 : (n
>=2 && n
<=4) ? 1 : 2;);
78 T((n
%100==1 ? 1 : n
%100==2 ? 2 : n
%100==3 || n
%100==4 ? 3 : 0););