Permalink
Browse files

Updated exception comments to be more useful, added them to test suite.

  • Loading branch information...
1 parent 2d662ec commit ade958e841485df6748b51c262326ceea6dd0555 @tedivm committed Jan 27, 2014
Showing with 8 additions and 4 deletions.
  1. +6 −4 src/JShrink/Minifier.php
  2. +2 −0 tests/JShrink/Test/JShrinkTest.php
@@ -108,7 +108,7 @@ public static function minify($js, $options = array())
// Sometimes there's a leading new line, so we trim that out here.
return ltrim(ob_get_clean());
- } catch (Exception $e) {
+ } catch (\Exception $e) {
if(isset($jshrink)){
// Since the breakdownScript function probably wasn't finished
@@ -332,7 +332,7 @@ protected function getReal()
}
if($char === false)
- throw new \RuntimeException('Stray comment. ' . $this->index);
+ throw new \RuntimeException('Unclosed multiline comment at position: ' . ($this->index - 2));
// if we're here c is part of the comment and therefore tossed
if(isset($this->c))
@@ -374,6 +374,8 @@ protected function getNext($string)
*/
protected function saveString()
{
+ $startpos = $this->index;
+
// saveString is always called after a gets cleared, so we push b into
// that spot.
$this->a = $this->b;
@@ -412,7 +414,7 @@ protected function saveString()
// character, so those will be treated just fine using the switch
// block below.
case "\n":
- throw new \RuntimeException('Unclosed string. ' . $this->index);
+ throw new \RuntimeException('Unclosed string at position: ' . $startpos );
break;
@@ -463,7 +465,7 @@ protected function saveRegex()
}
if($this->a == "\n")
- throw new \RuntimeException('Stray regex pattern. ' . $this->index);
+ throw new \RuntimeException('Unclosed regex pattern as position: ' . $this->index);
echo $this->a;
}
@@ -17,6 +17,7 @@ class JShrinkTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException RuntimeException
+ * @expectedExceptionMessage Unclosed multiline comment at position: 1
*/
public function testUnclosedCommentException()
{
@@ -25,6 +26,7 @@ public function testUnclosedCommentException()
/**
* @expectedException RuntimeException
+ * @expectedExceptionMessage Unclosed string at position: 14
*/
public function testUnclosedStringException()
{

0 comments on commit ade958e

Please sign in to comment.