Repository: prettier/plugin-php
Pull request #490 (2018-07-23 20:00:55)

refactor: string
Remove todo and uncomment tests, all tested


Patch:
diff --git a/src/printer.js b/src/printer.js
index 71abb53..fd615bc 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1070,8 +1070,6 @@ function printExpression(path, options, print) {
         return node.value ? "true" : "false";
       case "string": {
         // @TODO: need resolve https://github.com/glayzzle/php-parser/issues/101
-        // @TODO: need resolve https://github.com/glayzzle/php-parser/issues/123
-        // @TODO: need resolve https://github.com/glayzzle/php-parser/issues/124
         // @TODO: for now just reusing double/single quote preference from doc. could eventually
         // use setting from options. need to figure out how this works w/ complex strings and interpolation
         // also need to figure out splitting long strings


Test patch:
diff --git a/tests/string/__snapshots__/jsfmt.spec.js.snap b/tests/string/__snapshots__/jsfmt.spec.js.snap
index 8263803..6230d1b 100644
--- a/tests/string/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/string/__snapshots__/jsfmt.spec.js.snap
@@ -49,13 +49,16 @@ exports[`single.php 1`] = `
 exports[`string.php 1`] = `
 <?php
 $string = 'this is a simple string';
-// $string = 'You can also have embedded\\n newlines in
-// strings this way as it is
-// okay to do';
+$string = 'You can also have embedded\\n newlines in
+strings this way as it is
+okay to do';
+$string = "You can also have embedded\\n newlines in
+strings this way as it is
+okay to do";
 $string = 'Arnold once said: "I\\'ll be back"';
 $string = 'You deleted C:\\\\*.*?';
 $string = 'You deleted C:\\*.*?';
-// $string = 'This will not expand: \\n a newline';
+$string = 'This will not expand: \\n a newline';
 $string = 'Variables do not $expand $either';
 $string = 'qwe{$a}rty';
 $string = 'qwe\${a}rty';
@@ -67,10 +70,10 @@ $string = "foo\\vbar";
 $string = "foo\\ebar";
 $string = "foo\\fbar";
 $string = "foo\\\\bar";
-// $string = "foo\\\\\\bar";
+$string = "foo\\\\\\bar";
 $string = "foo\\\\\\\\bar";
-// $string = "foo\\$bar";
-// $string = "foo\\\\\\$bar";
+$string = "foo\\$bar";
+$string = "foo\\\\\\$bar";
 $string = "foo\\"bar";
 $string = "foo\\"";
 $string = "foo'bar";
@@ -89,19 +92,19 @@ $string = "encapsed variable {$value}.";
 $string = "encapsed offset {$value[0]}.";
 $string = "encapsed {$method->call()}.";
 $string = "combined \${$encapsed}.";
-// $string = "He drank some $juices[koolaid1] juice.";
+$string = "He drank some $juices[koolaid1] juice.";
 $string = "$people->john drank some $juices[0] juice.";
 $string = "This is { $great}";
 $string = "This is {$great}";
-// $string = "This square is {$square->width}00 centimeters broad.";
-// $string = "This works: {$arr['key']}";
-// $string = "This works: {$arr[4][3]}";
+$string = "This square is {$square->width}00 centimeters broad.";
+$string = "This works: {$arr['key']}";
+$string = "This works: {$arr[4][3]}";
 $string = "This works: " . $arr['foo'][3];
-// $string = "This works too: {$obj->values[3]->name}";
+$string = "This works too: {$obj->values[3]->name}";
 $string = "This is the value of the var named $name: {\${$name}}";
 $string = "This is the value of the var named by the return value of getName(): {\${getName()}}";
 $string = "This is the value of the var named by the return value of getName(): {\${getName($arg1, $arg2, $arg3)}}";
-// $string = "This is the value of the var named by the return value of \\$object->getName(): {\${$object->getName()}}";
+$string = "This is the value of the var named by the return value of \\$object->getName(): {\${$object->getName()}}";
 $string = "I'd like an {\${beers::softdrink}}\\n";
 $string = "I'd like an {\${beers::$ale}}\\n";
 $test = "\\\\";
@@ -122,13 +125,16 @@ $string = "\\u{9999}";
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 $string = 'this is a simple string';
-// $string = 'You can also have embedded\\n newlines in
-// strings this way as it is
-// okay to do';
+$string = 'You can also have embedded\\n newlines in
+strings this way as it is
+okay to do';
+$string = "You can also have embedded\\n newlines in
+strings this way as it is
+okay to do";
 $string = 'Arnold once said: "I\\'ll be back"';
 $string = 'You deleted C:\\\\*.*?';
 $string = 'You deleted C:\\*.*?';
-// $string = 'This will not expand: \\n a newline';
+$string = 'This will not expand: \\n a newline';
 $string = 'Variables do not $expand $either';
 $string = 'qwe{$a}rty';
 $string = 'qwe\${a}rty';
@@ -140,10 +146,10 @@ $string = "foo\\vbar";
 $string = "foo\\ebar";
 $string = "foo\\fbar";
 $string = "foo\\\\bar";
-// $string = "foo\\\\\\bar";
+$string = "foo\\\\\\bar";
 $string = "foo\\\\\\\\bar";
-// $string = "foo\\$bar";
-// $string = "foo\\\\\\$bar";
+$string = "foo\\$bar";
+$string = "foo\\\\\\$bar";
 $string = "foo\\"bar";
 $string = "foo\\"";
 $string = "foo'bar";
@@ -162,15 +168,15 @@ $string = "encapsed variable {$value}.";
 $string = "encapsed offset {$value[0]}.";
 $string = "encapsed {$method->call()}.";
 $string = "combined \${$encapsed}.";
-// $string = "He drank some $juices[koolaid1] juice.";
+$string = "He drank some {$juices[koolaid1]} juice.";
 $string = "{$people->john} drank some {$juices[0]} juice.";
 $string = "This is { $great}";
 $string = "This is {$great}";
-// $string = "This square is {$square->width}00 centimeters broad.";
-// $string = "This works: {$arr['key']}";
-// $string = "This works: {$arr[4][3]}";
+$string = "This square is {$square->width}00 centimeters broad.";
+$string = "This works: {$arr['key']}";
+$string = "This works: {$arr[4][3]}";
 $string = "This works: " . $arr['foo'][3];
-// $string = "This works too: {$obj->values[3]->name}";
+$string = "This works too: {$obj->values[3]->name}";
 $string = "This is the value of the var named $name: \${$name}";
 $string = "This is the value of the var named by the return value of getName(): \${getName()}";
 $string = "This is the value of the var named by the return value of getName(): \${getName(
@@ -178,7 +184,7 @@ $string = "This is the value of the var named by the return value of getName():
     $arg2,
     $arg3
 )}";
-// $string = "This is the value of the var named by the return value of \\$object->getName(): {\${$object->getName()}}";
+$string = "This is the value of the var named by the return value of \\$object->getName(): \${$object->getName()}";
 $string = "I'd like an \${beers::softdrink}\\n";
 $string = "I'd like an \${beers::$ale}\\n";
 $test = "\\\\";
diff --git a/tests/string/string.php b/tests/string/string.php
index b52be64..c16d7b1 100644
--- a/tests/string/string.php
+++ b/tests/string/string.php
@@ -1,12 +1,15 @@
 <?php
 $string = 'this is a simple string';
-// $string = 'You can also have embedded\n newlines in
-// strings this way as it is
-// okay to do';
+$string = 'You can also have embedded\n newlines in
+strings this way as it is
+okay to do';
+$string = "You can also have embedded\n newlines in
+strings this way as it is
+okay to do";
 $string = 'Arnold once said: "I\'ll be back"';
 $string = 'You deleted C:\\*.*?';
 $string = 'You deleted C:\*.*?';
-// $string = 'This will not expand: \n a newline';
+$string = 'This will not expand: \n a newline';
 $string = 'Variables do not $expand $either';
 $string = 'qwe{$a}rty';
 $string = 'qwe${a}rty';
@@ -18,10 +21,10 @@ $string = "foo\vbar";
 $string = "foo\ebar";
 $string = "foo\fbar";
 $string = "foo\\bar";
-// $string = "foo\\\bar";
+$string = "foo\\\bar";
 $string = "foo\\\\bar";
-// $string = "foo\$bar";
-// $string = "foo\\\$bar";
+$string = "foo\$bar";
+$string = "foo\\\$bar";
 $string = "foo\"bar";
 $string = "foo\"";
 $string = "foo'bar";
@@ -40,19 +43,19 @@ $string = "encapsed variable {$value}.";
 $string = "encapsed offset {$value[0]}.";
 $string = "encapsed {$method->call()}.";
 $string = "combined ${$encapsed}.";
-// $string = "He drank some $juices[koolaid1] juice.";
+$string = "He drank some $juices[koolaid1] juice.";
 $string = "$people->john drank some $juices[0] juice.";
 $string = "This is { $great}";
 $string = "This is {$great}";
-// $string = "This square is {$square->width}00 centimeters broad.";
-// $string = "This works: {$arr['key']}";
-// $string = "This works: {$arr[4][3]}";
+$string = "This square is {$square->width}00 centimeters broad.";
+$string = "This works: {$arr['key']}";
+$string = "This works: {$arr[4][3]}";
 $string = "This works: " . $arr['foo'][3];
-// $string = "This works too: {$obj->values[3]->name}";
+$string = "This works too: {$obj->values[3]->name}";
 $string = "This is the value of the var named $name: {${$name}}";
 $string = "This is the value of the var named by the return value of getName(): {${getName()}}";
 $string = "This is the value of the var named by the return value of getName(): {${getName($arg1, $arg2, $arg3)}}";
-// $string = "This is the value of the var named by the return value of \$object->getName(): {${$object->getName()}}";
+$string = "This is the value of the var named by the return value of \$object->getName(): {${$object->getName()}}";
 $string = "I'd like an {${beers::softdrink}}\n";
 $string = "I'd like an {${beers::$ale}}\n";
 $test = "\\";