Skip to content

Commit

Permalink
Chore: Add ArbitraryLengthValidator to Config class and ArbitraryShad…
Browse files Browse the repository at this point in the history
…owValidatorTest
  • Loading branch information
mr-chetan committed Jun 11, 2024
1 parent 02273f8 commit fcad976
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 160 deletions.
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
"require": {
"php": "^8.2.0",
"psr/simple-cache": "^3.0",
"illuminate/support": "^v11.5"
"illuminate/support": "^v11.10"
},
"require-dev": {
"laravel/pint": "^v1.15.2",
"nunomaduro/collision": "^v8.1.1",
"pestphp/pest": "^v2.34.7",
"pestphp/pest-plugin-arch": "^v2.7.0",
"laravel/pint": "^v1.16",
"nunomaduro/collision": "^v8.1",
"pestphp/pest": "^v2.34",
"pestphp/pest-plugin-arch": "^v2.7",
"pestphp/pest-plugin-mock": "^2.0",
"pestphp/pest-plugin-type-coverage": "^v2.8.1",
"phpstan/phpstan": "^1.10.67",
"rector/rector": "^1.0.4",
"symfony/var-dumper": "^v7.0.6"
"pestphp/pest-plugin-type-coverage": "^v2.8",
"phpstan/phpstan": "^1.11",
"rector/rector": "^1.1",
"symfony/var-dumper": "^v7.1"
},
"autoload": {
"psr-4": {
Expand Down
367 changes: 218 additions & 149 deletions composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Support/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,7 @@ private static function getLengthWithEmptyAndArbitrary(): array
return [
'',
LengthValidator::validate(...),
ArbitraryLengthValidator::validate(...),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Support/TailwindClassParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function getClassGroupId(string $class): string
private function getGroupIdForArbitraryProperty(string $className): string
{
if (Str::match(self::ARBITRARY_PROPERTY_REGEX, $className) !== '' && Str::match(self::ARBITRARY_PROPERTY_REGEX, $className) !== '0') {
$arbitraryPropertyClassName = Str::match(self::ARBITRARY_PROPERTY_REGEX, $className)[1] ?? '';
$arbitraryPropertyClassName = Str::match(self::ARBITRARY_PROPERTY_REGEX, $className);
$property = Str::before($arbitraryPropertyClassName, ':');

if ($property !== '' && $property !== '0') {
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/ArbitraryShadowValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ArbitraryShadowValidator implements \TailwindClassMerge\Contracts\Validato
{
use ValidatesArbitraryValue;

final public const SHADOW_REGEX = '/^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/';
final public const SHADOW_REGEX = '/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/';

public static function validate(string $value): bool
{
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/ArbitraryPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
})->with([
['[paint-order:markers] [paint-order:normal]', '[paint-order:normal]'],
['[paint-order:markers] [--my-var:2rem] [paint-order:normal] [--my-var:4px]', '[paint-order:normal] [--my-var:4px]'],
['[--first-var:1rem] [--second-var:2rem]', '[--first-var:1rem] [--second-var:2rem]'],
]);

it('handles arbitrary property conflicts with modifiers correctly', function (string $input, string $output) {
Expand Down
7 changes: 7 additions & 0 deletions tests/Feature/ArbitraryValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@
['bg-cover bg-[percentage:30%] bg-[length:200px_100px]', 'bg-[length:200px_100px]'],
['bg-none bg-[url(.)] bg-[image:.] bg-[url:.] bg-[linear-gradient(.)] bg-gradient-to-r', 'bg-gradient-to-r'],
]);

it('handles ambiguous non conflicting arbitrary values correctly', function (string $input, string $output) {
expect(TailwindClassMerge::instance()->merge($input))
->toBe($output);
})->with([
['border-[2px] border-[0.85px] border-[#ff0000] border-[#0000ff]', 'border-[0.85px] border-[#0000ff]'],
]);
1 change: 1 addition & 0 deletions tests/Unit/Validators/ArbitraryShadowValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
expect(ArbitraryShadowValidator::validate($input))->toBe($output);
})->with([
['[0_35px_60px_-15px_rgba(0,0,0,0.3)]', true],
['[inset_0_1px_0,inset_0_-1px_0]', true],
['[0_0_#00f]', true],
['[.5rem_0_rgba(5,5,5,5)]', true],
['[-.5rem_0_#123456]', true],
Expand Down

0 comments on commit fcad976

Please sign in to comment.