OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library descriptor_test; | 5 library descriptor_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:pathos/path.dart' as path; | 10 import 'package:pathos/path.dart' as path; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 errors = currentSchedule.errors; | 116 errors = currentSchedule.errors; |
117 }); | 117 }); |
118 | 118 |
119 d.file('name.txt', 'contents').validate(); | 119 d.file('name.txt', 'contents').validate(); |
120 }); | 120 }); |
121 | 121 |
122 test('test 2', () { | 122 test('test 2', () { |
123 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 123 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
124 expect(errors.length, equals(1)); | 124 expect(errors.length, equals(1)); |
125 expect(errors.first.error, | 125 expect(errors.first.error, |
126 matches(r"^File not found: '[^']+/name\.txt'\.$")); | 126 matches(r"^File not found: '[^']+[\\/]name\.txt'\.$")); |
127 }); | 127 }); |
128 }, passing: ['test 2']); | 128 }, passing: ['test 2']); |
129 | 129 |
130 expectTestsPass('file().validate() with a RegExp completes successfully if ' | 130 expectTestsPass('file().validate() with a RegExp completes successfully if ' |
131 'the filesystem matches the descriptor', () { | 131 'the filesystem matches the descriptor', () { |
132 test('test', () { | 132 test('test', () { |
133 scheduleSandbox(); | 133 scheduleSandbox(); |
134 | 134 |
135 schedule(() { | 135 schedule(() { |
136 return new File(path.join(sandbox, 'name.txt')) | 136 return new File(path.join(sandbox, 'name.txt')) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 d.file(new RegExp(r'na..\.txt'), 'contents').validate(); | 216 d.file(new RegExp(r'na..\.txt'), 'contents').validate(); |
217 }); | 217 }); |
218 | 218 |
219 test('test 2', () { | 219 test('test 2', () { |
220 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 220 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
221 expect(errors.length, equals(1)); | 221 expect(errors.length, equals(1)); |
222 expect(errors.first.error, | 222 expect(errors.first.error, |
223 matches( | 223 matches( |
224 r"^Multiple entries found in '[^']+' matching /na\.\.\\\.txt/:\n" | 224 r"^Multiple entries found in '[^']+' matching /na\.\.\\\.txt/:\n" |
225 r"\* .*/nail\.txt\n" | 225 r"\* .*[\\/]nail\.txt\n" |
226 r"\* .*/name\.txt\n" | 226 r"\* .*[\\/]name\.txt\n" |
227 r"\* .*/nape\.txt")); | 227 r"\* .*[\\/]nape\.txt")); |
228 }); | 228 }); |
229 }, passing: ['test 2']); | 229 }, passing: ['test 2']); |
230 | 230 |
231 expectTestsPass("file().read() returns the contents of the file as a stream", | 231 expectTestsPass("file().read() returns the contents of the file as a stream", |
232 () { | 232 () { |
233 test('test', () { | 233 test('test', () { |
234 expect(byteStreamToString(d.file('name.txt', 'contents').read()), | 234 expect(byteStreamToString(d.file('name.txt', 'contents').read()), |
235 completion(equals('contents'))); | 235 completion(equals('contents'))); |
236 }); | 236 }); |
237 }); | 237 }); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 ]), | 436 ]), |
437 d.file('file1.txt', 'contents1'), | 437 d.file('file1.txt', 'contents1'), |
438 d.file('file2.txt', 'contents2') | 438 d.file('file2.txt', 'contents2') |
439 ]).validate(); | 439 ]).validate(); |
440 }); | 440 }); |
441 | 441 |
442 test('test 2', () { | 442 test('test 2', () { |
443 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 443 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
444 expect(errors.length, equals(1)); | 444 expect(errors.length, equals(1)); |
445 expect(errors.first.error, | 445 expect(errors.first.error, |
446 matches(r"^Directory not found: '[^']+/dir/subdir'\.$")); | 446 matches(r"^Directory not found: '[^']+[\\/]dir[\\/]subdir'\.$")); |
447 }); | 447 }); |
448 }, passing: ['test 2']); | 448 }, passing: ['test 2']); |
449 | 449 |
450 expectTestsPass("directory().validate() fails if a file isn't found", () { | 450 expectTestsPass("directory().validate() fails if a file isn't found", () { |
451 var errors; | 451 var errors; |
452 test('test 1', () { | 452 test('test 1', () { |
453 scheduleSandbox(); | 453 scheduleSandbox(); |
454 | 454 |
455 currentSchedule.onException.schedule(() { | 455 currentSchedule.onException.schedule(() { |
456 errors = currentSchedule.errors; | 456 errors = currentSchedule.errors; |
(...skipping 21 matching lines...) Expand all Loading... |
478 ]), | 478 ]), |
479 d.file('file1.txt', 'contents1'), | 479 d.file('file1.txt', 'contents1'), |
480 d.file('file2.txt', 'contents2') | 480 d.file('file2.txt', 'contents2') |
481 ]).validate(); | 481 ]).validate(); |
482 }); | 482 }); |
483 | 483 |
484 test('test 2', () { | 484 test('test 2', () { |
485 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 485 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
486 expect(errors.length, equals(1)); | 486 expect(errors.length, equals(1)); |
487 expect(errors.first.error, | 487 expect(errors.first.error, |
488 matches(r"^File not found: '[^']+/dir/file2\.txt'\.$")); | 488 matches(r"^File not found: '[^']+[\\/]dir[\\/]file2\.txt'\.$")); |
489 }); | 489 }); |
490 }, passing: ['test 2']); | 490 }, passing: ['test 2']); |
491 | 491 |
492 expectTestsPass("directory().validate() fails if a file has the wrong " | 492 expectTestsPass("directory().validate() fails if a file has the wrong " |
493 "contents", () { | 493 "contents", () { |
494 var errors; | 494 var errors; |
495 test('test 1', () { | 495 test('test 1', () { |
496 scheduleSandbox(); | 496 scheduleSandbox(); |
497 | 497 |
498 currentSchedule.onException.schedule(() { | 498 currentSchedule.onException.schedule(() { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 ]), | 602 ]), |
603 d.file('file1.txt', 'contents1'), | 603 d.file('file1.txt', 'contents1'), |
604 d.file('file2.txt', 'contents2') | 604 d.file('file2.txt', 'contents2') |
605 ]).validate(); | 605 ]).validate(); |
606 }); | 606 }); |
607 | 607 |
608 test('test 2', () { | 608 test('test 2', () { |
609 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 609 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
610 expect(errors.length, equals(1)); | 610 expect(errors.length, equals(1)); |
611 expect(errors.first.error, | 611 expect(errors.first.error, |
612 matches(r"^File not found: '[^']+/dir/file2\.txt'\.$")); | 612 matches(r"^File not found: '[^']+[\\/]dir[\\/]file2\.txt'\.$")); |
613 }); | 613 }); |
614 }, passing: ['test 2']); | 614 }, passing: ['test 2']); |
615 | 615 |
616 expectTestsPass("directory().validate() with a RegExp fails if there's no " | 616 expectTestsPass("directory().validate() with a RegExp fails if there's no " |
617 "dir", () { | 617 "dir", () { |
618 var errors; | 618 var errors; |
619 test('test 1', () { | 619 test('test 1', () { |
620 scheduleSandbox(); | 620 scheduleSandbox(); |
621 | 621 |
622 currentSchedule.onException.schedule(() { | 622 currentSchedule.onException.schedule(() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 d.file('file2.txt', 'contents2') | 679 d.file('file2.txt', 'contents2') |
680 ]).validate(); | 680 ]).validate(); |
681 }); | 681 }); |
682 | 682 |
683 test('test 2', () { | 683 test('test 2', () { |
684 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 684 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
685 expect(errors.length, equals(1)); | 685 expect(errors.length, equals(1)); |
686 expect(errors.first.error, | 686 expect(errors.first.error, |
687 matches( | 687 matches( |
688 r"^Multiple entries found in '[^']+' matching /d\.r/:\n" | 688 r"^Multiple entries found in '[^']+' matching /d\.r/:\n" |
689 r"\* .*/dar\n" | 689 r"\* .*[\\/]dar\n" |
690 r"\* .*/dir\n" | 690 r"\* .*[\\/]dir\n" |
691 r"\* .*/dor")); | 691 r"\* .*[\\/]dor")); |
692 }); | 692 }); |
693 }, passing: ['test 2']); | 693 }, passing: ['test 2']); |
694 | 694 |
695 expectTestsPass("directory().load() loads a file", () { | 695 expectTestsPass("directory().load() loads a file", () { |
696 test('test', () { | 696 test('test', () { |
697 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); | 697 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); |
698 expect(byteStreamToString(dir.load('name.txt')), | 698 expect(byteStreamToString(dir.load('name.txt')), |
699 completion(equals('contents'))); | 699 completion(equals('contents'))); |
700 }); | 700 }); |
701 }); | 701 }); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 | 882 |
883 Future<List<int>> byteStreamToList(Stream<List<int>> stream) { | 883 Future<List<int>> byteStreamToList(Stream<List<int>> stream) { |
884 return stream.reduce(<int>[], (buffer, chunk) { | 884 return stream.reduce(<int>[], (buffer, chunk) { |
885 buffer.addAll(chunk); | 885 buffer.addAll(chunk); |
886 return buffer; | 886 return buffer; |
887 }); | 887 }); |
888 } | 888 } |
889 | 889 |
890 Future<String> byteStreamToString(Stream<List<int>> stream) => | 890 Future<String> byteStreamToString(Stream<List<int>> stream) => |
891 byteStreamToList(stream).then((bytes) => new String.fromCharCodes(bytes)); | 891 byteStreamToList(stream).then((bytes) => new String.fromCharCodes(bytes)); |
OLD | NEW |