-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathumatch-spec.coffee
162 lines (135 loc) · 5.21 KB
/
umatch-spec.coffee
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
files = [
'file.txt'
'path/file.coffee'
'draft/mydraft.coffee'
'literate/draft/*.coffee.md'
'uRequireConfigUMD.coffee'
'mytext.md'
'draft/mydraft.txt'
'badfile'
]
specFiltersFiles = (spec, expectedFilteredFiles)->
equalSet (_.filter files, (f)-> umatch f, spec), expectedFilteredFiles
describe 'umatch filters', ->
describe "no files, with specs being:", ->
it "undefined", -> specFiltersFiles undefined, []
it "null", -> specFiltersFiles null, []
it "empty specs", -> specFiltersFiles [], []
it "silly specs", -> specFiltersFiles ['silly', 'spec'], []
it "`-> false`", -> specFiltersFiles [-> false], []
describe "all files:", ->
it "with `'**/*'`", -> specFiltersFiles ['**/*'], files
it "with `/./`", -> specFiltersFiles [/./], files
it "with `-> true`", -> specFiltersFiles [-> true], files
describe "only files in root:", ->
it "with `'*'`", -> specFiltersFiles ['*'], [
'file.txt'
'uRequireConfigUMD.coffee'
'mytext.md'
'badfile'
]
it "only root files with extension `'*.*'`:", -> specFiltersFiles ['*.*'], [
'file.txt'
'uRequireConfigUMD.coffee'
'mytext.md'
]
describe "include or exclude specifics:", ->
it "included by name", ->
expectedFiles = [
'path/file.coffee'
'draft/mydraft.coffee'
'uRequireConfigUMD.coffee'
'mytext.md'
]
specFiltersFiles expectedFiles, expectedFiles
describe "included by extension:", ->
expectedFiles = ['path/file.coffee', 'draft/mydraft.coffee', 'uRequireConfigUMD.coffee']
it "with string spec", -> specFiltersFiles ['**/*.coffee'], expectedFiles
it "with RegExp spec", -> specFiltersFiles [/.*\.coffee$/], expectedFiles
it "with Function spec", -> specFiltersFiles [(f)-> f[f.length-6..] is 'coffee' ], expectedFiles
describe "excluded by extension:", ->
expectedFiles = [
'file.txt'
'literate/draft/*.coffee.md'
'mytext.md'
'draft/mydraft.txt'
'badfile'
]
it "with string spec", -> specFiltersFiles ['**/*', '!**/*.coffee'], expectedFiles
it "with RegExp spec", -> specFiltersFiles [/./, '!', /.*\.coffee$/], expectedFiles
it "with Function spec", -> specFiltersFiles [(->true), '!', (f)-> f[f.length-6..] is 'coffee' ], expectedFiles
describe "included, then excluded:", ->
expectedFiles = [
'path/file.coffee'
'uRequireConfigUMD.coffee'
# excluded 'draft/mydraft.coffee'
]
it "with string spec", -> specFiltersFiles ['**/*.coffee', '!*draft/*'], expectedFiles
it "with RegExp spec", -> specFiltersFiles [/.*\.coffee$/, '!', /draft/], expectedFiles
it "with Function spec", -> specFiltersFiles [
(f)-> f[f.length-6..] is 'coffee'
'!', (f)-> f.indexOf('draft') >= 0
], expectedFiles
describe "excluded, then included:", ->
expectedFiles = [
'file.txt'
'literate/draft/*.coffee.md'
'mytext.md'
'draft/mydraft.txt'
'badfile'
#included
'draft/mydraft.coffee'
]
it "with string spec", -> specFiltersFiles ['**/*', '!**/*.coffee', '*draft/*'], expectedFiles
it "with RegExp spec", -> specFiltersFiles [/./, '!', /.*\.coffee$/, /draft/], expectedFiles
it "with Function spec", -> specFiltersFiles [
(->true)
'!', (f)-> f[f.length-6..] is 'coffee'
(f)-> f.indexOf('draft') >= 0
], expectedFiles
describe "with String, RegExp, Function combined:", ->
it "correctly filters files", ->
specFiltersFiles [
'**/*'
'!**/draft/*.*'
'!uRequireConfig*.*'
'!', /.*\.md/
'**/*.coffee.md'
'**/draft/*.coffee'
'!', (f)-> f is 'badfile'
], [
'file.txt'
'path/file.coffee'
'draft/mydraft.coffee'
'literate/draft/*.coffee.md'
]
describe "A Function :", ->
it "that returns false / falsey for all files matches no file, thus excludes nothing", ->
specFiltersFiles [
'**/*'
(f)-> false
(f)-> undefined
(f)-> null
], files
it "that returns true for all files matches all files, thus includes all files", ->
specFiltersFiles [(f)-> true], files
it "that matches one file and has negation, excludes only that one file", ->
specFiltersFiles [/./, '!', (f)-> f is 'file.txt'], files.filter (f)-> f isnt 'file.txt'
describe "An Array ", ->
someFiles = ['file.txt', 'path/file.coffee']
it "that matches no files, excludes nothing", ->
specFiltersFiles [
'**/*'
['missing', 'irrelevant']
], files
it "that matches some files, includes those files", ->
specFiltersFiles [ someFiles ], someFiles
it "is recursivelly processed", ->
specFiltersFiles [ [ [ someFiles ] ] ], someFiles
it "that matches some files and has negation, excludes only those files", ->
specFiltersFiles [/./, '!', someFiles], files.filter (f)-> f not in someFiles
describe "Bad specs", ->
it "throw a TypeError exception ", ->
expect(-> umatch "somefile", [1]).to.throw TypeError
expect(-> umatch "somefile", [{}]).to.throw TypeError
expect(-> umatch "somefile", [true]).to.throw TypeError