Skip to content

Commit f7f4204

Browse files
jrfnlgrogy
authored andcommitted
TokenizeTest: add additional test cases for text string handling
This adds extra tests for: * Double quoted strings with interpolated variables. * Nowdoc * Heredocs with and without interpolated variables. Note: for the nowdoc and heredoc tests, the test input is put in single quotes to prevent "nested here/nowdoc", which could skew the tests. These test cases also need to have a new line after the `;` as otherwise PHP does not tokenize these correctly (and the highlighter is not concerned with fixing incorrect tokenization of PHP itself).
1 parent aa233c8 commit f7f4204

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

tests/TokenizeTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,81 @@ public function dataTextStrings()
426426
'expected' => <<<'EOL'
427427
<token_default><?php</token_default>
428428
<token_keyword>echo </token_keyword><token_string>"Ahoj světe"</token_string><token_keyword>;</token_keyword>
429+
EOL
430+
),
431+
'Double quoted text string with interpolation [1]' => array(
432+
'original' => <<<'EOL'
433+
<?php
434+
echo "Ahoj $text and more text";
435+
EOL
436+
,
437+
'expected' => <<<'EOL'
438+
<token_default><?php</token_default>
439+
<token_keyword>echo </token_keyword><token_string>"Ahoj </token_string><token_default>$text</token_default><token_string> and more text"</token_string><token_keyword>;</token_keyword>
440+
EOL
441+
),
442+
'Double quoted text string with interpolation [2]' => array(
443+
'original' => <<<'EOL'
444+
<?php
445+
echo "$text and more text";
446+
EOL
447+
,
448+
'expected' => <<<'EOL'
449+
<token_default><?php</token_default>
450+
<token_keyword>echo </token_keyword><token_string>"</token_string><token_default>$text</token_default><token_string> and more text"</token_string><token_keyword>;</token_keyword>
451+
EOL
452+
),
453+
'Double quoted text string with interpolation [3]' => array(
454+
'original' => <<<'EOL'
455+
<?php
456+
echo "Ahoj {$obj->prop} and more text";
457+
EOL
458+
,
459+
'expected' => <<<'EOL'
460+
<token_default><?php</token_default>
461+
<token_keyword>echo </token_keyword><token_string>"Ahoj </token_string><token_keyword>{</token_keyword><token_default>$obj</token_default><token_keyword>-></token_keyword><token_default>prop</token_default><token_keyword>}</token_keyword><token_string> and more text"</token_string><token_keyword>;</token_keyword>
462+
EOL
463+
),
464+
'Nowdoc' => array(
465+
'original' => '<?php
466+
echo <<<\'TXT\'
467+
Text
468+
TXT;
469+
',
470+
'expected' => <<<'EOL'
471+
<token_default><?php</token_default>
472+
<token_keyword>echo <<<'TXT'</token_keyword>
473+
<token_string>Text</token_string>
474+
<token_keyword>TXT;</token_keyword>
475+
476+
EOL
477+
),
478+
'Heredoc' => array(
479+
'original' => '<?php
480+
echo <<<TXT
481+
Text
482+
TXT;
483+
',
484+
'expected' => <<<'EOL'
485+
<token_default><?php</token_default>
486+
<token_keyword>echo <<<TXT</token_keyword>
487+
<token_string>Text</token_string>
488+
<token_keyword>TXT;</token_keyword>
489+
490+
EOL
491+
),
492+
'Heredoc with interpolation' => array(
493+
'original' => '<?php
494+
echo <<<TXT
495+
Text $text
496+
TXT;
497+
',
498+
'expected' => <<<'EOL'
499+
<token_default><?php</token_default>
500+
<token_keyword>echo <<<TXT</token_keyword>
501+
<token_string>Text </token_string><token_default>$text</token_default>
502+
<token_keyword>TXT;</token_keyword>
503+
429504
EOL
430505
),
431506
);

0 commit comments

Comments
 (0)