| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 d.dir("top", [ | 279 d.dir("top", [ |
| 257 d.dir("dir1", [ | 280 d.dir("dir1", [ |
| 258 d.dir("subdir", [d.file("file")]) | 281 d.dir("subdir", [d.file("file")]) |
| 259 ]), | 282 ]), |
| 260 d.dir("dir2", []) | 283 d.dir("dir2", []) |
| 261 ]).create(); | 284 ]).create(); |
| 262 | 285 |
| 263 expect(list("top/*/subdir/**"), | 286 expect(list("top/*/subdir/**"), |
| 264 completion(equals([p.join("top", "dir1", "subdir", "file")]))); | 287 completion(equals([p.join("top", "dir1", "subdir", "file")]))); |
| 265 }); | 288 }); |
| 289 |
| 290 group("when case-insensitive", () { |
| 291 test("lists literals case-insensitively", () { |
| 292 expect(list("foo/baz/qux", caseSensitive: false), |
| 293 completion(equals([p.join("foo", "baz", "qux")]))); |
| 294 expect(list("foo/BAZ/qux", caseSensitive: false), |
| 295 completion(equals([p.join("foo", "baz", "qux")]))); |
| 296 }); |
| 297 |
| 298 test("lists ranges case-insensitively", () { |
| 299 expect(list("foo/[bx][a-z]z/qux", caseSensitive: false), |
| 300 completion(equals([p.join("foo", "baz", "qux")]))); |
| 301 expect(list("foo/[BX][A-Z]z/qux", caseSensitive: false), |
| 302 completion(equals([p.join("foo", "baz", "qux")]))); |
| 303 }); |
| 304 |
| 305 test("options preserve case-insensitivity", () { |
| 306 expect(list("foo/{bar,baz}/qux", caseSensitive: false), |
| 307 completion(equals([p.join("foo", "baz", "qux")]))); |
| 308 expect(list("foo/{BAR,BAZ}/qux", caseSensitive: false), |
| 309 completion(equals([p.join("foo", "baz", "qux")]))); |
| 310 }); |
| 311 }); |
| 266 }); | 312 }); |
| 267 } | 313 } |
| 268 | 314 |
| 269 typedef Future<List<String>> ListFn(String glob, | 315 typedef Future<List<String>> ListFn(String glob, |
| 270 {bool recursive, bool followLinks}); | 316 {bool recursive, bool followLinks, bool caseSensitive}); |
| 271 | 317 |
| 272 /// Runs [callback] in two groups with two values of [listFn]: one that uses | 318 /// Runs [callback] in two groups with two values of [listFn]: one that uses |
| 273 /// [Glob.list], one that uses [Glob.listSync]. | 319 /// [Glob.list], one that uses [Glob.listSync]. |
| 274 void syncAndAsync(callback(ListFn listFn)) { | 320 void syncAndAsync(callback(ListFn listFn)) { |
| 275 group("async", () { | 321 group("async", () { |
| 276 callback((glob, {recursive: false, followLinks: true}) { | 322 callback((pattern, {recursive: false, followLinks: true, caseSensitive}) { |
| 277 return schedule(() { | 323 return schedule(() { |
| 278 return new Glob(glob, recursive: recursive) | 324 var glob = new Glob(pattern, |
| 325 recursive: recursive, caseSensitive: caseSensitive); |
| 326 |
| 327 return glob |
| 279 .list(root: sandbox, followLinks: followLinks) | 328 .list(root: sandbox, followLinks: followLinks) |
| 280 .map((entity) => p.relative(entity.path, from: sandbox)) | 329 .map((entity) => p.relative(entity.path, from: sandbox)) |
| 281 .toList(); | 330 .toList(); |
| 282 }, 'listing $glob'); | 331 }, 'listing $pattern'); |
| 283 }); | 332 }); |
| 284 }); | 333 }); |
| 285 | 334 |
| 286 group("sync", () { | 335 group("sync", () { |
| 287 callback((glob, {recursive: false, followLinks: true}) { | 336 callback((pattern, {recursive: false, followLinks: true, caseSensitive}) { |
| 288 return schedule(() { | 337 return schedule(() { |
| 289 return new Glob(glob, recursive: recursive) | 338 var glob = new Glob(pattern, |
| 339 recursive: recursive, caseSensitive: caseSensitive); |
| 340 |
| 341 return glob |
| 290 .listSync(root: sandbox, followLinks: followLinks) | 342 .listSync(root: sandbox, followLinks: followLinks) |
| 291 .map((entity) => p.relative(entity.path, from: sandbox)) | 343 .map((entity) => p.relative(entity.path, from: sandbox)) |
| 292 .toList(); | 344 .toList(); |
| 293 }, 'listing $glob'); | 345 }, 'listing $pattern'); |
| 294 }); | 346 }); |
| 295 }); | 347 }); |
| 296 } | 348 } |
| 297 | 349 |
| 298 void scheduleSandbox() { | 350 void scheduleSandbox() { |
| 299 schedule(() { | 351 schedule(() { |
| 300 return Directory.systemTemp.createTemp('glob_').then((dir) { | 352 return Directory.systemTemp.createTemp('glob_').then((dir) { |
| 301 sandbox = dir.path; | 353 sandbox = dir.path; |
| 302 d.defaultRoot = sandbox; | 354 d.defaultRoot = sandbox; |
| 303 }); | 355 }); |
| 304 }, 'creating sandbox'); | 356 }, 'creating sandbox'); |
| 305 | 357 |
| 306 currentSchedule.onComplete.schedule(() { | 358 currentSchedule.onComplete.schedule(() { |
| 307 d.defaultRoot = null; | 359 d.defaultRoot = null; |
| 308 if (sandbox == null) return null; | 360 if (sandbox == null) return null; |
| 309 var oldSandbox = sandbox; | 361 var oldSandbox = sandbox; |
| 310 sandbox = null; | 362 sandbox = null; |
| 311 return new Directory(oldSandbox).delete(recursive: true); | 363 return new Directory(oldSandbox).delete(recursive: true); |
| 312 }); | 364 }); |
| 313 } | 365 } |
| OLD | NEW |