|
28 | 28 |
|
29 | 29 | final class StringLiteralTranspilerTest extends TestCase |
30 | 30 | { |
| 31 | + public function stringExamples(): array |
| 32 | + { |
| 33 | + return [ |
| 34 | + '"Hello World!"' => [ |
| 35 | + '"Hello World!"', |
| 36 | + 'Hello World!' |
| 37 | + ], |
| 38 | + "\"Two\nLines\"" => [ |
| 39 | + "\"Two\nLines\"", |
| 40 | + 'Two\' . "\n" . \'Lines' |
| 41 | + ], |
| 42 | + "\"Three\n\nLines\"" => [ |
| 43 | + "\"Three\n\nLines\"", |
| 44 | + 'Three\' . "\n\n" . \'Lines' |
| 45 | + ], |
| 46 | + "\"\n\nLeading Line Breaks\"" => [ |
| 47 | + "\"\n\nLeading Line Breaks\"", |
| 48 | + '"\n\n" . \'Leading Line Breaks' |
| 49 | + ], |
| 50 | + "\"Trailing Line Breaks\n\n\"" => [ |
| 51 | + "\"Trailing Line Breaks\n\n\"", |
| 52 | + 'Trailing Line Breaks\' . "\n\n"' |
| 53 | + ] |
| 54 | + ]; |
| 55 | + } |
| 56 | + |
31 | 57 | /** |
| 58 | + * @dataProvider stringExamples |
32 | 59 | * @test |
| 60 | + * @param string $stringLiteralAsString |
| 61 | + * @param string $expectedTranspilationResult |
33 | 62 | * @return void |
34 | 63 | */ |
35 | | - public function transpilesStringLiteralNodes(): void |
| 64 | + public function transpilesStringLiteralNodes(string $stringLiteralAsString, string $expectedTranspilationResult): void |
36 | 65 | { |
37 | 66 | $stringLiteralTranspiler = new StringLiteralTranspiler(); |
38 | | - $stringLiteralNode = StringLiteralNode::fromString('"Hello World!"'); |
| 67 | + $stringLiteralNode = StringLiteralNode::fromString($stringLiteralAsString); |
| 68 | + |
| 69 | + $actualTranspilationResult = $stringLiteralTranspiler->transpile( |
| 70 | + $stringLiteralNode |
| 71 | + ); |
| 72 | + |
| 73 | + $this->assertEquals( |
| 74 | + $expectedTranspilationResult, |
| 75 | + $actualTranspilationResult |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + public function stringExamplesWithAddedQuotes(): array |
| 80 | + { |
| 81 | + return [ |
| 82 | + '"Hello World!"' => [ |
| 83 | + '"Hello World!"', |
| 84 | + '\'Hello World!\'' |
| 85 | + ], |
| 86 | + "\"Two\nLines\"" => [ |
| 87 | + "\"Two\nLines\"", |
| 88 | + '\'Two\' . "\n" . \'Lines\'' |
| 89 | + ], |
| 90 | + "\"Three\n\nLines\"" => [ |
| 91 | + "\"Three\n\nLines\"", |
| 92 | + '\'Three\' . "\n\n" . \'Lines\'' |
| 93 | + ], |
| 94 | + "\"\n\nLeading Line Breaks\"" => [ |
| 95 | + "\"\n\nLeading Line Breaks\"", |
| 96 | + '"\n\n" . \'Leading Line Breaks\'' |
| 97 | + ], |
| 98 | + "\"Trailing Line Breaks\n\n\"" => [ |
| 99 | + "\"Trailing Line Breaks\n\n\"", |
| 100 | + '\'Trailing Line Breaks\' . "\n\n"' |
| 101 | + ] |
| 102 | + ]; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * @dataProvider stringExamplesWithAddedQuotes |
| 107 | + * @test |
| 108 | + * @param string $stringLiteralAsString |
| 109 | + * @param string $expectedTranspilationResult |
| 110 | + * @return void |
| 111 | + */ |
| 112 | + public function addsQuotesIfNecessary(string $stringLiteralAsString, string $expectedTranspilationResult): void |
| 113 | + { |
| 114 | + $stringLiteralTranspiler = new StringLiteralTranspiler( |
| 115 | + shouldAddQuotes: true |
| 116 | + ); |
| 117 | + $stringLiteralNode = StringLiteralNode::fromString($stringLiteralAsString); |
39 | 118 |
|
40 | | - $expectedTranspilationResult = 'Hello World!'; |
41 | 119 | $actualTranspilationResult = $stringLiteralTranspiler->transpile( |
42 | 120 | $stringLiteralNode |
43 | 121 | ); |
|
0 commit comments