-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: respect separators while sorting fixes issue #161 * test(sort.test.ts): add tests for sorting * test(sort.test.ts): add tests for malformed HTML * perf(commands.ts, index.ts): improve sorting Use new strategy to sort classes and preserve formatting. * test(sort.test.ts): use new functions for testing
- Loading branch information
Diptesh Choudhuri
authored
Aug 11, 2021
1 parent
f03a776
commit 6dc8f22
Showing
3 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { HTMLParser } from 'windicss/utils/parser'; | ||
import { | ||
sortClassNames, | ||
rearrangeClasses, | ||
} from '../src/utils'; | ||
|
||
it('sorts classes single line', () => { | ||
const parser = new HTMLParser(); | ||
parser.html = ` | ||
<div class="p-4 text-transparent bg-transparent backdrop-blur" /> | ||
`; | ||
const p = parser.parseClasses()[0]; | ||
const expected = 'bg-transparent text-transparent p-4 backdrop-blur'; | ||
const sortedP = sortClassNames(p.result, {}); | ||
const toReplace = rearrangeClasses(p.result, sortedP); | ||
expect(toReplace).toBe(expected); | ||
}); | ||
|
||
it('sorts classes single line but malformed', () => { | ||
const parser = new HTMLParser(); | ||
parser.html = ` | ||
<div class=" p-4 text-transparent bg-transparent backdrop-blur" /> | ||
`; | ||
const p = parser.parseClasses()[0]; | ||
const expected = ' bg-transparent text-transparent p-4 backdrop-blur'; | ||
const sortedP = sortClassNames(p.result, {}); | ||
const toReplace = rearrangeClasses(p.result, sortedP); | ||
expect(toReplace).toBe(expected); | ||
}); | ||
|
||
it('sorts classes multi line', () => { | ||
const parser = new HTMLParser(); | ||
parser.html = ` | ||
<div | ||
class=" | ||
p-4 | ||
text-transparent | ||
bg-transparent | ||
backdrop-blur | ||
" | ||
/> | ||
`; | ||
const p = parser.parseClasses()[0]; | ||
const expected = ` | ||
bg-transparent | ||
text-transparent | ||
p-4 | ||
backdrop-blur | ||
`; | ||
|
||
const sortedP = sortClassNames(p.result, {}); | ||
const toReplace = rearrangeClasses(p.result, sortedP); | ||
expect(toReplace).toBe(expected); | ||
}); | ||
|
||
it('sorts classes multi line but malformed', () => { | ||
const parser = new HTMLParser(); | ||
parser.html = ` | ||
<div | ||
class=" | ||
p-4 | ||
text-transparent | ||
bg-transparent | ||
backdrop-blur | ||
" | ||
/> | ||
`; | ||
const p = parser.parseClasses()[0]; | ||
const expected = ` | ||
bg-transparent | ||
text-transparent | ||
p-4 | ||
backdrop-blur | ||
`; | ||
|
||
const sortedP = sortClassNames(p.result, {}); | ||
const toReplace = rearrangeClasses(p.result, sortedP); | ||
expect(toReplace).toBe(expected); | ||
}); |