Skip to content

Commit 913d4c2

Browse files
committed
Add tests for doc-strings (heredoc, nowdoc)
1 parent dc315e0 commit 913d4c2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php namespace lang\ast\unittest\emit;
2+
3+
use test\{Assert, Test, Values};
4+
5+
/** @see https://www.php.net/manual/en/language.types.string.php */
6+
class DocStringsTest extends EmittingTest {
7+
8+
#[Test, Values(['$body', '{$body}', '{$this->body}'])]
9+
public function heredoc_interpolation($variable) {
10+
$html= $this->run('class %T {
11+
private $body= "...";
12+
13+
public function run() {
14+
$body= $this->body;
15+
16+
return <<<HTML
17+
<html>
18+
<body>
19+
'.$variable.'
20+
</body>
21+
</html>
22+
HTML
23+
;
24+
}
25+
}');
26+
27+
Assert::equals("<html>\n<body>\n ...\n</body>\n</html>", $html);
28+
}
29+
30+
#[Test]
31+
public function nowdoc() {
32+
$html= $this->run('class %T {
33+
public function run() {
34+
return <<<\'HTML\'
35+
<html>
36+
<body>
37+
{$body}
38+
</body>
39+
</html>
40+
HTML
41+
;
42+
}
43+
}');
44+
45+
Assert::equals("<html>\n<body>\n {\$body}\n</body>\n</html>", $html);
46+
}
47+
}

0 commit comments

Comments
 (0)