From c8c233f9005ad9e3b1984ca99cb2e157a561cabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Polomsk=C3=BD?= Date: Sun, 16 Mar 2014 21:50:06 +0100 Subject: [PATCH] Correctly pretty print negative floats --- lib/PhpParser/PrettyPrinter/Standard.php | 4 +-- test/code/prettyPrinter/numbers.test | 35 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/code/prettyPrinter/numbers.test diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index 46cebce..45fe741 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -98,7 +98,7 @@ class Standard extends PrettyPrinterAbstract $stringValue = (string) $node->value; // ensure that number is really printed as float - return ctype_digit($stringValue) ? $stringValue . '.0' : $stringValue; + return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue; } // Assignments @@ -735,4 +735,4 @@ class Standard extends PrettyPrinterAbstract return $this->p($node); } } -} \ No newline at end of file +} diff --git a/test/code/prettyPrinter/numbers.test b/test/code/prettyPrinter/numbers.test new file mode 100644 index 0000000..292919b --- /dev/null +++ b/test/code/prettyPrinter/numbers.test @@ -0,0 +1,35 @@ +Number literals +----- +