11import Glob
2+ import Glob.Data.NonEmptyList
23import Glob.Data.Tree
34import Glob.WF.IO
45import Glob.WF.Tree
@@ -23,26 +24,26 @@ def glob (pattern : PatternValidated) (tree : Tree) : Option Tree := none
2324def globMany (patterns : NonEmptyList PatternValidated) (tree : Tree) : Option Tree := none
2425
2526-- Helper to assert glob results match expected Tree
26- def assertGlobResult (name : String) ( pattern : String) (tree : Tree) (expected : Option Tree) : IO Unit := do
27+ def assertGlobResult (pattern : String) (tree : Tree) (expected : Option Tree) : IO Unit := do
2728 let patternValidated ← PatternValidated.patternStrictIO! pattern
2829 let actual := glob patternValidated tree
2930 unless actual == expected do
30- IO.println s! "❌ { name } failed:"
31+ IO.println s! "❌ { pattern } failed:"
3132 IO.println s! " Pattern: { pattern} "
3233 IO.println s! " Expected: { reprStr expected} "
3334 IO.println s! " Actual: { reprStr actual} "
34- throw <| IO.Error.userError s! "Assertion failed: { name } "
35+ throw <| IO.Error.userError s! "Assertion failed: { pattern } "
3536
3637-- Helper to assert globMany results match expected Tree
37- def assertGlobManyResult (name : String) ( patternsNel : NonEmptyList String) (tree : Tree) (expected : Option Tree) : IO Unit := do
38+ def assertGlobManyResult (patternsNel : NonEmptyList String) (tree : Tree) (expected : Option Tree) : IO Unit := do
3839 let patternsNel' ← patternsNel.mapM PatternValidated.patternStrictIO!
3940 let actual := globMany patternsNel' tree
4041 unless actual == expected do
41- IO.println s! "❌ { name } failed:"
42+ IO.println s! "❌ { toString patternsNel } failed:"
4243 IO.println s! " Patterns: { patternsNel} "
4344 IO.println s! " Expected: { reprStr expected} "
4445 IO.println s! " Actual: { reprStr actual} "
45- throw <| IO.Error.userError s! "Assertion failed: { name } "
46+ throw <| IO.Error.userError s! "Assertion failed: { toString patternsNel } "
4647
4748-- Test data
4849def globTestExample1 := tree! "Glob" { "A" { "X" { } }, "B" { "Y" { } } }
@@ -58,198 +59,185 @@ def globTestExample2 := tree! "Root" {
5859def testBasicGlob : IO Unit := do
5960 IO.println "Testing basic glob patterns..."
6061
61- assertGlobResult "Glob root match" "Glob "
62+ assertGlobResult "Glob"
6263 (tree! "Glob" { "A" { } })
6364 (some (tree! "Glob" {}))
6465
65- assertGlobResult "Glob/A match" "Glob/A "
66+ assertGlobResult "Glob/A"
6667 (tree! "Glob" { "A" { } })
6768 (some (tree! "Glob" { "A" { } }))
6869
69- assertGlobResult "Glob/A match without children" "Glob/A "
70+ assertGlobResult "Glob/A"
7071 (tree! "Glob" { "A" })
7172 (some (tree! "Glob" { "A" }))
7273
73- assertGlobResult "Glob/B no match" "Glob/B "
74+ assertGlobResult "Glob/B"
7475 (tree! "Glob" { "A" { } })
7576 none
7677
7778-- Wildcard tests
7879def testWildcardGlob : IO Unit := do
7980 IO.println "Testing wildcard patterns..."
8081
81- assertGlobResult "Double star match" " **"
82+ assertGlobResult "**"
8283 globTestExample1
8384 (some (tree! "Glob" { "A" { "X" {} }, "B" { "Y" {} } }))
8485
85- assertGlobResult "**/X recursive match" "**/X "
86+ assertGlobResult "**/X"
8687 globTestExample1
8788 (some (tree! "Glob" { "A" { "X" {} } }))
8889
89- assertGlobResult "**/Y recursive match" "**/Y "
90+ assertGlobResult "**/Y"
9091 globTestExample1
9192 (some (tree! "Glob" { "B" { "Y" {} } }))
9293
93- assertGlobResult "**/Z no match" "**/Z "
94+ assertGlobResult "**/Z"
9495 globTestExample1
9596 none
9697
97- assertGlobResult "Glob/* single level" "Glob/* "
98+ assertGlobResult "Glob/*"
9899 globTestExample1
99100 (some (tree! "Glob" { "A" {}, "B" {} }))
100101
101- assertGlobResult "Glob/** recursive" "Glob/** "
102+ assertGlobResult "Glob/**"
102103 globTestExample1
103104 (some globTestExample1)
104105
105106-- Specific path tests
106107def testSpecificPaths : IO Unit := do
107108 IO.println "Testing specific path patterns..."
108109
109- assertGlobResult "Glob/A/* match" "Glob/A/* "
110+ assertGlobResult "Glob/A/*"
110111 globTestExample1
111112 (some (tree! "Glob" { "A" { "X" {} } }))
112113
113- assertGlobResult "Glob/A/** recursive" "Glob/A/** "
114+ assertGlobResult "Glob/A/**"
114115 globTestExample1
115116 (some (tree! "Glob" { "A" { "X" { } } }))
116117
117- assertGlobResult "Glob/A/X exact match" "Glob/A/X "
118+ assertGlobResult "Glob/A/X"
118119 globTestExample1
119120 (some (tree! "Glob" { "A" { "X" {} } }))
120121
121- assertGlobResult "Glob/B/** recursive" "Glob/B/** "
122+ assertGlobResult "Glob/B/**"
122123 globTestExample1
123124 (some (tree! "Glob" { "B" { "Y" {} } }))
124125
125- assertGlobResult "Glob/C no match" "Glob/C "
126+ assertGlobResult "Glob/C"
126127 globTestExample1
127128 none
128129
129130-- Simple tree tests
130131def testSimpleTrees : IO Unit := do
131132 IO.println "Testing simple tree patterns..."
132133
133- assertGlobResult "Single star match" " *"
134+ assertGlobResult "*"
134135 (tree! "foo" {})
135136 (some (tree! "foo" {}))
136137
137- assertGlobResult "Double star on simple tree" " **"
138+ assertGlobResult "**"
138139 (tree! "root" {})
139140 (some (tree! "root" {}))
140141
141142-- Complex tree tests
142143def testComplexTree : IO Unit := do
143144 IO.println "Testing complex tree patterns..."
144145
145- assertGlobResult "**/baz.txt deep search" "**/baz.txt "
146+ assertGlobResult "**/baz.txt"
146147 globTestExample2
147148 (some (tree! "Root" { "foo" { "bar" { "baz.txt" } } }))
148149
149- assertGlobResult "**/delta.txt deep search" "**/delta.txt "
150+ assertGlobResult "**/delta.txt"
150151 globTestExample2
151152 (some (tree! "Root" { "alpha" { "beta" { "gamma" { "delta.txt" } } } }))
152153
153- assertGlobResult "**/file.txt search" "**/file.txt "
154+ assertGlobResult "**/file.txt"
154155 globTestExample2
155156 (some (tree! "Root" { "foo" { "file.txt" } }))
156157
157- assertGlobResult "**/qux.md search" "**/qux.md "
158+ assertGlobResult "**/qux.md"
158159 globTestExample2
159160 (some (tree! "Root" { "foo" { "bar" { "qux.md" } } }))
160161
161- assertGlobResult "Root exact match" "Root "
162+ assertGlobResult "Root"
162163 globTestExample2
163164 (some (tree! "Root" {}))
164165
165- assertGlobResult "Root/* first level" "Root/* "
166+ assertGlobResult "Root/*"
166167 globTestExample2
167168 (some (Tree.dir "Root" [Tree.dir "foo" [], Tree.dir "foo2" [], Tree.dir "alpha" [], Tree.dir "zeta" []]))
168169
169- assertGlobResult "Root/** full tree" "Root/** "
170+ assertGlobResult "Root/**"
170171 globTestExample2
171172 (some globTestExample2)
172173
173174-- Multi-level pattern tests
174175def testMultiLevelPatterns : IO Unit := do
175176 IO.println "Testing multi-level patterns..."
176177
177- assertGlobResult "Root/**/bar/* nested wildcard" "Root/**/bar/* "
178+ assertGlobResult "Root/**/bar/*"
178179 globTestExample2
179180 (some (tree! "Root" { "foo" { "bar" { "baz.txt" , "qux.md" } }, "foo2" { "bar" { "baz2.txt" , "qux2.md" } } }))
180181
181- assertGlobResult "Root/**/delta.txt deep nested" "Root/**/delta.txt "
182+ assertGlobResult "Root/**/delta.txt"
182183 globTestExample2
183184 (some (tree! "Root" { "alpha" { "beta" { "gamma" { "delta.txt" } } } }))
184185
185- assertGlobResult "Root/**/file.txt nested search" "Root/**/file.txt "
186+ assertGlobResult "Root/**/file.txt"
186187 globTestExample2
187188 (some (tree! "Root" { "foo" { "file.txt" } }))
188189
189- assertGlobResult "Root/*/*/*/delta.txt exact depth" "Root/*/*/*/delta.txt "
190+ assertGlobResult "Root/*/*/*/delta.txt"
190191 globTestExample2
191192 (some (tree! "Root" { "alpha" { "beta" { "gamma" { "delta.txt" } } } }))
192193
193194-- Specific path combinations
194195def testSpecificCombinations : IO Unit := do
195196 IO.println "Testing specific path combinations..."
196197
197- assertGlobResult "Root/foo/**/baz.txt" "Root/foo/**/baz.txt"
198+ assertGlobResult "Root/foo/**/baz.txt"
198199 globTestExample2
199200 (some (tree! "Root" { "foo" { "bar" { "baz.txt" } } }))
200201
201- assertGlobResult "Root/foo/*/baz.txt" "Root/foo/*/baz.txt"
202+ assertGlobResult "Root/foo/*/baz.txt"
202203 globTestExample2
203204 (some (tree! "Root" { "foo" { "bar" { "baz.txt" } } }))
204205
205- assertGlobResult "Root/foo/*/doesntexist.txt no match" "Root/foo/*/doesntexist.txt "
206+ assertGlobResult "Root/foo/*/doesntexist.txt"
206207 globTestExample2
207208 none
208209
209- assertGlobResult "Root/foo/bar/baz.txt exact" "Root/foo/bar/baz.txt "
210+ assertGlobResult "Root/foo/bar/baz.txt"
210211 globTestExample2
211212 (some (tree! "Root" { "foo" { "bar" { "baz.txt" } } }))
212213
213- assertGlobResult "Root/foo/bar/baz.txt/extra invalid" "Root/foo/bar/baz.txt/extra "
214+ assertGlobResult "Root/foo/bar/baz.txt/extra"
214215 globTestExample2
215216 none
216217
217- assertGlobResult "Root/foo/bar/notfound.txt no match" "Root/foo/bar/notfound.txt "
218+ assertGlobResult "Root/foo/bar/notfound.txt"
218219 globTestExample2
219220 none
220221
221222-- GlobMany tests using assertGlobManyResult
222223def testGlobMany : IO Unit := do
223224 IO.println "Testing globMany patterns..."
224225
225- assertGlobManyResult "GlobMany test 1" nel!["Glob/A" , "Glob/B" ]
226- (tree! "Glob" { "A" {}, "B" {} })
227- (some (tree! "Glob" { "A" {}, "B" {} }))
228-
229- assertGlobManyResult "GlobMany test 2" nel!["Glob/A" , "Glob/C" ]
230- (tree! "Glob" { "A" {}, "B" {} })
231- (some (tree! "Glob" { "A" {} }))
232-
233- assertGlobManyResult "GlobMany test 3" nel!["**/X" , "**/Y" ]
234- globTestExample1
235- (some (tree! "Glob" { "A" { "X" {} }, "B" { "Y" {} } }))
236-
237- assertGlobManyResult "GlobMany test 4" nel!["**/baz.txt" , "**/delta.txt" ]
226+ assertGlobManyResult nel!["Glob/A" , "Glob/B" ] (tree! "Glob" { "A" {}, "B" {} }) (some (tree! "Glob" { "A" {}, "B" {} }))
227+ assertGlobManyResult nel!["Glob/A" , "Glob/C" ] (tree! "Glob" { "A" {}, "B" {} }) (some (tree! "Glob" { "A" {} }))
228+ assertGlobManyResult nel!["**/X" , "**/Y" ] globTestExample1 (some (tree! "Glob" { "A" { "X" {} }, "B" { "Y" {} } }))
229+ assertGlobManyResult nel!["**/baz.txt" , "**/delta.txt" ]
238230 globTestExample2
239231 (some (tree! "Root" {
240232 "foo" { "bar" { "baz.txt" } },
241233 "alpha" { "beta" { "gamma" { "delta.txt" } } }
242234 }))
243235
244- assertGlobManyResult "GlobMany test 5" nel!["**/file.txt" , "**/qux.md" ]
245- globTestExample2
246- (some (tree! "Root" { "foo" { "file.txt" , "bar" { "qux.md" } } }))
236+ assertGlobManyResult nel!["**/file.txt" , "**/qux.md" ] globTestExample2 (some (tree! "Root" { "foo" { "file.txt" , "bar" { "qux.md" } } }))
247237
248- assertGlobManyResult "GlobMany test 6" nel!["**/doesntexist.txt" , "**/missing.txt" ]
249- globTestExample2
250- none
238+ assertGlobManyResult nel!["**/doesntexist.txt" , "**/missing.txt" ] globTestExample2 none
251239
252- assertGlobManyResult "GlobMany test 7" nel!["Root/foo/bar/baz.txt" , "Root/foo2/bar/qux2.md" ]
240+ assertGlobManyResult nel!["Root/foo/bar/baz.txt" , "Root/foo2/bar/qux2.md" ]
253241 globTestExample2
254242 (some (tree! "Root" {
255243 "foo" { "bar" { "baz.txt" } },
@@ -275,4 +263,4 @@ def runGlobTests : IO Unit := do
275263 IO.println s! "❌ Glob tests failed: { e} "
276264 throw e
277265
278- end
266+ end GlobSpec
0 commit comments