| OLD | NEW | 
|---|
| 1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 import 'dart:async'; | 5 import 'dart:async'; | 
| 6 import 'dart:io'; | 6 import 'dart:io'; | 
| 7 | 7 | 
| 8 import 'package:glob/glob.dart'; | 8 import 'package:glob/glob.dart'; | 
| 9 import 'package:glob/src/utils.dart'; | 9 import 'package:glob/src/utils.dart'; | 
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 45     }); | 45     }); | 
| 46 | 46 | 
| 47     test("reports exceptions for non-existent directories", () { | 47     test("reports exceptions for non-existent directories", () { | 
| 48       schedule(() { | 48       schedule(() { | 
| 49         expect(new Glob("non/existent/**").listSync, | 49         expect(new Glob("non/existent/**").listSync, | 
| 50             throwsA(new isInstanceOf<FileSystemException>())); | 50             throwsA(new isInstanceOf<FileSystemException>())); | 
| 51       }); | 51       }); | 
| 52     }); | 52     }); | 
| 53   }); | 53   }); | 
| 54 | 54 | 
|  | 55   group("when case-sensitive", () { | 
|  | 56     test("lists literals case-sensitively", () { | 
|  | 57       schedule(() { | 
|  | 58         expect(new Glob("foo/BAZ/qux", caseSensitive: true).listSync, | 
|  | 59             throwsA(new isInstanceOf<FileSystemException>())); | 
|  | 60       }); | 
|  | 61     }); | 
|  | 62 | 
|  | 63     test("lists ranges case-sensitively", () { | 
|  | 64       schedule(() { | 
|  | 65         expect(new Glob("foo/[BX][A-Z]z/qux", caseSensitive: true).listSync, | 
|  | 66             throwsA(new isInstanceOf<FileSystemException>())); | 
|  | 67       }); | 
|  | 68     }); | 
|  | 69 | 
|  | 70     test("options preserve case-sensitivity", () { | 
|  | 71       schedule(() { | 
|  | 72         expect(new Glob("foo/{BAZ,ZAP}/qux", caseSensitive: true).listSync, | 
|  | 73             throwsA(new isInstanceOf<FileSystemException>())); | 
|  | 74       }); | 
|  | 75     }); | 
|  | 76   }); | 
|  | 77 | 
| 55   syncAndAsync((list) { | 78   syncAndAsync((list) { | 
| 56     group("literals", () { | 79     group("literals", () { | 
| 57       test("lists a single literal", () { | 80       test("lists a single literal", () { | 
| 58         expect(list("foo/baz/qux"), | 81         expect(list("foo/baz/qux"), | 
| 59             completion(equals([p.join("foo", "baz", "qux")]))); | 82             completion(equals([p.join("foo", "baz", "qux")]))); | 
| 60       }); | 83       }); | 
| 61 | 84 | 
| 62       test("lists a non-matching literal", () { | 85       test("lists a non-matching literal", () { | 
| 63         expect(list("foo/baz/nothing"), completion(isEmpty)); | 86         expect(list("foo/baz/nothing"), completion(isEmpty)); | 
| 64       }); | 87       }); | 
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 245         var pattern = separatorToForwardSlash( | 268         var pattern = separatorToForwardSlash( | 
| 246             p.absolute(p.join(sandbox, 'foo/baz/**'))); | 269             p.absolute(p.join(sandbox, 'foo/baz/**'))); | 
| 247 | 270 | 
| 248         return list(pattern); | 271         return list(pattern); | 
| 249       }), completion(unorderedEquals([ | 272       }), completion(unorderedEquals([ | 
| 250         p.join("foo", "baz", "bang"), | 273         p.join("foo", "baz", "bang"), | 
| 251         p.join("foo", "baz", "qux") | 274         p.join("foo", "baz", "qux") | 
| 252       ]))); | 275       ]))); | 
| 253     }); | 276     }); | 
| 254 | 277 | 
|  | 278     // Regression test for #4. | 
|  | 279     test("lists an absolute case-insensitive glob", () { | 
|  | 280       expect(schedule(() { | 
|  | 281         var pattern = separatorToForwardSlash( | 
|  | 282             p.absolute(p.join(sandbox, 'foo/Baz/**'))); | 
|  | 283 | 
|  | 284         return list(pattern, caseSensitive: false); | 
|  | 285       }), completion(unorderedEquals([ | 
|  | 286         p.join("foo", "baz", "bang"), | 
|  | 287         p.join("foo", "baz", "qux") | 
|  | 288       ]))); | 
|  | 289     }); | 
|  | 290 | 
| 255     test("lists a subdirectory that sometimes exists", () { | 291     test("lists a subdirectory that sometimes exists", () { | 
| 256       d.dir("top", [ | 292       d.dir("top", [ | 
| 257         d.dir("dir1", [ | 293         d.dir("dir1", [ | 
| 258           d.dir("subdir", [d.file("file")]) | 294           d.dir("subdir", [d.file("file")]) | 
| 259         ]), | 295         ]), | 
| 260         d.dir("dir2", []) | 296         d.dir("dir2", []) | 
| 261       ]).create(); | 297       ]).create(); | 
| 262 | 298 | 
| 263       expect(list("top/*/subdir/**"), | 299       expect(list("top/*/subdir/**"), | 
| 264           completion(equals([p.join("top", "dir1", "subdir", "file")]))); | 300           completion(equals([p.join("top", "dir1", "subdir", "file")]))); | 
| 265     }); | 301     }); | 
|  | 302 | 
|  | 303     group("when case-insensitive", () { | 
|  | 304       test("lists literals case-insensitively", () { | 
|  | 305         expect(list("foo/baz/qux", caseSensitive: false), | 
|  | 306             completion(equals([p.join("foo", "baz", "qux")]))); | 
|  | 307         expect(list("foo/BAZ/qux", caseSensitive: false), | 
|  | 308             completion(equals([p.join("foo", "baz", "qux")]))); | 
|  | 309       }); | 
|  | 310 | 
|  | 311       test("lists ranges case-insensitively", () { | 
|  | 312         expect(list("foo/[bx][a-z]z/qux", caseSensitive: false), | 
|  | 313             completion(equals([p.join("foo", "baz", "qux")]))); | 
|  | 314         expect(list("foo/[BX][A-Z]z/qux", caseSensitive: false), | 
|  | 315             completion(equals([p.join("foo", "baz", "qux")]))); | 
|  | 316       }); | 
|  | 317 | 
|  | 318       test("options preserve case-insensitivity", () { | 
|  | 319         expect(list("foo/{bar,baz}/qux", caseSensitive: false), | 
|  | 320             completion(equals([p.join("foo", "baz", "qux")]))); | 
|  | 321         expect(list("foo/{BAR,BAZ}/qux", caseSensitive: false), | 
|  | 322             completion(equals([p.join("foo", "baz", "qux")]))); | 
|  | 323       }); | 
|  | 324     }); | 
| 266   }); | 325   }); | 
| 267 } | 326 } | 
| 268 | 327 | 
| 269 typedef Future<List<String>> ListFn(String glob, | 328 typedef Future<List<String>> ListFn(String glob, | 
| 270     {bool recursive, bool followLinks}); | 329     {bool recursive, bool followLinks, bool caseSensitive}); | 
| 271 | 330 | 
| 272 /// Runs [callback] in two groups with two values of [listFn]: one that uses | 331 /// Runs [callback] in two groups with two values of [listFn]: one that uses | 
| 273 /// [Glob.list], one that uses [Glob.listSync]. | 332 /// [Glob.list], one that uses [Glob.listSync]. | 
| 274 void syncAndAsync(callback(ListFn listFn)) { | 333 void syncAndAsync(callback(ListFn listFn)) { | 
| 275   group("async", () { | 334   group("async", () { | 
| 276     callback((glob, {recursive: false, followLinks: true}) { | 335     callback((pattern, {recursive: false, followLinks: true, caseSensitive}) { | 
| 277       return schedule(() { | 336       return schedule(() { | 
| 278         return new Glob(glob, recursive: recursive) | 337         var glob = new Glob(pattern, | 
|  | 338             recursive: recursive, caseSensitive: caseSensitive); | 
|  | 339 | 
|  | 340         return glob | 
| 279             .list(root: sandbox, followLinks: followLinks) | 341             .list(root: sandbox, followLinks: followLinks) | 
| 280             .map((entity) => p.relative(entity.path, from: sandbox)) | 342             .map((entity) => p.relative(entity.path, from: sandbox)) | 
| 281             .toList(); | 343             .toList(); | 
| 282       }, 'listing $glob'); | 344       }, 'listing $pattern'); | 
| 283     }); | 345     }); | 
| 284   }); | 346   }); | 
| 285 | 347 | 
| 286   group("sync", () { | 348   group("sync", () { | 
| 287     callback((glob, {recursive: false, followLinks: true}) { | 349     callback((pattern, {recursive: false, followLinks: true, caseSensitive}) { | 
| 288       return schedule(() { | 350       return schedule(() { | 
| 289         return new Glob(glob, recursive: recursive) | 351         var glob = new Glob(pattern, | 
|  | 352             recursive: recursive, caseSensitive: caseSensitive); | 
|  | 353 | 
|  | 354         return glob | 
| 290             .listSync(root: sandbox, followLinks: followLinks) | 355             .listSync(root: sandbox, followLinks: followLinks) | 
| 291             .map((entity) => p.relative(entity.path, from: sandbox)) | 356             .map((entity) => p.relative(entity.path, from: sandbox)) | 
| 292             .toList(); | 357             .toList(); | 
| 293       }, 'listing $glob'); | 358       }, 'listing $pattern'); | 
| 294     }); | 359     }); | 
| 295   }); | 360   }); | 
| 296 } | 361 } | 
| 297 | 362 | 
| 298 void scheduleSandbox() { | 363 void scheduleSandbox() { | 
| 299   schedule(() { | 364   schedule(() { | 
| 300     return Directory.systemTemp.createTemp('glob_').then((dir) { | 365     return Directory.systemTemp.createTemp('glob_').then((dir) { | 
| 301       sandbox = dir.path; | 366       sandbox = dir.path; | 
| 302       d.defaultRoot = sandbox; | 367       d.defaultRoot = sandbox; | 
| 303     }); | 368     }); | 
| 304   }, 'creating sandbox'); | 369   }, 'creating sandbox'); | 
| 305 | 370 | 
| 306   currentSchedule.onComplete.schedule(() { | 371   currentSchedule.onComplete.schedule(() { | 
| 307     d.defaultRoot = null; | 372     d.defaultRoot = null; | 
| 308     if (sandbox == null) return null; | 373     if (sandbox == null) return null; | 
| 309     var oldSandbox = sandbox; | 374     var oldSandbox = sandbox; | 
| 310     sandbox = null; | 375     sandbox = null; | 
| 311     return new Directory(oldSandbox).delete(recursive: true); | 376     return new Directory(oldSandbox).delete(recursive: true); | 
| 312   }); | 377   }); | 
| 313 } | 378 } | 
| OLD | NEW | 
|---|