Skip to content

Commit 44aa58c

Browse files
Test tokenization
1 parent 7d19423 commit 44aa58c

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
Verify that tokenization of file contents includes attributes on constants
3+
--EXTENSIONS--
4+
tokenizer
5+
--FILE--
6+
<?php
7+
8+
#[MyAttribute("foo", 123, bar: "baz", qux: true)]
9+
const EXAMPLE = 'Value';
10+
11+
$tokens = PhpToken::tokenize( file_get_contents( __FILE__ ) );
12+
$relevant = array_slice( $tokens, 0, 32 );
13+
14+
foreach ($relevant as $token) {
15+
echo "Line {$token->line}: {$token->getTokenName()} ('{$token->text}')\n";
16+
}
17+
18+
?>
19+
--EXPECT--
20+
Line 1: T_OPEN_TAG ('<?php
21+
')
22+
Line 2: T_WHITESPACE ('
23+
')
24+
Line 3: T_ATTRIBUTE ('#[')
25+
Line 3: T_STRING ('MyAttribute')
26+
Line 3: ( ('(')
27+
Line 3: T_CONSTANT_ENCAPSED_STRING ('"foo"')
28+
Line 3: , (',')
29+
Line 3: T_WHITESPACE (' ')
30+
Line 3: T_LNUMBER ('123')
31+
Line 3: , (',')
32+
Line 3: T_WHITESPACE (' ')
33+
Line 3: T_STRING ('bar')
34+
Line 3: : (':')
35+
Line 3: T_WHITESPACE (' ')
36+
Line 3: T_CONSTANT_ENCAPSED_STRING ('"baz"')
37+
Line 3: , (',')
38+
Line 3: T_WHITESPACE (' ')
39+
Line 3: T_STRING ('qux')
40+
Line 3: : (':')
41+
Line 3: T_WHITESPACE (' ')
42+
Line 3: T_STRING ('true')
43+
Line 3: ) (')')
44+
Line 3: ] (']')
45+
Line 3: T_WHITESPACE ('
46+
')
47+
Line 4: T_CONST ('const')
48+
Line 4: T_WHITESPACE (' ')
49+
Line 4: T_STRING ('EXAMPLE')
50+
Line 4: T_WHITESPACE (' ')
51+
Line 4: = ('=')
52+
Line 4: T_WHITESPACE (' ')
53+
Line 4: T_CONSTANT_ENCAPSED_STRING (''Value'')
54+
Line 4: ; (';')

0 commit comments

Comments
 (0)