Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Sabberworm/CSS/Value/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sabberworm\CSS\Value;

use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
use Sabberworm\CSS\Renderable;

abstract class Value implements Renderable {
Expand Down Expand Up @@ -55,6 +56,9 @@ public static function parseValue(ParserState $oParserState, $aListDelimiters =
array_splice($aStack, $iStartPosition - 1, $iLength * 2 - 1, array($oList));
}
}
if (!isset($aStack[0])) {
throw new UnexpectedTokenException(" {$oParserState->peek()} ", $oParserState->peek(1, -1) . $oParserState->peek(2), 'literal', $oParserState->currentLine());
}
return $aStack[0];
}

Expand Down
49 changes: 43 additions & 6 deletions tests/Sabberworm/CSS/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,26 +472,63 @@ function testTrailingWhitespace() {
}

/**
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
*/
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*/
function testCharsetFailure1() {
$this->parsedStructureForFile('-charset-after-rule', Settings::create()->withLenientParsing(false));
}

/**
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
*/
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*/
function testCharsetFailure2() {
$this->parsedStructureForFile('-charset-in-block', Settings::create()->withLenientParsing(false));
}

/**
* @expectedException Sabberworm\CSS\Parsing\SourceException
*/
* @expectedException \Sabberworm\CSS\Parsing\SourceException
*/
function testUnopenedClosingBracketFailure() {
$this->parsedStructureForFile('unopened-close-brackets', Settings::create()->withLenientParsing(false));
}

/**
* Ensure that a missing property value raises an exception.
*
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
* @covers \Sabberworm\CSS\Value\Value::parseValue()
*/
function testMissingPropertyValueStrict() {
$this->parsedStructureForFile('missing-property-value', Settings::create()->withLenientParsing(false));
}

/**
* Ensure that a missing property value is ignored when in lenient parsing mode.
*
* @covers \Sabberworm\CSS\Value\Value::parseValue()
*/
function testMissingPropertyValueLenient() {
$parsed = $this->parsedStructureForFile('missing-property-value', Settings::create()->withLenientParsing(true));
$rulesets = $parsed->getAllRuleSets();
$this->assertCount( 1, $rulesets );
$block = $rulesets[0];
$this->assertTrue( $block instanceof DeclarationBlock );
$this->assertEquals( array( 'div' ), $block->getSelectors() );
$rules = $block->getRules();
$this->assertCount( 1, $rules );
$rule = $rules[0];
$this->assertEquals( 'display', $rule->getRule() );
$this->assertEquals( 'inline-block', $rule->getValue() );
}

/**
* Parse structure for file.
*
* @param string $sFileName Filename.
* @param null|obJeCt $oSettings Settings.
*
* @return CSSList\Document Parsed document.
*/
function parsedStructureForFile($sFileName, $oSettings = null) {
$sFile = dirname(__FILE__) . '/../../files' . DIRECTORY_SEPARATOR . "$sFileName.css";
$oParser = new Parser(file_get_contents($sFile), $oSettings);
Expand Down