Skip to content

[FEATURE] Support arithmetic operators in CSS functions #607

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

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Extend test for multiple operators to include max.
`calc` was already supported.
  • Loading branch information
JakeQZ committed Jun 21, 2024
commit 3808d0775c0ea9b97f2fb94eee2b0bbb6cc254c7
33 changes: 29 additions & 4 deletions tests/Value/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,38 @@ public function parsesArithmeticInFunctions(string $operator): void
}

/**
* @test
* @return array<string, array{0: string, 1: string}>
* The first datum is a template for the parser (using `sprintf` insertion marker `%s` for some expression).
* The second is for the expected result, which may have whitespace and trailing semicolon removed.
*/
public function parsesArithmeticWithMultipleOperatorsInFunctions(): void
public static function provideCssFunctionTemplates(): array
{
$subject = Value::parseValue(new ParserState('calc(300px + 10% + 10vw);', Settings::create()));
return [
'calc' => [
'to be parsed' => 'calc(%s);',
'expected' => 'calc(%s)',
],
'max' => [
'to be parsed' => 'max(300px, %s);',
'expected' => 'max(300px,%s)',
],
];
}

/**
* @test
*
* @dataProvider provideCssFunctionTemplates
*/
public function parsesArithmeticWithMultipleOperatorsInFunctions(
string $parserTemplate,
string $expectedResultTemplate
): void {
static $expression = '300px + 10% + 10vw';

$subject = Value::parseValue(new ParserState(\sprintf($parserTemplate, $expression), Settings::create()));

self::assertSame('calc(300px + 10% + 10vw)', (string) $subject);
self::assertSame(\sprintf($expectedResultTemplate, $expression), (string) $subject);
}

/**
Expand Down