|
1 | 1 | import makeConsoleMock from 'consolemock'
|
2 | 2 |
|
3 |
| -import { validateBraces, BRACES_REGEXP } from '../../lib/validateBraces.js' |
| 3 | +import { |
| 4 | + validateBraces, |
| 5 | + INCORRECT_BRACES_REGEXP, |
| 6 | + DOUBLE_BRACES_REGEXP, |
| 7 | +} from '../../lib/validateBraces.js' |
4 | 8 |
|
5 |
| -describe('BRACES_REGEXP', () => { |
| 9 | +describe('INCORRECT_BRACES_REGEXP', () => { |
6 | 10 | it(`should match '*.{js}'`, () => {
|
7 |
| - expect('*.{js}'.match(BRACES_REGEXP)).toBeTruthy() |
| 11 | + expect('*.{js}'.match(INCORRECT_BRACES_REGEXP)).toBeTruthy() |
8 | 12 | })
|
9 | 13 |
|
10 | 14 | it(`should match 'file_{10}'`, () => {
|
11 |
| - expect('file_{test}'.match(BRACES_REGEXP)).toBeTruthy() |
| 15 | + expect('file_{test}'.match(INCORRECT_BRACES_REGEXP)).toBeTruthy() |
12 | 16 | })
|
13 | 17 |
|
14 | 18 | it(`should match '*.{spec\\.js}'`, () => {
|
15 |
| - expect('*.{spec\\.js}'.match(BRACES_REGEXP)).toBeTruthy() |
| 19 | + expect('*.{spec\\.js}'.match(INCORRECT_BRACES_REGEXP)).toBeTruthy() |
16 | 20 | })
|
17 | 21 |
|
18 | 22 | it(`should match '*.{js\\,ts}'`, () => {
|
19 |
| - expect('*.{js\\,ts}'.match(BRACES_REGEXP)).toBeTruthy() |
| 23 | + expect('*.{js\\,ts}'.match(INCORRECT_BRACES_REGEXP)).toBeTruthy() |
20 | 24 | })
|
21 | 25 |
|
22 | 26 | it("should not match '*.${js}'", () => {
|
23 |
| - expect('*.${js}'.match(BRACES_REGEXP)).not.toBeTruthy() |
| 27 | + expect('*.${js}'.match(INCORRECT_BRACES_REGEXP)).toBeFalsy() |
24 | 28 | })
|
25 | 29 |
|
26 | 30 | it(`should not match '.{js,ts}'`, () => {
|
27 |
| - expect('.{js,ts}'.match(BRACES_REGEXP)).not.toBeTruthy() |
| 31 | + expect('.{js,ts}'.match(INCORRECT_BRACES_REGEXP)).toBeFalsy() |
28 | 32 | })
|
29 | 33 |
|
30 | 34 | it(`should not match 'file_{1..10}'`, () => {
|
31 |
| - expect('file_{1..10}'.match(BRACES_REGEXP)).not.toBeTruthy() |
| 35 | + expect('file_{1..10}'.match(INCORRECT_BRACES_REGEXP)).toBeFalsy() |
32 | 36 | })
|
33 | 37 |
|
34 | 38 | it(`should not match '*.\\{js\\}'`, () => {
|
35 |
| - expect('*.\\{js\\}'.match(BRACES_REGEXP)).not.toBeTruthy() |
| 39 | + expect('*.\\{js\\}'.match(INCORRECT_BRACES_REGEXP)).toBeFalsy() |
36 | 40 | })
|
37 | 41 |
|
38 | 42 | it(`should not match '*.\\{js}'`, () => {
|
39 |
| - expect('*.\\{js}'.match(BRACES_REGEXP)).not.toBeTruthy() |
| 43 | + expect('*.\\{js}'.match(INCORRECT_BRACES_REGEXP)).toBeFalsy() |
40 | 44 | })
|
41 | 45 |
|
42 | 46 | it(`should not match '*.{js\\}'`, () => {
|
43 |
| - expect('*.{js\\}'.match(BRACES_REGEXP)).not.toBeTruthy() |
| 47 | + expect('*.{js\\}'.match(INCORRECT_BRACES_REGEXP)).toBeFalsy() |
| 48 | + }) |
| 49 | +}) |
| 50 | + |
| 51 | +describe('DOUBLE_BRACES_REGEXP', () => { |
| 52 | + it(`should match '*.{{js,ts}}'`, () => { |
| 53 | + expect('*.{{js,ts}}'.match(DOUBLE_BRACES_REGEXP)).toBeTruthy() |
| 54 | + }) |
| 55 | + |
| 56 | + it(`should not match '*.{{js,ts},{css}}'`, () => { |
| 57 | + expect('*.{{js,ts},{css}}'.match(DOUBLE_BRACES_REGEXP)).toBeFalsy() |
| 58 | + }) |
| 59 | + |
| 60 | + it(`should not match '*.{{js,ts},{css}}'`, () => { |
| 61 | + expect('*.{{js,ts},{css}}'.match(DOUBLE_BRACES_REGEXP)).toBeFalsy() |
44 | 62 | })
|
45 | 63 | })
|
46 | 64 |
|
@@ -84,18 +102,15 @@ describe('validateBraces', () => {
|
84 | 102 | `)
|
85 | 103 | })
|
86 | 104 |
|
87 |
| - /** |
88 |
| - * @todo This isn't correctly detected even though the outer braces are invalid. |
89 |
| - */ |
90 |
| - it.skip('should warn about `*.{{js,ts}}` and return fixed pattern', () => { |
| 105 | + it('should warn about `*.{{js,ts}}` and return fixed pattern', () => { |
91 | 106 | const logger = makeConsoleMock()
|
92 | 107 |
|
93 | 108 | const fixedBraces = validateBraces('*.{{js,ts}}', logger)
|
94 | 109 |
|
95 | 110 | expect(fixedBraces).toEqual('*.{js,ts}')
|
96 | 111 | expect(logger.printHistory()).toMatchInlineSnapshot(`
|
97 | 112 | "
|
98 |
| - WARN ‼ Detected incorrect braces with only single value: \`*.{{js,ts}}\`. Reformatted as: \`*.{js,ts}\` |
| 113 | + WARN ⚠ Detected incorrect braces with only single value: \`*.{{js,ts}}\`. Reformatted as: \`*.{js,ts}\` |
99 | 114 | "
|
100 | 115 | `)
|
101 | 116 | })
|
|
0 commit comments