Skip to content

Commit

Permalink
[FEATURE] Add support for the dvh, lvh and svh length units (My…
Browse files Browse the repository at this point in the history
…Intervals#627)

Fixes MyIntervals#412

For now, the `TestCase` just tests that all the unit values are parsed.
(Other tests can be added here, but are beyond the scope of this change.)

Co-authored-by: Kai König <[email protected]>
Co-authored-by: Jake Hotson <[email protected]>
  • Loading branch information
3 people authored Jun 29, 2024
1 parent 2487bde commit ab0baf7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Added
- Add support for inserting an item in a CSS list (#545)

- Add support for the `dvh`, `lvh` and `svh` length units (#415)

### Changed

### Deprecated
Expand Down
7 changes: 6 additions & 1 deletion src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class Size extends PrimitiveValue
*
* @internal
*/
const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem'];
const ABSOLUTE_SIZE_UNITS = [
'px', 'pt', 'pc',
'cm', 'mm', 'mozmm', 'in',
'vh', 'dvh', 'svh', 'lvh',
'vw', 'vmin', 'vmax', 'rem',
];

/**
* @var array<int, string>
Expand Down
51 changes: 51 additions & 0 deletions tests/Value/SizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Sabberworm\CSS\Tests\Value;

use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Value\Size;

/**
* @covers \Sabberworm\CSS\Value\Size
*/
final class SizeTest extends TestCase
{
/**
* @return array<string, array{0: string}>
*/
public static function provideUnit()
{
$units = [
'px', 'pt', 'pc',
'cm', 'mm', 'mozmm', 'in',
'vh', 'dvh', 'svh', 'lvh',
'vw', 'vmin', 'vmax', 'rem',
'%', 'em', 'ex', 'ch', 'fr',
'deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz',
];

return \array_combine(
$units,
\array_map(
function ($unit) {
return [$unit];
},
$units
)
);
}

/**
* @test
*
* @dataProvider provideUnit
*/
public function parsesUnit($unit)
{
$subject = Size::parse(new ParserState('1' . $unit, Settings::create()));

self::assertSame($unit, $subject->getUnit());
}
}

0 comments on commit ab0baf7

Please sign in to comment.