Skip to content

Commit

Permalink
Merge "Less_Tree_Rule: Add source to "Operation on an invalid type" e…
Browse files Browse the repository at this point in the history
…rror"
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Nov 29, 2023
2 parents b60b3d7 + 1ede985 commit 9501d9f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/Less/Tree/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function compile( $env ) {
if ( !is_numeric( $e->index ) ) {
$e->index = $this->index;
$e->currentFile = $this->currentFileInfo;
$e->genMessage();
}
throw $e;
}
Expand Down
8 changes: 2 additions & 6 deletions test/phpunit/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ public static function reverse( $arg ) {
}

public function testException() {
$lessCode = '
.foo {
content: number("x");
}
';
$lessFile = __DIR__ . '/data/exception/f1.less';

$parser = new Less_Parser();
$parser->parse( $lessCode );
$parser->parseFile( $lessFile );

try {
$parser->getCss();
Expand Down
40 changes: 40 additions & 0 deletions test/phpunit/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,44 @@ public function testAllParsedFiles() {
$files
);
}

public function testOperationException() {
$lessFile = __DIR__ . '/data/exception/f2.less';

$parser = new Less_Parser();
$parser->parseFile( $lessFile );

try {
$parser->getCss();
} catch ( Exception $e ) {
$this->assertInstanceOf( Less_Exception_Parser::class, $e );
$this->assertEquals(
"Operation on an invalid type in f2.less on line 4, column 2
2| @bar: 'world';
3| div {
4| content: (@foo) * @bar;
5| }",
$e->getMessage()
);
}

$lessFile = __DIR__ . '/data/exception/f3.less';

$parser = new Less_Parser();
$parser->parseFile( $lessFile );

try {
$parser->getCss();
} catch ( Exception $e ) {
$this->assertInstanceOf( Less_Exception_Parser::class, $e );
$this->assertEquals(
"Operation on an invalid type in f3.less on line 5, column 2
3|
4| div {
5| content: @foo * @bar;
6| }",
$e->getMessage()
);
}
}
}
3 changes: 3 additions & 0 deletions test/phpunit/data/exception/f1.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
content: number("x");
}
5 changes: 5 additions & 0 deletions test/phpunit/data/exception/f2.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@foo: 'hello';
@bar: 'world';
div {
content: (@foo) * @bar;
}
6 changes: 6 additions & 0 deletions test/phpunit/data/exception/f3.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@foo: 'hello';
@bar: 'world';

div {
content: @foo * @bar;
}

0 comments on commit 9501d9f

Please sign in to comment.