Debian Codegraph @

fast-glob/src/providers/matchers/partial.spec.ts

raw symbols SCIP
1 import * as assert from 'assert';
2
3 import { Pattern, MicromatchOptions } from '../../types';
4 import Settings from '../../settings';
5 import Matcher from './partial';
6
7 function getMatcher(patterns: Pattern[], options: MicromatchOptions = {}): Matcher {
8 return new Matcher(patterns, new Settings(), options);
9 }
10
11 function assertMatch(patterns: Pattern[], filepath: string): void | never {
12 const matcher = getMatcher(patterns);
13
14 assert.ok(matcher.match(filepath), `Path "${filepath}" should match: ${patterns}`);
15 }
16
17 function assertNotMatch(patterns: Pattern[], filepath: string): void | never {
18 const matcher = getMatcher(patterns);
19
20 assert.ok(!matcher.match(filepath), `Path "${filepath}" should do not match: ${patterns}`);
21 }
22
23 describe('Providers → Matchers → Partial', () => {
24 describe('.match', () => {
25 it('should handle patterns with globstar', () => {
26 assertMatch(['**'], 'a');
27 assertMatch(['**'], './a');
28 assertMatch(['**/a'], 'a');
29 assertMatch(['**/a'], 'b/a');
30 assertMatch(['a/**'], 'a/b');
31 assertNotMatch(['a/**'], 'b');
32 });
33
34 it('should do not match the latest segment', () => {
35 assertMatch(['b/*'], 'b');
36 assertNotMatch(['*'], 'a');
37 assertNotMatch(['a/*'], 'a/b');
38 });
39
40 it('should trying to match all patterns', () => {
41 assertMatch(['a/*', 'b/*'], 'b');
42 assertMatch(['non-match/b/c', 'a/*/c'], 'a/b');
43 assertNotMatch(['non-match/d/c', 'a/b/c'], 'a/d');
44 });
45
46 it('should match a static segment', () => {
47 assertMatch(['a/b'], 'a');
48 assertNotMatch(['b/b'], 'a');
49 });
50
51 it('should match a dynamic segment', () => {
52 assertMatch(['*/b'], 'a');
53 assertMatch(['{a,b}/*'], 'a');
54 assertNotMatch(['{a,b}/*'], 'c');
55 });
56 });
57 });