Skip to content

Commit c5979cd

Browse files
committed
Add arbitrary variant classes to fuzz tests
1 parent 160811c commit c5979cd

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

tests/fuzz/compare.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { exec } from 'child_process';
66
import { promisify } from 'util';
7-
import { allClasses, variants, variantStackingPatterns, opacityClasses, arbitraryValueClasses } from './tailwind-classes.js';
7+
import { allClasses, variants, variantStackingPatterns, opacityClasses, arbitraryValueClasses, arbitraryVariantClasses } from './tailwind-classes.js';
88
import { filterLegacyClasses, isLegacyClass } from './legacy-classes.js';
99
import prettier from 'prettier';
1010
import seedrandom from 'seedrandom';
@@ -24,7 +24,7 @@ const rng = seedrandom(SEED);
2424

2525
// Filter classes if needed and add real-world pattern classes
2626
const baseClasses = FILTER_LEGACY ? filterLegacyClasses(allClasses) : allClasses;
27-
const classPool = [...baseClasses, ...opacityClasses, ...arbitraryValueClasses];
27+
const classPool = [...baseClasses, ...opacityClasses, ...arbitraryValueClasses, ...arbitraryVariantClasses];
2828

2929
/**
3030
* Generate a random integer between min and max (inclusive)

tests/fuzz/tailwind-classes.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,4 +649,49 @@ export const arbitraryValueClasses = [
649649
'pt-[120px]', 'border-[1.5px]',
650650
];
651651

652+
// Arbitrary variant classes (Issue #115)
653+
// These use CSS selectors inside brackets as variants
654+
export const arbitraryVariantClasses = [
655+
// Element state selectors (& refers to current element)
656+
'[&.htmx-request]:h-0',
657+
'[&.htmx-request]:opacity-0',
658+
'[&.htmx-request]:pointer-events-none',
659+
'[&.active]:bg-red-500',
660+
'[&.active]:text-white',
661+
'[&.selected]:bg-blue-500',
662+
'[&.disabled]:opacity-50',
663+
'[&.disabled]:cursor-not-allowed',
664+
'[&.loading]:animate-pulse',
665+
'[&.open]:rotate-180',
666+
'[&.expanded]:max-h-screen',
667+
'[&.collapsed]:max-h-0',
668+
669+
// Attribute selectors
670+
'[&[data-state=open]]:bg-gray-100',
671+
'[&[data-active]]:ring-2',
672+
'[&[aria-selected=true]]:bg-blue-100',
673+
'[&[aria-expanded=true]]:rotate-180',
674+
675+
// Child/descendant selectors
676+
'[&>*]:p-4',
677+
'[&>*:first-child]:rounded-t-lg',
678+
'[&>*:last-child]:rounded-b-lg',
679+
'[&_p]:text-gray-700',
680+
'[&_a]:text-blue-500',
681+
682+
// Pseudo-element extensions
683+
'[&::before]:block',
684+
'[&::after]:absolute',
685+
686+
// Sibling selectors
687+
'[&+*]:mt-4',
688+
'[&~*]:opacity-50',
689+
690+
// Complex selectors
691+
'[&:not(:first-child)]:border-t',
692+
'[&:not(:last-child)]:border-b',
693+
'[&:nth-child(odd)]:bg-gray-50',
694+
'[&:hover]:scale-105',
695+
];
696+
652697
export default allClasses;

0 commit comments

Comments
 (0)