Repository: prettier/plugin-php
Pull request #98 (2018-02-21 12:09:22)

fix: newline before interface body brace

evilebottnawi: @czosel done

Patch:
diff --git a/src/clean.js b/src/clean.js
index cf9bd17..edb95a6 100644
--- a/src/clean.js
+++ b/src/clean.js
@@ -1,5 +1,7 @@
 "use strict";
 
+const util = require("./util");
+
 function clean(ast) {
   // continue ((2)); -> continue 2;
   // continue 1; -> continue;
@@ -14,6 +16,11 @@ function clean(ast) {
         : { kind: ast.kind, level };
     }
   }
+  if (ast.kind === "number") {
+    ast.value = util.printNumber(ast.value);
+
+    return ast;
+  }
 }
 
 module.exports = clean;
diff --git a/src/printer.js b/src/printer.js
index 1af428f..2e78c94 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1,7 +1,9 @@
 "use strict";
 
 const docBuilders = require("prettier").doc.builders;
-const util = require("prettier").util;
+const sharedUtil = require("prettier").util;
+
+const util = require("./util");
 
 const concat = docBuilders.concat;
 const join = docBuilders.join;
@@ -56,7 +58,9 @@ function lineShouldEndWithSemicolon(path) {
     "static",
     "include",
     "goto",
-    "throw"
+    "throw",
+    "new",
+    "eval"
   ];
   if (node.kind === "traituse") {
     return !node.adaptations;
@@ -87,7 +91,7 @@ function printLines(path, options, print) {
       parts.push(";");
     }
     if (
-      util.isNextLineEmpty(text, stmt, options) &&
+      sharedUtil.isNextLineEmpty(text, stmt, options) &&
       !isLastStatement(stmtPath)
     ) {
       parts.push(hardline);
@@ -225,7 +229,7 @@ function printExpression(path, options, print) {
         return quote + node.value + quote;
       }
       case "number":
-        return node.value;
+        return util.printNumber(node.value);
       case "encapsed":
         if (node.type === "offset") {
           return group(concat(path.map(print, "value")));
@@ -371,7 +375,7 @@ function printStatement(path, options, print) {
           path.call(childrenPath => {
             return printLines(childrenPath, options, print);
           }, "children"),
-          hardline
+          node.children.length ? hardline : ""
         ]);
       }
       case "namespace": {
@@ -590,10 +594,11 @@ function printStatement(path, options, print) {
                       join(", ", path.map(print, "extends"))
                     ])
                   )
-                : "",
-              " {"
+                : ""
             ])
           ),
+          hardline,
+          "{",
           indent(
             concat(
               path.map(element => {
@@ -657,18 +662,32 @@ function printStatement(path, options, print) {
           return "}";
         }
         if (alternate.kind === "if") {
-          return concat(["} else", path.call(print, "alternate")]);
+          return concat([
+            node.shortForm ? "" : "} ",
+            "else",
+            path.call(print, "alternate")
+          ]);
         }
         return concat([
-          "} else {",
+          concat([
+            node.shortForm ? "" : "} ",
+            "else",
+            node.shortForm ? ":" : " {"
+          ]),
           indent(concat([line, path.call(print, "alternate")])),
           line,
-          "}"
+          node.shortForm ? "endif;" : "}"
         ]);
       };
       return concat([
         group(
-          concat(["if (", softline, path.call(print, "test"), softline, ") {"])
+          concat([
+            "if (",
+            softline,
+            path.call(print, "test"),
+            softline,
+            concat([")", node.shortForm ? ":" : " {"])
+          ])
         ),
         indent(concat([line, path.call(print, "body")])),
         line,
@@ -701,12 +720,12 @@ function printStatement(path, options, print) {
             softline,
             path.call(print, "test"),
             softline,
-            ") {"
+            concat([")", node.shortForm ? ":" : " {"])
           ])
         ),
         indent(concat([line, path.call(print, "body")])),
         line,
-        "}"
+        node.shortForm ? "endwhile;" : "}"
       ]);
     case "for": {
       const parts = [
@@ -734,13 +753,17 @@ function printStatement(path, options, print) {
               ])
             ),
             softline,
-            node.body ? ") {" : ");"
+            node.body ? concat([")", node.shortForm ? ":" : " {"]) : ");"
           ])
         )
       ];
       if (node.body) {
         parts.push(
-          concat([indent(concat([line, path.call(print, "body")])), line, "}"])
+          concat([
+            indent(concat([line, path.call(print, "body")])),
+            line,
+            node.shortForm ? "endfor;" : "}"
+          ])
         );
       }
       return concat(parts);
@@ -765,12 +788,12 @@ function printStatement(path, options, print) {
               ])
             ),
             softline,
-            ") {"
+            concat([")", node.shortForm ? ":" : " {"])
           ])
         ),
         indent(concat([line, path.call(print, "body")])),
         line,
-        "}"
+        node.shortForm ? "endforeach;" : "}"
       ]);
     case "switch":
       return concat([
@@ -780,7 +803,7 @@ function printStatement(path, options, print) {
             softline,
             path.call(print, "test"),
             softline,
-            ") {"
+            concat([")", node.shortForm ? ":" : " {"])
           ])
         ),
         indent(
@@ -793,7 +816,7 @@ function printStatement(path, options, print) {
           )
         ),
         line,
-        "}"
+        node.shortForm ? "endswitch;" : "}"
       ]);
     case "call":
       return group(
@@ -885,6 +908,8 @@ function printStatement(path, options, print) {
         ])
       );
     case "exit":
+      // Todo use `node.useDie` for determining `exit` or `die`
+      // after https://github.com/glayzzle/php-parser/commit/b22ea4863be9125c381951dc008820b68fc3d135 shipped
       return concat(["exit(", path.call(print, "status"), ")"]);
     case "clone":
       return concat(["clone ", path.call(print, "what")]);
@@ -1037,8 +1062,8 @@ function printStatement(path, options, print) {
       return concat(["@", path.call(print, "expr")]);
     case "halt":
       return concat(["__halt_compiler();", node.after]);
-    //@TODO: leaving eval until we figure out encapsed https://github.com/prettier/prettier-php/pull/2
     case "eval":
+      return concat(["eval(", path.call(print, "source"), ")"]);
     default:
       return "Have not implemented statement kind " + node.kind + " yet.";
   }
@@ -1066,7 +1091,7 @@ function printNode(path, options, print) {
         node.test
           ? concat(["case ", path.call(print, "test"), ":"])
           : "default:",
-        indent(concat([line, path.call(print, "body")]))
+        node.body ? indent(concat([line, path.call(print, "body")])) : ""
       ]);
     case "break":
       if (node.level) {
diff --git a/src/util.js b/src/util.js
new file mode 100644
index 0000000..77384e7
--- /dev/null
+++ b/src/util.js
@@ -0,0 +1,22 @@
+"use strict";
+
+function printNumber(rawNumber) {
+  return (
+    rawNumber
+      .toLowerCase()
+      // Remove unnecessary plus and zeroes from scientific notation.
+      .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
+      // Remove unnecessary scientific notation (1e0).
+      .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1")
+      // Make sure numbers always start with a digit.
+      .replace(/^([+-])?\./, "$10.")
+      // Remove extraneous trailing decimal zeroes.
+      .replace(/(\.\d+?)0+(?=e|$)/, "$1")
+      // Remove trailing dot.
+      .replace(/\.(?=e|$)/, "")
+  );
+}
+
+module.exports = {
+  printNumber
+};


Test patch:
diff --git a/tests/class/__snapshots__/jsfmt.spec.js.snap b/tests/class/__snapshots__/jsfmt.spec.js.snap
index 80a319c..b75555b 100644
--- a/tests/class/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/class/__snapshots__/jsfmt.spec.js.snap
@@ -90,6 +90,14 @@ abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResou
   public function method(iterable $iterable): array {
     // Parameter broadened and return type narrowed.
   }
+
+  public function method1() { return 'hi'; }
+
+  public function method2() {
+      return 'hi'; }
+
+  public function method3()
+    { return 'hi'; }
 }
 
 $this->something->method($argument, $this->more->stuff($this->even->more->things->complicatedMethod()));
@@ -201,6 +209,21 @@ abstract class ReallyReallyReallyLongClassName
   {
     // Parameter broadened and return type narrowed.
   }
+
+  public function method1()
+  {
+    return 'hi';
+  }
+
+  public function method2()
+  {
+    return 'hi';
+  }
+
+  public function method3()
+  {
+    return 'hi';
+  }
 }
 
 $this->something->method(
diff --git a/tests/class/class.php b/tests/class/class.php
index 57a43e1..b2df2a7 100644
--- a/tests/class/class.php
+++ b/tests/class/class.php
@@ -87,6 +87,14 @@ abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResou
   public function method(iterable $iterable): array {
     // Parameter broadened and return type narrowed.
   }
+
+  public function method1() { return 'hi'; }
+
+  public function method2() {
+      return 'hi'; }
+
+  public function method3()
+    { return 'hi'; }
 }
 
 $this->something->method($argument, $this->more->stuff($this->even->more->things->complicatedMethod()));
diff --git a/tests/eval/__snapshots__/jsfmt.spec.js.snap b/tests/eval/__snapshots__/jsfmt.spec.js.snap
new file mode 100644
index 0000000..85a1d19
--- /dev/null
+++ b/tests/eval/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,12 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`eval.php 1`] = `
+<?php
+eval('return 1;');
+eval("return $a;");
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+eval('return 1;');
+eval("return $a;");
+
+`;
diff --git a/tests/eval/eval.php b/tests/eval/eval.php
new file mode 100644
index 0000000..d614e2e
--- /dev/null
+++ b/tests/eval/eval.php
@@ -0,0 +1,3 @@
+<?php
+eval('return 1;');
+eval("return $a;");
diff --git a/tests/eval/jsfmt.spec.js b/tests/eval/jsfmt.spec.js
new file mode 100644
index 0000000..e395434
--- /dev/null
+++ b/tests/eval/jsfmt.spec.js
@@ -0,0 +1,1 @@
+run_spec(__dirname, ["php"]);
diff --git a/tests/exit/__snapshots__/jsfmt.spec.js.snap b/tests/exit/__snapshots__/jsfmt.spec.js.snap
index 1125877..ae556e5 100644
--- a/tests/exit/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/exit/__snapshots__/jsfmt.spec.js.snap
@@ -4,12 +4,16 @@ exports[`exit.php 1`] = `
 <?php
 exit("exit info");
 exit(1);
+die("die info");
+die(1);
 __halt_compiler();
 echo "this is not parsed anymore!";
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 exit("exit info");
 exit(1);
+exit("die info");
+exit(1);
 __halt_compiler();
 echo "this is not parsed anymore!";
 
diff --git a/tests/exit/exit.php b/tests/exit/exit.php
index 8a7eb2e..b9c170c 100644
--- a/tests/exit/exit.php
+++ b/tests/exit/exit.php
@@ -1,5 +1,7 @@
 <?php
 exit("exit info");
 exit(1);
+die("die info");
+die(1);
 __halt_compiler();
 echo "this is not parsed anymore!";
diff --git a/tests/for/__snapshots__/jsfmt.spec.js.snap b/tests/for/__snapshots__/jsfmt.spec.js.snap
index 6c5b1ec..009f9a0 100644
--- a/tests/for/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/for/__snapshots__/jsfmt.spec.js.snap
@@ -13,6 +13,10 @@ for ($really_really_long_variable_name = 0; $really_really_long_variable_name <=
 for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
 
 for ($really_really_long_variable_name = 0, $and_something_else = 0; $really_really_long_variable_name <= 5; $really_really_long_variable_name++, print $really_really_long_variable_name, $even_more_stuff++);
+
+for (;;):
+  $test = $i;
+endfor;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 for ($i = 0; $i <= 5; $i++) {
@@ -37,4 +41,8 @@ for (
   $even_more_stuff++
 );
 
+for (; ; ):
+  $test = $i;
+endfor;
+
 `;
diff --git a/tests/for/for.php b/tests/for/for.php
index 0eb7efa..bcace7d 100644
--- a/tests/for/for.php
+++ b/tests/for/for.php
@@ -10,3 +10,7 @@ for ($really_really_long_variable_name = 0; $really_really_long_variable_name <=
 for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
 
 for ($really_really_long_variable_name = 0, $and_something_else = 0; $really_really_long_variable_name <= 5; $really_really_long_variable_name++, print $really_really_long_variable_name, $even_more_stuff++);
+
+for (;;):
+  $test = $i;
+endfor;
diff --git a/tests/foreach/__snapshots__/jsfmt.spec.js.snap b/tests/foreach/__snapshots__/jsfmt.spec.js.snap
index e5b7384..e535d40 100644
--- a/tests/foreach/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/foreach/__snapshots__/jsfmt.spec.js.snap
@@ -9,6 +9,10 @@ foreach ($test as $i) {
 foreach ($really_really_really_really_really_long_array as $key => $really_really_really_long_value) {
   $test3 = $really_really_really_long_value;
 }
+
+foreach ($test as $i):
+  $test2 = $i;
+endforeach;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 foreach ($test as $i) {
@@ -22,4 +26,8 @@ foreach (
   $test3 = $really_really_really_long_value;
 }
 
+foreach ($test as $i):
+  $test2 = $i;
+endforeach;
+
 `;
diff --git a/tests/foreach/foreach.php b/tests/foreach/foreach.php
index 3433518..37a0f94 100644
--- a/tests/foreach/foreach.php
+++ b/tests/foreach/foreach.php
@@ -6,3 +6,7 @@ foreach ($test as $i) {
 foreach ($really_really_really_really_really_long_array as $key => $really_really_really_long_value) {
   $test3 = $really_really_really_long_value;
 }
+
+foreach ($test as $i):
+  $test2 = $i;
+endforeach;
diff --git a/tests/if/__snapshots__/jsfmt.spec.js.snap b/tests/if/__snapshots__/jsfmt.spec.js.snap
index dc74cca..7aff019 100644
--- a/tests/if/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/if/__snapshots__/jsfmt.spec.js.snap
@@ -10,6 +10,14 @@ if (true) {
   return;
 }
 
+if (true):
+  return 1;
+elseif (false):
+  return 2;
+else:
+  return;
+endif;
+
 return true ? 1 : 2;
 return ($testReallyReallyLong >= 1) ? $someOtherReallyReallyLongVariable : $thisOtherVariable;
 return true ?: 2;
@@ -28,6 +36,14 @@ if (true) {
   return;
 }
 
+if (true):
+  return 1;
+elseif (false):
+  return 2;
+else:
+  return;
+endif;
+
 return true ? 1 : 2;
 return ($testReallyReallyLong >= 1)
   ? $someOtherReallyReallyLongVariable
diff --git a/tests/if/if.php b/tests/if/if.php
index 6605691..28c8b4c 100644
--- a/tests/if/if.php
+++ b/tests/if/if.php
@@ -7,6 +7,14 @@ if (true) {
   return;
 }
 
+if (true):
+  return 1;
+elseif (false):
+  return 2;
+else:
+  return;
+endif;
+
 return true ? 1 : 2;
 return ($testReallyReallyLong >= 1) ? $someOtherReallyReallyLongVariable : $thisOtherVariable;
 return true ?: 2;
diff --git a/tests/interface/__snapshots__/jsfmt.spec.js.snap b/tests/interface/__snapshots__/jsfmt.spec.js.snap
index 79ca8dd..4159d3e 100644
--- a/tests/interface/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/interface/__snapshots__/jsfmt.spec.js.snap
@@ -13,12 +13,14 @@ interface test2 extends testInterface {
 }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
-interface testInterface {
+interface testInterface
+{
   public function setVariable($test);
   public function method(array $array): iterable;
 }
 
-interface test2 extends testInterface {
+interface test2 extends testInterface
+{
   public function other($hi);
 }
 
diff --git a/tests/new/__snapshots__/jsfmt.spec.js.snap b/tests/new/__snapshots__/jsfmt.spec.js.snap
new file mode 100644
index 0000000..245fdaf
--- /dev/null
+++ b/tests/new/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,18 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`new.php 1`] = `
+<?php
+new Foo();
+new Foo;
+$a = new Foo;
+$b = new Foo();
+$c = new Foo([1, 2, 3], "foo", $variable);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+new Foo();
+new Foo();
+$a = new Foo();
+$b = new Foo();
+$c = new Foo([1, 2, 3], "foo", $variable);
+
+`;
diff --git a/tests/new/jsfmt.spec.js b/tests/new/jsfmt.spec.js
new file mode 100644
index 0000000..e395434
--- /dev/null
+++ b/tests/new/jsfmt.spec.js
@@ -0,0 +1,1 @@
+run_spec(__dirname, ["php"]);
diff --git a/tests/new/new.php b/tests/new/new.php
new file mode 100644
index 0000000..ef5e400
--- /dev/null
+++ b/tests/new/new.php
@@ -0,0 +1,6 @@
+<?php
+new Foo();
+new Foo;
+$a = new Foo;
+$b = new Foo();
+$c = new Foo([1, 2, 3], "foo", $variable);
diff --git a/tests/number/__snapshots__/jsfmt.spec.js.snap b/tests/number/__snapshots__/jsfmt.spec.js.snap
new file mode 100644
index 0000000..c403729
--- /dev/null
+++ b/tests/number/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,170 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`number.php 1`] = `
+<?php
+$a = 0;
+$a = 1;
+$a = + 1;
+$a = - 1;
+
+$a = 0.1;
+$a = 1.1;
+
+$a = .1;
+$a = 1.;
+
+$a = 000123;
+$a = 012300;
+
+$a = 0x1;
+$a = 0X1;
+$a = 0x001;
+$a = 0X100;
+
+$a = 0x123abcdef456ABCDEF;
+$a = 0X123abcdef456ABCDEF;
+$a = 0xdeadbeef;
+
+$a = 0b111000;
+$a = 0b000111;
+$a = 0B111000;
+$a = 0B000111;
+
+$a = 1e1;
+$a = 1e+1;
+$a = 1e-1;
+$a = 1.e1;
+$a = .1e1;
+$a = 1.1e1;
+$a = 1.1e0010;
+$a = .1e+0010;
+$a = .1e-0010;
+
+$a = 1E1;
+$a = 1E+1;
+$a = 1E-1;
+$a = 1.E1;
+$a = .1E1;
+$a = 1.1E1;
+$a = 1.1E0010;
+$a = .1E+0010;
+$a = .1E-0010;
+
+$a = 0.5e0;
+$a = 0.5e00;
+$a = 0.5e+0;
+$a = 0.5e+00;
+$a = 0.5e-0;
+$a = 0.5e-00;
+
+$a = 1;
+$a = 1.00500;
+$a = 1.0;
+$a = 1.5;
+$a = 1.50;
+$a = 0;
+$a = 0.00500;
+$a = 0.0;
+$a = 0.0000;
+$a = .0;
+$a = 500600.001230045000;
+$a = 1.00500e60;
+$a = 1.0e60;
+$a = 0.00500e60;
+$a = 0.0e60;
+$a = 0.0000e60;
+$a = .0e60;
+$a = 0.e60;
+$a = 0e60;
+$a = 500600.001230045000e60;
+$a = 10;
+$a = 9700;
+$a = 10e100;
+
+$a = (-100);
+$a = -(100);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+$a = 0;
+$a = 1;
+$a = +1;
+$a = -1;
+
+$a = 0.1;
+$a = 1.1;
+
+$a = 0.1;
+$a = 1;
+
+$a = 000123;
+$a = 012300;
+
+$a = 0x1;
+$a = 0x1;
+$a = 0x001;
+$a = 0x100;
+
+$a = 0x123abcdef456abcdef;
+$a = 0x123abcdef456abcdef;
+$a = 0xdeadbeef;
+
+$a = 0b111000;
+$a = 0b000111;
+$a = 0b111000;
+$a = 0b000111;
+
+$a = 1e1;
+$a = 1e1;
+$a = 1e-1;
+$a = 1e1;
+$a = 0.1e1;
+$a = 1.1e1;
+$a = 1.1e10;
+$a = 0.1e10;
+$a = 0.1e-10;
+
+$a = 1e1;
+$a = 1e1;
+$a = 1e-1;
+$a = 1e1;
+$a = 0.1e1;
+$a = 1.1e1;
+$a = 1.1e10;
+$a = 0.1e10;
+$a = 0.1e-10;
+
+$a = 0.5;
+$a = 0.5;
+$a = 0.5;
+$a = 0.5;
+$a = 0.5;
+$a = 0.5;
+
+$a = 1;
+$a = 1.005;
+$a = 1.0;
+$a = 1.5;
+$a = 1.5;
+$a = 0;
+$a = 0.005;
+$a = 0.0;
+$a = 0.0;
+$a = 0.0;
+$a = 500600.001230045;
+$a = 1.005e60;
+$a = 1.0e60;
+$a = 0.005e60;
+$a = 0.0e60;
+$a = 0.0e60;
+$a = 0.0e60;
+$a = 0e60;
+$a = 0e60;
+$a = 500600.001230045e60;
+$a = 10;
+$a = 9700;
+$a = 10e100;
+
+$a = (-100);
+$a = -(100);
+
+`;
diff --git a/tests/number/jsfmt.spec.js b/tests/number/jsfmt.spec.js
new file mode 100644
index 0000000..e395434
--- /dev/null
+++ b/tests/number/jsfmt.spec.js
@@ -0,0 +1,1 @@
+run_spec(__dirname, ["php"]);
diff --git a/tests/number/number.php b/tests/number/number.php
new file mode 100644
index 0000000..a157d7c
--- /dev/null
+++ b/tests/number/number.php
@@ -0,0 +1,82 @@
+<?php
+$a = 0;
+$a = 1;
+$a = + 1;
+$a = - 1;
+
+$a = 0.1;
+$a = 1.1;
+
+$a = .1;
+$a = 1.;
+
+$a = 000123;
+$a = 012300;
+
+$a = 0x1;
+$a = 0X1;
+$a = 0x001;
+$a = 0X100;
+
+$a = 0x123abcdef456ABCDEF;
+$a = 0X123abcdef456ABCDEF;
+$a = 0xdeadbeef;
+
+$a = 0b111000;
+$a = 0b000111;
+$a = 0B111000;
+$a = 0B000111;
+
+$a = 1e1;
+$a = 1e+1;
+$a = 1e-1;
+$a = 1.e1;
+$a = .1e1;
+$a = 1.1e1;
+$a = 1.1e0010;
+$a = .1e+0010;
+$a = .1e-0010;
+
+$a = 1E1;
+$a = 1E+1;
+$a = 1E-1;
+$a = 1.E1;
+$a = .1E1;
+$a = 1.1E1;
+$a = 1.1E0010;
+$a = .1E+0010;
+$a = .1E-0010;
+
+$a = 0.5e0;
+$a = 0.5e00;
+$a = 0.5e+0;
+$a = 0.5e+00;
+$a = 0.5e-0;
+$a = 0.5e-00;
+
+$a = 1;
+$a = 1.00500;
+$a = 1.0;
+$a = 1.5;
+$a = 1.50;
+$a = 0;
+$a = 0.00500;
+$a = 0.0;
+$a = 0.0000;
+$a = .0;
+$a = 500600.001230045000;
+$a = 1.00500e60;
+$a = 1.0e60;
+$a = 0.00500e60;
+$a = 0.0e60;
+$a = 0.0000e60;
+$a = .0e60;
+$a = 0.e60;
+$a = 0e60;
+$a = 500600.001230045000e60;
+$a = 10;
+$a = 9700;
+$a = 10e100;
+
+$a = (-100);
+$a = -(100);
diff --git a/tests/program/__snapshots__/jsfmt.spec.js.snap b/tests/program/__snapshots__/jsfmt.spec.js.snap
new file mode 100644
index 0000000..4e20954
--- /dev/null
+++ b/tests/program/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,8 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`single-open-php-tag.php 1`] = `
+<?php
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+`;
diff --git a/tests/program/jsfmt.spec.js b/tests/program/jsfmt.spec.js
new file mode 100644
index 0000000..e395434
--- /dev/null
+++ b/tests/program/jsfmt.spec.js
@@ -0,0 +1,1 @@
+run_spec(__dirname, ["php"]);
diff --git a/tests/program/single-open-php-tag.php b/tests/program/single-open-php-tag.php
new file mode 100644
index 0000000..b3d9bbc
--- /dev/null
+++ b/tests/program/single-open-php-tag.php
@@ -0,0 +1,1 @@
+<?php
diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap
index 9c65cde..62a6754 100644
--- a/tests/switch/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap
@@ -9,9 +9,23 @@ switch (2) {
   case 2:
     $test = 'second';
     break;
+  case 10:
+  case 20:
+    $test = 'big';
+    break;
+  case 100:
   default:
     $test = 1;
 }
+
+switch ($var):
+  case 1:
+  case 2:
+    echo "Goodbye!";
+    break;
+  default:
+    echo "I only understand 1 and 2.";
+endswitch;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 switch (2) {
@@ -21,8 +35,22 @@ switch (2) {
   case 2:
     $test = 'second';
     break;
+  case 10:
+  case 20:
+    $test = 'big';
+    break;
+  case 100:
   default:
     $test = 1;
 }
 
+switch ($var):
+  case 1:
+  case 2:
+    echo "Goodbye!";
+    break;
+  default:
+    echo "I only understand 1 and 2.";
+endswitch;
+
 `;
diff --git a/tests/switch/switch.php b/tests/switch/switch.php
index 6066b99..c59b5a2 100644
--- a/tests/switch/switch.php
+++ b/tests/switch/switch.php
@@ -6,6 +6,20 @@ switch (2) {
   case 2:
     $test = 'second';
     break;
+  case 10:
+  case 20:
+    $test = 'big';
+    break;
+  case 100:
   default:
     $test = 1;
 }
+
+switch ($var):
+  case 1:
+  case 2:
+    echo "Goodbye!";
+    break;
+  default:
+    echo "I only understand 1 and 2.";
+endswitch;
diff --git a/tests/while/__snapshots__/jsfmt.spec.js.snap b/tests/while/__snapshots__/jsfmt.spec.js.snap
index 44fc185..14f7303 100644
--- a/tests/while/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/while/__snapshots__/jsfmt.spec.js.snap
@@ -6,6 +6,10 @@ $i = 1;
 while ($i <= 5) {
   $i++;
 }
+
+while ($i <= 5):
+  $i++;
+endwhile;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 $i = 1;
@@ -13,4 +17,8 @@ while ($i <= 5) {
   $i++;
 }
 
+while ($i <= 5):
+  $i++;
+endwhile;
+
 `;
diff --git a/tests/while/while.php b/tests/while/while.php
index 3fcb675..194e8f2 100644
--- a/tests/while/while.php
+++ b/tests/while/while.php
@@ -3,3 +3,7 @@ $i = 1;
 while ($i <= 5) {
   $i++;
 }
+
+while ($i <= 5):
+  $i++;
+endwhile;