Skip to content

Commit 8818f96

Browse files
KaiOnGitHubJakeQZ
authored andcommitted
[FEATURE] Add support for the dvh, lvh and svh length units (#415)
Fixes #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.)
1 parent ef8c59c commit 8818f96

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
77

88
### Added
99

10+
- Add support for the `dvh`, `lvh` and `svh` length units (#415)
11+
1012
### Changed
1113

1214
### Deprecated

src/Value/Size.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ class Size extends PrimitiveValue
1919
*
2020
* @internal
2121
*/
22-
const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem'];
22+
const ABSOLUTE_SIZE_UNITS = [
23+
'px', 'pt', 'pc',
24+
'cm', 'mm', 'mozmm', 'in',
25+
'vh', 'dvh', 'svh', 'lvh',
26+
'vw', 'vmin', 'vmax', 'rem',
27+
];
2328

2429
/**
2530
* @var array<int, string>

tests/Value/SizeTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Sabberworm\CSS\Tests\Value;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Sabberworm\CSS\Parsing\ParserState;
7+
use Sabberworm\CSS\Settings;
8+
use Sabberworm\CSS\Value\Size;
9+
10+
/**
11+
* @covers \Sabberworm\CSS\Value\Size
12+
*/
13+
final class SizeTest extends TestCase
14+
{
15+
/**
16+
* @return array<string, array{0: string}>
17+
*/
18+
public static function provideUnit(): array
19+
{
20+
$units = [
21+
'px', 'pt', 'pc',
22+
'cm', 'mm', 'mozmm', 'in',
23+
'vh', 'dvh', 'svh', 'lvh',
24+
'vw', 'vmin', 'vmax', 'rem',
25+
'%', 'em', 'ex', 'ch', 'fr',
26+
'deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz',
27+
];
28+
29+
return \array_combine(
30+
$units,
31+
\array_map(
32+
function (string $unit): array {
33+
return [$unit];
34+
},
35+
$units
36+
)
37+
);
38+
}
39+
40+
/**
41+
* @test
42+
*
43+
* @dataProvider provideUnit
44+
*/
45+
public function parsesUnit(string $unit): void
46+
{
47+
$subject = Size::parse(new ParserState('1' . $unit, Settings::create()));
48+
49+
self::assertSame($unit, $subject->getUnit());
50+
}
51+
}

0 commit comments

Comments
 (0)