xref: /php-ast/tests/php81_enums.phpt (revision 260678d4)
1--TEST--
2Enums in php 8.1
3--SKIPIF--
4<?php if (PHP_VERSION_ID < 80100) die('skip PHP >= 8.1 only'); ?>
5--FILE--
6<?php
7
8require __DIR__ . '/../util.php';
9
10$code = <<<'PHP'
11<?php
12enum HasValue: int {
13    case FOO = 42;
14    const FOO_ALIAS = self::FOO;
15}
16
17#[MyAttribute(1)]
18enum NoValue {
19    /** Case doc comment */
20    #[OtherAttribute()]
21    case FOO;
22}
23PHP;
24
25$node = ast\parse_code($code, $version=70);
26echo ast_dump($node), "\n";
27$node = ast\parse_code($code, $version=80);
28echo ast_dump($node), "\n";
29$node = ast\parse_code($code, $version=85);
30echo ast_dump($node), "\n";
31--EXPECTF--
32AST_STMT_LIST
33    0: AST_CLASS
34        flags: CLASS_FINAL | CLASS_ENUM (%d)
35        name: "HasValue"
36        docComment: null
37        extends: null
38        implements: null
39        stmts: AST_STMT_LIST
40            0: AST_ENUM_CASE
41                name: "FOO"
42                expr: 42
43                docComment: null
44                attributes: null
45            1: AST_CLASS_CONST_DECL
46                flags: MODIFIER_PUBLIC (%d)
47                0: AST_CONST_ELEM
48                    name: "FOO_ALIAS"
49                    value: AST_CLASS_CONST
50                        class: AST_NAME
51                            flags: NAME_NOT_FQ (%d)
52                            name: "self"
53                        const: "FOO"
54                    docComment: null
55        __declId: 0
56    1: AST_CLASS
57        flags: CLASS_FINAL | CLASS_ENUM (%d)
58        name: "NoValue"
59        docComment: null
60        extends: null
61        implements: null
62        stmts: AST_STMT_LIST
63            0: AST_ENUM_CASE
64                name: "FOO"
65                expr: null
66                docComment: "/** Case doc comment */"
67                attributes: AST_ATTRIBUTE_LIST
68                    0: AST_ATTRIBUTE_GROUP
69                        0: AST_ATTRIBUTE
70                            class: AST_NAME
71                                flags: NAME_NOT_FQ (%d)
72                                name: "OtherAttribute"
73                            args: AST_ARG_LIST
74        __declId: 1
75AST_STMT_LIST
76    0: AST_CLASS
77        flags: CLASS_FINAL | CLASS_ENUM (%d)
78        name: "HasValue"
79        docComment: null
80        extends: null
81        implements: null
82        stmts: AST_STMT_LIST
83            0: AST_ENUM_CASE
84                name: "FOO"
85                expr: 42
86                docComment: null
87                attributes: null
88            1: AST_CLASS_CONST_GROUP
89                flags: MODIFIER_PUBLIC (%d)
90                const: AST_CLASS_CONST_DECL
91                    0: AST_CONST_ELEM
92                        name: "FOO_ALIAS"
93                        value: AST_CLASS_CONST
94                            class: AST_NAME
95                                flags: NAME_NOT_FQ (%d)
96                                name: "self"
97                            const: "FOO"
98                        docComment: null
99                attributes: null
100        attributes: null
101        __declId: 0
102    1: AST_CLASS
103        flags: CLASS_FINAL | CLASS_ENUM (%d)
104        name: "NoValue"
105        docComment: null
106        extends: null
107        implements: null
108        stmts: AST_STMT_LIST
109            0: AST_ENUM_CASE
110                name: "FOO"
111                expr: null
112                docComment: "/** Case doc comment */"
113                attributes: AST_ATTRIBUTE_LIST
114                    0: AST_ATTRIBUTE_GROUP
115                        0: AST_ATTRIBUTE
116                            class: AST_NAME
117                                flags: NAME_NOT_FQ (%d)
118                                name: "OtherAttribute"
119                            args: AST_ARG_LIST
120        attributes: AST_ATTRIBUTE_LIST
121            0: AST_ATTRIBUTE_GROUP
122                0: AST_ATTRIBUTE
123                    class: AST_NAME
124                        flags: NAME_NOT_FQ (%d)
125                        name: "MyAttribute"
126                    args: AST_ARG_LIST
127                        0: 1
128        __declId: 1
129AST_STMT_LIST
130    0: AST_CLASS
131        flags: CLASS_FINAL | CLASS_ENUM (%d)
132        name: "HasValue"
133        docComment: null
134        extends: null
135        implements: null
136        stmts: AST_STMT_LIST
137            0: AST_ENUM_CASE
138                name: "FOO"
139                expr: 42
140                docComment: null
141                attributes: null
142            1: AST_CLASS_CONST_GROUP
143                flags: MODIFIER_PUBLIC (%d)
144                const: AST_CLASS_CONST_DECL
145                    0: AST_CONST_ELEM
146                        name: "FOO_ALIAS"
147                        value: AST_CLASS_CONST
148                            class: AST_NAME
149                                flags: NAME_NOT_FQ (%d)
150                                name: "self"
151                            const: "FOO"
152                        docComment: null
153                attributes: null
154        attributes: null
155        type: AST_TYPE
156            flags: TYPE_LONG (%d)
157        __declId: 0
158    1: AST_CLASS
159        flags: CLASS_FINAL | CLASS_ENUM (%d)
160        name: "NoValue"
161        docComment: null
162        extends: null
163        implements: null
164        stmts: AST_STMT_LIST
165            0: AST_ENUM_CASE
166                name: "FOO"
167                expr: null
168                docComment: "/** Case doc comment */"
169                attributes: AST_ATTRIBUTE_LIST
170                    0: AST_ATTRIBUTE_GROUP
171                        0: AST_ATTRIBUTE
172                            class: AST_NAME
173                                flags: NAME_NOT_FQ (%d)
174                                name: "OtherAttribute"
175                            args: AST_ARG_LIST
176        attributes: AST_ATTRIBUTE_LIST
177            0: AST_ATTRIBUTE_GROUP
178                0: AST_ATTRIBUTE
179                    class: AST_NAME
180                        flags: NAME_NOT_FQ (%d)
181                        name: "MyAttribute"
182                    args: AST_ARG_LIST
183                        0: 1
184        type: null
185        __declId: 1