f9869a830b1231f300143926057db8c442b721e6
[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 function validate($check, $psi) {
11 $file = __DIR__."/001.psi";
12 file_put_contents($file, $psi);
13 if ($check !== psi_validate($file)) {
14 echo "Assertion failed!\n";
15 }
16 }
17
18 validate(false, "typedef void foo;");
19 validate(true, "typedef void *bar;");
20 validate(false, "typedef long int;");
21 validate(true, "typedef long foo;");
22 validate(false, "typedef struct foo bar;");
23 validate(true, "typedef struct {int a;} foo;");
24 validate(false, "struct a; \n typedef struct a a_t;");
25 validate(true, "struct a::(8,8); \n typedef struct a a_t;");
26 validate(true, "typedef struct a a_t; \n struct a::(8,8);");
27
28 validate(true,
29 <<<PSI
30 enum {
31 A,
32 B,
33 C
34 }
35 PSI
36 );
37 validate(false,
38 <<<PSI
39 enum {
40 A,
41 B = A + 2,
42 C = X
43 }
44 PSI
45 );
46
47 validate(true,
48 <<<PSI
49 struct a {
50 int i;
51 }
52 struct b {
53 long l;
54 }
55 typedef struct b b;
56 union v {
57 struct a a;
58 b b;
59 struct {
60 double d;
61 } s;
62 union {
63 long l;
64 double d;
65 } u;
66 }
67 PSI
68 );
69
70 validate(true, "typedef int foo(int bar);");
71 validate(true, "typedef int (foo)(int bar);");
72 validate(true, "typedef int (*foo)(int bar);");
73 validate(true, "typedef int *(*foo)(int bar);");
74 validate(false, "typedef int *(*foo)(int *(*bar)(int baz));");
75 validate(true, "typedef int *(*bar)(int baz); \n typedef int *(*foo)(bar bar);");
76 validate(false, "typedef int bar(int baz); \n typedef int *(*foo)(bar bar);");
77
78 ?>
79 ===DONE===
80 --CLEAN--
81 <?php
82 @unlink(__DIR__."/001.psi");
83 ?>
84 --EXPECTF--
85 ===TEST===
86
87 Warning: PSI syntax error: Unexpected token ';' in %s001.psi on line 1
88
89 Warning: PSI syntax error: Unexpected token 'int' in %s001.psi on line 1
90
91 Warning: Type 'bar' cannot be aliased to struct 'foo' 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 '(' in %s001.psi on line 1
98 ===DONE===