-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/arithmetic in functions #390
Changes from all commits
093c527
f734920
184b610
83d7609
ec9fc7c
1ee1820
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,35 @@ public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0 | |
parent::__construct($aArguments, $sSeparator, $iLineNo); | ||
} | ||
|
||
/** | ||
* @param ParserState $oParserState | ||
* @param bool $bIgnoreCase | ||
* | ||
* @return string | ||
* | ||
* @throws SourceException | ||
* @throws UnexpectedEOFException | ||
* @throws UnexpectedTokenException | ||
*/ | ||
public static function parseName(ParserState $oParserState, $bIgnoreCase = false) | ||
{ | ||
return $oParserState->parseIdentifier($bIgnoreCase); | ||
} | ||
|
||
/** | ||
* @param ParserState $oParserState | ||
* | ||
* @return array | ||
* | ||
* @throws SourceException | ||
* @throws UnexpectedEOFException | ||
* @throws UnexpectedTokenException | ||
*/ | ||
public static function parseArgs(ParserState $oParserState) | ||
{ | ||
return Value::parseValue($oParserState, ['=', ' ', ',']); | ||
} | ||
|
||
Comment on lines
+36
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the refactoring. But can the new methods be made Also, since we now have a minimum PHP version of 7.2, the return types can be included in the function declaration (and removed from the DocBlock, since they would then become redundant there). (I know we didn't have PHP>=7.2 at the time this PR was created.) |
||
/** | ||
* @param ParserState $oParserState | ||
* @param bool $bIgnoreCase | ||
|
@@ -45,9 +74,9 @@ public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0 | |
*/ | ||
public static function parse(ParserState $oParserState, $bIgnoreCase = false) | ||
{ | ||
$mResult = $oParserState->parseIdentifier($bIgnoreCase); | ||
$mResult = self::parseName($oParserState, $bIgnoreCase); | ||
$oParserState->consume('('); | ||
$aArguments = Value::parseValue($oParserState, ['=', ' ', ',']); | ||
$aArguments = self::parseArgs($oParserState); | ||
$mResult = new CSSFunction($mResult, $aArguments, ',', $oParserState->currentLine()); | ||
$oParserState->consume(')'); | ||
return $mResult; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1240,6 +1240,29 @@ public function lonelyImport() | |
self::assertSame($sExpected, $oDoc->render()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function functionArithmeticInFile() | ||
{ | ||
$oDoc = self::parsedStructureForFile('function-arithmetic', Settings::create()->withMultibyteSupport(true)); | ||
$sExpected = 'div {height: max(300,vh + 10);} | ||
div {height: max(300,vh - 10);} | ||
div {height: max(300,vh * 10);} | ||
div {height: max(300,vh / 10);}'; | ||
Comment on lines
+1249
to
+1252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For readability, can this be a series of concatenations with "\n", so that indentation is retained? |
||
self::assertSame($sExpected, $oDoc->render()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function infiniteLoopInFile() | ||
{ | ||
$oDoc = self::parsedStructureForFile('infinite-loop', Settings::create()->withMultibyteSupport(true)); | ||
$sExpected = 'div {}'; | ||
self::assertSame($sExpected, $oDoc->render()); | ||
} | ||
|
||
public function escapedSpecialCaseTokens() | ||
{ | ||
$oDoc = $this->parsedStructureForFile('escaped-tokens'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
div { | ||
height: max(300, vh + 10); | ||
} | ||
div { | ||
height: max(300, vh - 10); | ||
} | ||
div { | ||
height: max(300, vh * 10); | ||
} | ||
div { | ||
height: max(300, vh / 10); | ||
} | ||
Comment on lines
+1
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer valid examples here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
div { | ||
height: ///!; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps
parseArguments
is a better name (though I know 'args' is a very common shorthand).