flockfile list corruption test
[libc-test.git] / src / musl / pleval.c
blob60d80c8a6eb4e924ad363ff613f4fa02116454d1
1 // testing musl internal __pleval api used in dcngettext
2 #include <string.h>
3 #include "test.h"
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);
10 if (got != want)
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
15 #define T(e) do { \
16 unsigned long n, _w; \
17 for (n=0; n<200; n++) { \
18 _w = e \
19 t(#e, n, _w); \
20 } \
21 } while(0)
23 int main()
25 char buf[210];
27 // recursion depth limit check
28 memset(buf, '!', 200);
29 memcpy(buf+200, "n;", 3);
30 t(buf, 7, -1);
32 memcpy(buf+51, "n;", 3);
33 t(buf, 3, 0);
34 t(buf, 0, 1);
35 memcpy(buf+50, "n;", 3);
36 t(buf, 3, 1);
37 t(buf, 0, 0);
39 // bad expr
40 t("!n n;", 1, -1);
41 t("32n;", 1, -1);
42 t("n/n;", 0, -1);
43 t("n*3-;", 1, -1);
44 t("4*;", 13, -1);
45 t("n?1:;", 13, -1);
47 // good expr
48 T(n % 4;);
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;);
55 T(n%7&&n||0&&n-1;);
57 // the following plural rules are from
58 // http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
59 T(0;);
60 T((n > 1););
61 T((n != 1););
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););
72 T((n != 0););
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););
80 return t_status;