Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92980831
PhutilPHPFragmentLexerTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 25, 08:14
Size
9 KB
Mime Type
text/x-php
Expires
Wed, Nov 27, 08:14 (2 d)
Engine
blob
Format
Raw Data
Handle
22530570
Attached To
rPHU libphutil
PhutilPHPFragmentLexerTestCase.php
View Options
<?php
final
class
PhutilPHPFragmentLexerTestCase
extends
PhutilTestCase
{
public
function
testFragmentLexer
()
{
$dir
=
dirname
(
__FILE__
).
'/php'
;
foreach
(
Filesystem
::
listDirectory
(
$dir
,
$hidden
=
false
)
as
$file
)
{
$data
=
Filesystem
::
readFile
(
$dir
.
'/'
.
$file
);
$this
->
runLexer
(
$file
,
$data
);
}
}
private
function
runLexer
(
$file
,
$data
)
{
$lexer
=
new
PhutilPHPFragmentLexer
();
switch
(
$file
)
{
case
'pop-from-php.txt'
:
$initial_state
=
'php'
;
break
;
default
:
$initial_state
=
'start'
;
break
;
}
$caught
=
null
;
$tokens
=
null
;
try
{
$tokens
=
$lexer
->
getTokens
(
$data
,
$initial_state
);
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
switch
(
$file
)
{
case
'basics.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nf'
,
'f'
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'catch.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'k'
,
'try'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'catch'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'nc'
,
'Z'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nv'
,
'$ex'
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
"
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'comments.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$tokens
=
$lexer
->
mergeTokens
(
$tokens
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'cm'
,
'/**/'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'sd'
,
'/** doc */'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'cm'
,
'/* m */'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'c'
,
'//* m */'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'c'
,
'// a'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'c'
,
'// b'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'c'
,
'// c '
,
null
),
array
(
'cp'
,
'?>'
,
null
),
array
(
null
,
"
\n\n
d
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'extendsimplements.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'k'
,
'class'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'no'
,
'C'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'extends'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'A'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'implements'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'I'
,
null
),
array
(
'o'
,
','
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'J'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
"
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'haltcompiler.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'cp'
,
'__halt_compiler'
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n\n
derp derp derp
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'heredocs.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
's'
,
"<<<H
\n
a
\n
H;
\n
"
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
's'
,
"<<<H
\n
b
\n
H;
\n
"
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
's'
,
"<<<'H'
\n
c
\n
H;
\n
"
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
's'
,
"<<<
\"
H
\"\n
d
\n
H;
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'symbols.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'k'
,
'public'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'function'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'no'
,
'f'
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'nf'
,
'g'
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'nc'
,
'H'
,
null
),
array
(
'o'
,
'::'
,
null
),
array
(
'nf'
,
'i'
,
'H'
),
array
(
'o'
,
'('
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'nc'
,
'J'
,
null
),
array
(
'o'
,
'::'
,
null
),
array
(
'na'
,
'C'
,
'J'
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'k'
,
'new'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'K'
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
"
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'case-insensitive.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'<?php'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'k'
,
'CLASS'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'no'
,
'C'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'EXTENDS'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'stdClass'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'IMPLEMENTS'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'I'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'k'
,
'FUNCTION'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'no'
,
'f'
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'nv'
,
'$c'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'='
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'NEW'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'C'
,
null
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'k'
,
'TRY'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'k'
,
'IF'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'nv'
,
'$c'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'instanceOf'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nc'
,
'C'
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'no'
,
'ECHO'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'kc'
,
'__line__'
,
null
),
array
(
'o'
,
';'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'k'
,
'CATCH'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'('
,
null
),
array
(
'nc'
,
'Exception'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'nv'
,
'$ex'
,
null
),
array
(
'o'
,
')'
,
null
),
array
(
null
,
' '
,
null
),
array
(
'o'
,
'{'
,
null
),
array
(
null
,
"
\n
"
,
null
),
array
(
'o'
,
'}'
,
null
),
array
(
null
,
"
\n\n
"
,
null
),
array
(
'no'
,
'echo'
,
null
),
array
(
null
,
' '
,
null
),
array
(
's'
,
"<<<EOT
\n
eot;
\n
EOT;
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
case
'pop-from-php.txt'
:
$this
->
assertEqual
(
null
,
$caught
);
$this
->
assertEqual
(
array
(
array
(
'cp'
,
'?>'
,
null
),
array
(
null
,
"
\n
"
,
null
),
),
$tokens
,
$file
);
break
;
default
:
throw
new
Exception
(
"No assertion block for test '{$file}'!"
);
}
}
}
Event Timeline
Log In to Comment