fix ptrdiff_t and _GNU_SOURCE detection
[m6w6/ext-psi] / tests / parser / validate001.phpt
1 --TEST--
2 validate types
3 --SKIPIF--
4 <?php
5 extension_loaded("psi") or die("skip - need ext/psi");
6 ?>
7 --FILE--
8 ===TEST===
9 <?php
10
11 function validate($check, $psi) {
12 $file = __DIR__."/001.psi";
13 file_put_contents($file, $psi);
14 if ($check !== psi_validate($file)) {
15 printf("Assertion failed!\nExpected: %s\n\n%s\n\n",
16 $check ? "true" : "false", $psi);
17 }
18 }
19
20 validate(false, "typedef void foo;");
21 validate(true, "typedef void *bar;");
22 validate(false, "typedef long int;");
23 validate(true, "typedef long foo;");
24 validate(true, "typedef struct foo bar;");
25 validate(true, "typedef struct {int a;} foo;");
26 validate(false, "struct a; \ntypedef struct a a_t;");
27 validate(true, "struct a::(8,8); \ntypedef struct a a_t;");
28 validate(true, "typedef struct a a_t; \nstruct a::(8,8);");
29
30 validate(true,
31 <<<PSI
32 enum {
33 A,
34 B,
35 C
36 }
37 PSI
38 );
39 validate(false,
40 <<<PSI
41 enum {
42 A,
43 B = A + 2,
44 C = X
45 }
46 PSI
47 );
48
49 validate(true,
50 <<<PSI
51 struct a {
52 int i;
53 }
54 struct b {
55 long l;
56 }
57 typedef struct b b;
58 union v {
59 struct a a;
60 b b;
61 struct {
62 double d;
63 } s;
64 union {
65 long l;
66 double d;
67 } u;
68 }
69 PSI
70 );
71
72 validate(true, "typedef int foo(int bar);");
73 validate(true, "typedef int (foo)(int bar);");
74 validate(true, "typedef int (*foo)(int bar);");
75 validate(true, "typedef int *(*foo)(int bar);");
76 validate(false, "typedef int *(*foo)(int *(*bar)(int baz));");
77 validate(true, "typedef int *(*bar)(int baz); \ntypedef int *(*foo)(bar bar);");
78 validate(true, "typedef int bar(int baz); \ntypedef int *(*foo)(bar bar);");
79
80 ?>
81 ===DONE===
82 --CLEAN--
83 <?php
84 @unlink(__DIR__."/001.psi");
85 ?>
86 --EXPECTF--
87 ===TEST===
88
89 Warning: PSI syntax error: Unexpected token ';' at pos 17 in %s001.psi on line 1
90
91 Warning: PSI syntax error: Unexpected token 'int' at pos 14 in %s001.psi on line 1
92
93 Warning: Cannot compute size of empty struct 'a' in %s001.psi on line 1
94
95 Warning: Unknown variable 'X' in numeric expression in %s001.psi on line 4
96
97 Warning: PSI syntax error: Unexpected token '(' at pos 26 in %s001.psi on line 1
98
99 Warning: PSI syntax error: Unexpected token '(' at pos 32 in %s001.psi on line 1
100 ===DONE===