5774d77adfb88869aae15438d7591a1c6a612012
[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 if ($check !== psi_validate_string($psi)) {
13 printf("Assertion failed!\nExpected: %s\n\n%s\n\n",
14 $check ? "true" : "false", $psi);
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(true, "typedef struct foo bar;");
23 validate(true, "typedef struct {int a;} foo;");
24 validate(false, "struct a; \ntypedef struct a a_t;");
25 validate(true, "struct a::(8,8); \ntypedef struct a a_t;");
26 validate(true, "typedef struct a a_t; \nstruct 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); \ntypedef int *(*foo)(bar bar);");
76 validate(true, "typedef int bar(int baz); \ntypedef int *(*foo)(bar bar);");
77
78 ?>
79 ===DONE===
80 --EXPECTF--
81 ===TEST===
82
83 Warning: PSI syntax error: Unexpected token ';' at pos 17 in %s on line 1
84
85 Warning: PSI syntax error: Unexpected token 'int' at pos 14 in %s on line 1
86
87 Warning: Cannot compute size of empty struct 'a' in %s on line 1
88
89 Warning: Unknown variable 'X' in numeric expression in %s on line 4
90
91 Warning: PSI syntax error: Unexpected token '(' at pos 26 in %s on line 1
92
93 Warning: PSI syntax error: Unexpected token '(' at pos 32 in %s on line 1
94 ===DONE===