deno.land / std@0.224.0 / path / is_glob_test.ts

is_glob_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assert } from "../assert/mod.ts";import { isGlob } from "./is_glob.ts";
Deno.test({ name: "isGlob()", fn() { // should be true if valid glob pattern assert(isGlob("!foo.js")); assert(isGlob("*.js")); assert(isGlob("f?o.js")); assert(isGlob("!*.js")); assert(isGlob("!foo")); assert(isGlob("!foo.js")); assert(isGlob("**/abc.js")); assert(isGlob("abc/*.js")); assert(isGlob("@.(?:abc)")); assert(isGlob("@.(?!abc)"));
// should be false if invalid glob pattern assert(!isGlob("")); assert(!isGlob("~/abc")); assert(!isGlob("~/abc")); assert(!isGlob("~/(abc)")); assert(!isGlob("+~(abc)")); assert(!isGlob(".")); assert(!isGlob("@.(abc)")); assert(!isGlob("aa")); assert(!isGlob("abc!/def/!ghi.js")); assert(!isGlob("abc.js")); assert(!isGlob("abc/def/!ghi.js")); assert(!isGlob("abc/def/ghi.js"));
// Should be true if path has regex capture group assert(isGlob("abc/(?!foo).js")); assert(isGlob("abc/(?:foo).js")); assert(isGlob("abc/(?=foo).js")); assert(isGlob("abc/(a|b).js")); assert(isGlob("abc/(a|b|c).js")); assert(isGlob("abc/(foo bar)/*.js"));
// Should be false if the path has parens but is not a valid capture group assert(!isGlob("abc/(a b c).js")); assert(!isGlob("abc/(ab).js")); assert(!isGlob("abc/(abc).js")); assert(!isGlob("abc/(foo bar).js"));
// should be false if the capture group is imbalanced assert(!isGlob("abc/(ab.js")); assert(!isGlob("abc/(a|b.js")); assert(!isGlob("abc/(a|b|c.js"));
// should be true if the path has a regex character class assert(isGlob("abc/[abc].js")); assert(isGlob("abc/[^abc].js")); assert(isGlob("abc/[1-3].js"));
// should be false if the character class is not balanced assert(!isGlob("abc/[abc.js")); assert(!isGlob("abc/[^abc.js")); assert(!isGlob("abc/[1-3.js"));
// should be false if the character class is escaped assert(!isGlob("abc/\\[abc].js")); assert(!isGlob("abc/\\[^abc].js")); assert(!isGlob("abc/\\[1-3].js"));
// should be true if the path has brace characters assert(isGlob("abc/{a,b}.js")); assert(isGlob("abc/{a..z}.js")); assert(isGlob("abc/{a..z..2}.js"));
// should be false if (basic) braces are not balanced assert(!isGlob("abc/\\{a,b}.js")); assert(!isGlob("abc/\\{a..z}.js")); assert(!isGlob("abc/\\{a..z..2}.js"));
// should be true if the path has regex characters assert(isGlob("!&(abc)")); assert(isGlob("!*.js")); assert(isGlob("!foo")); assert(isGlob("!foo.js")); assert(isGlob("**/abc.js")); assert(isGlob("*.js")); assert(isGlob("*z(abc)")); assert(isGlob("[1-10].js")); assert(isGlob("[^abc].js")); assert(isGlob("[a-j]*[^c]b/c")); assert(isGlob("[abc].js")); assert(isGlob("a/b/c/[a-z].js")); assert(isGlob("abc/(aaa|bbb).js")); assert(isGlob("abc/*.js")); assert(isGlob("abc/{a,b}.js")); assert(isGlob("abc/{a..z..2}.js")); assert(isGlob("abc/{a..z}.js"));
assert(!isGlob("$(abc)")); assert(!isGlob("&(abc)"));
// should be false if regex characters are escaped assert(!isGlob("\\?.js")); assert(!isGlob("\\[1-10\\].js")); assert(!isGlob("\\[^abc\\].js")); assert(!isGlob("\\[a-j\\]\\*\\[^c\\]b/c")); assert(!isGlob("\\[abc\\].js")); assert(!isGlob("\\a/b/c/\\[a-z\\].js")); assert(!isGlob("abc/\\(aaa|bbb).js")); assert(!isGlob("abc/\\?.js")); },});
std

Version Info

Tagged at
6 months ago