This repository has been archived by the owner on Feb 12, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix converting glob expression to regex error and add tests
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { constructPatternFilter } from '../src/utils' | ||
|
||
describe('constructPatternFilter', () => { | ||
it('should match exact strings', () => { | ||
const filter = constructPatternFilter(['test', 'example']) | ||
expect(filter('test')).toBe(true) | ||
expect(filter('example')).toBe(true) | ||
expect(filter('other')).toBe(false) | ||
}) | ||
|
||
it('should match patterns with wildcards', () => { | ||
const filter = constructPatternFilter(['*.js', '*.ts']) | ||
expect(filter('file.js')).toBe(true) | ||
expect(filter('file.ts')).toBe(true) | ||
expect(filter('file.txt')).toBe(false) | ||
}) | ||
|
||
it('should match patterns with regex special characters', () => { | ||
const filter = constructPatternFilter(['example*']) | ||
expect(filter('example123')).toBe(true) | ||
expect(filter('test123')).toBe(false) | ||
}) | ||
|
||
it('should handle empty patterns', () => { | ||
const filter = constructPatternFilter([]) | ||
expect(filter('anything')).toBe(false) | ||
}) | ||
|
||
it('should match mixed exact strings and patterns', () => { | ||
const filter = constructPatternFilter(['test', '*.js']) | ||
expect(filter('test')).toBe(true) | ||
expect(filter('file.js')).toBe(true) | ||
expect(filter('example')).toBe(false) | ||
}) | ||
}) |