|
1 | 1 | import { describe, it, expect } from "vitest";
|
2 | 2 | import { basicMatcher, loadMatcher } from "./matcher";
|
3 | 3 |
|
4 |
| -describe("basicMatcher", () => { |
5 |
| - it("matches exact strings", () => { |
6 |
| - expect(basicMatcher.isMatch("foo.bar", ["foo.bar"])).toBe(true); |
7 |
| - expect(basicMatcher.isMatch("foo.bar", ["foo.baz"])).toBe(false); |
8 |
| - }); |
| 4 | +for (const matcherName of ["basicMatcher", "micromatch", "picomatch"] as const) { |
| 5 | + describe(matcherName, async () => { |
| 6 | + const matcher = matcherName === "basicMatcher" ? basicMatcher : await loadMatcher(matcherName); |
| 7 | + it("matches exact strings", () => { |
| 8 | + expect(matcher.isMatch("foo.bar", ["foo.bar"])).toBe(true); |
| 9 | + expect(matcher.isMatch("foo.bar", ["foo.baz"])).toBe(false); |
| 10 | + }); |
9 | 11 |
|
10 |
| - it("matches with single * segment", () => { |
11 |
| - expect(basicMatcher.isMatch("foo.bar", ["foo.*"])).toBe(true); |
12 |
| - expect(basicMatcher.isMatch("foo.baz.qux", ["foo.*.qux"])).toBe(true); |
13 |
| - expect(basicMatcher.isMatch("foo.bar", ["*.baz"])).toBe(false); |
14 |
| - }); |
| 12 | + it("matches with single * segment", () => { |
| 13 | + expect(matcher.isMatch("foo.bar", ["foo.*"])).toBe(true); |
| 14 | + expect(matcher.isMatch("foo.baz.qux", ["foo.*.qux"])).toBe(true); |
| 15 | + expect(matcher.isMatch("foo.bar", ["*.baz"])).toBe(false); |
| 16 | + }); |
15 | 17 |
|
16 |
| - it("matches with ** for nested paths", () => { |
17 |
| - expect(basicMatcher.isMatch("a.b.c", ["a.**"])).toBe(true); |
18 |
| - expect(basicMatcher.isMatch("a.b.c.d", ["a.**.d"])).toBe(true); |
19 |
| - expect(basicMatcher.isMatch("a.b.c.d", ["**.d"])).toBe(true); |
20 |
| - expect(basicMatcher.isMatch("a.b.c.d", ["*.d"])).toBe(false); |
21 |
| - expect(basicMatcher.isMatch("a.b.c", ["**"])).toBe(true); |
22 |
| - }); |
| 18 | + it("matches with ** for nested paths", () => { |
| 19 | + expect(matcher.isMatch("a.b.c", ["a.**"])).toBe(true); |
| 20 | + expect(matcher.isMatch("a.b.c.d", ["a.**.d"])).toBe(true); |
| 21 | + expect(matcher.isMatch("a.b.c.d", ["**.d"])).toBe(true); |
| 22 | + expect(matcher.isMatch("a.b.c.d", ["*.d"])).toBe(false); |
| 23 | + expect(matcher.isMatch("a.b.c", ["**"])).toBe(true); |
| 24 | + }); |
23 | 25 |
|
24 |
| - it("supports prefix-* and *-suffix in segments", () => { |
25 |
| - expect(basicMatcher.isMatch("foo.helloWorld", ["foo.hello*"])).toBe(true); |
26 |
| - expect(basicMatcher.isMatch("foo.helloWorld", ["foo.*World"])).toBe(true); |
27 |
| - expect(basicMatcher.isMatch("foo.helloWorld", ["foo.hel*ld"])).toBe(true); |
28 |
| - expect(basicMatcher.isMatch("foo.helloWorld", ["foo.hel*xyz"])).toBe(false); |
29 |
| - }); |
| 26 | + it("supports prefix-* and *-suffix in segments", () => { |
| 27 | + expect(matcher.isMatch("foo.helloWorld", ["foo.hello*"])).toBe(true); |
| 28 | + expect(matcher.isMatch("foo.helloWorld", ["foo.*World"])).toBe(true); |
| 29 | + expect(matcher.isMatch("foo.helloWorld", ["foo.hel*ld"])).toBe(true); |
| 30 | + expect(matcher.isMatch("foo.helloWorld", ["foo.hel*xyz"])).toBe(false); |
| 31 | + }); |
30 | 32 |
|
31 |
| - it("returns true if any pattern matches", () => { |
32 |
| - expect(basicMatcher.isMatch("foo.bar", ["no.match", "foo.*"])).toBe(true); |
33 |
| - }); |
| 33 | + it("returns true if any pattern matches", () => { |
| 34 | + expect(matcher.isMatch("foo.bar", ["no.match", "foo.*"])).toBe(true); |
| 35 | + }); |
34 | 36 |
|
35 |
| - it("handles empty patterns", () => { |
36 |
| - expect(basicMatcher.isMatch("foo.bar", [])).toBe(false); |
37 |
| - }); |
| 37 | + it("handles empty patterns", () => { |
| 38 | + expect(matcher.isMatch("foo.bar", [])).toBe(false); |
| 39 | + }); |
38 | 40 |
|
39 |
| - it("respects escapes", () => { |
40 |
| - expect(basicMatcher.isMatch("foo.helloWorld", ["foo.hello*"])).toBe(true); |
41 |
| - expect(basicMatcher.isMatch("foo.helloWorld", ["foo.hello\\*"])).toBe(false); |
42 |
| - expect(basicMatcher.isMatch("foo.hello*", ["foo.hello\\*"])).toBe(true); |
| 41 | + it("respects escapes", () => { |
| 42 | + expect(matcher.isMatch("foo.helloWorld", ["foo.hello*"])).toBe(true); |
| 43 | + expect(matcher.isMatch("foo.helloWorld", ["foo.hello\\*"])).toBe(false); |
| 44 | + expect(matcher.isMatch("foo.hello*", ["foo.hello\\*"])).toBe(true); |
43 | 45 |
|
44 |
| - expect(basicMatcher.isMatch("a.b.c", ["a.**"])).toBe(true); |
45 |
| - expect(basicMatcher.isMatch("a.b.c", ["a.\\*\\*"])).toBe(false); |
46 |
| - expect(basicMatcher.isMatch("a.**", ["a.\\*\\*"])).toBe(true); |
47 |
| - expect(basicMatcher.isMatch("a.c.b", ["a.***"])).toBe(false); |
| 46 | + expect(matcher.isMatch("a.b.c", ["a.**"])).toBe(true); |
| 47 | + expect(matcher.isMatch("a.b.c", ["a.\\*\\*"])).toBe(false); |
| 48 | + expect(matcher.isMatch("a.**", ["a.\\*\\*"])).toBe(true); |
| 49 | + expect(matcher.isMatch("a.c.b", ["a.***"])).toBe(false); |
| 50 | + }); |
48 | 51 | });
|
49 |
| -}); |
| 52 | +} |
50 | 53 |
|
51 | 54 | describe("loadMatcher", () => {
|
52 | 55 | it("loads micromatch when available", async () => {
|
|
0 commit comments