| 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 /// A library for declaratively describing a filesystem structure, usually for | 5 /// A library for declaratively describing a filesystem structure, usually for |
| 6 /// the purpose of creating or validating it as part of a scheduled test. | 6 /// the purpose of creating or validating it as part of a scheduled test. |
| 7 /// | 7 /// |
| 8 /// You can use [dir] and [file] to define a filesystem structure. Then, you can | 8 /// You can use [dir] and [file] to define a filesystem structure. Then, you can |
| 9 /// call [Entry.create] to schedule a task that will create that structure on | 9 /// call [Descriptor.create] to schedule a task that will create that structure |
| 10 /// the physical filesystem, or [Entry.validate] to schedule an assertion that | 10 /// on the physical filesystem, or [Descriptor.validate] to schedule an |
| 11 /// that structure exists. For example: | 11 /// assertion that that structure exists. For example: |
| 12 /// | 12 /// |
| 13 /// import 'package:scheduled_test/descriptor.dart' as d; | 13 /// import 'package:scheduled_test/descriptor.dart' as d; |
| 14 /// import 'package:scheduled_test/scheduled_test.dart'; | 14 /// import 'package:scheduled_test/scheduled_test.dart'; |
| 15 /// | 15 /// |
| 16 /// void main() { | 16 /// void main() { |
| 17 /// test('Directory.rename', () { | 17 /// test('Directory.rename', () { |
| 18 /// d.dir('parent', [ | 18 /// d.dir('parent', [ |
| 19 /// d.file('sibling', 'sibling-contents'), | 19 /// d.file('sibling', 'sibling-contents'), |
| 20 /// d.dir('old-name', [ | 20 /// d.dir('old-name', [ |
| 21 /// d.file('child', 'child-contents') | 21 /// d.file('child', 'child-contents') |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 /// | 60 /// |
| 61 /// // ... | 61 /// // ... |
| 62 /// } | 62 /// } |
| 63 library descriptor; | 63 library descriptor; |
| 64 | 64 |
| 65 import 'dart:async'; | 65 import 'dart:async'; |
| 66 | 66 |
| 67 import '../../../pkg/pathos/lib/path.dart' as path; | 67 import '../../../pkg/pathos/lib/path.dart' as path; |
| 68 | 68 |
| 69 import 'scheduled_test.dart'; | 69 import 'scheduled_test.dart'; |
| 70 import 'src/descriptor/async.dart'; | 70 import 'src/descriptor/async_descriptor.dart'; |
| 71 import 'src/descriptor/directory.dart'; | 71 import 'src/descriptor/descriptor.dart'; |
| 72 import 'src/descriptor/entry.dart'; | 72 import 'src/descriptor/directory_descriptor.dart'; |
| 73 import 'src/descriptor/file.dart'; | 73 import 'src/descriptor/file_descriptor.dart'; |
| 74 import 'src/descriptor/nothing.dart'; | 74 import 'src/descriptor/nothing_descriptor.dart'; |
| 75 import 'src/descriptor/pattern_descriptor.dart'; |
| 75 | 76 |
| 76 export 'src/descriptor/async.dart'; | 77 export 'src/descriptor/async_descriptor.dart'; |
| 77 export 'src/descriptor/directory.dart'; | 78 export 'src/descriptor/descriptor.dart'; |
| 78 export 'src/descriptor/entry.dart'; | 79 export 'src/descriptor/directory_descriptor.dart'; |
| 79 export 'src/descriptor/file.dart'; | 80 export 'src/descriptor/file_descriptor.dart'; |
| 80 export 'src/descriptor/nothing.dart'; | 81 export 'src/descriptor/nothing_descriptor.dart'; |
| 82 export 'src/descriptor/pattern_descriptor.dart'; |
| 81 | 83 |
| 82 /// The root path for descriptors. Top-level descriptors will be created and | 84 /// The root path for descriptors. Top-level descriptors will be created and |
| 83 /// validated at this path. Defaults to the current working directory. | 85 /// validated at this path. Defaults to the current working directory. |
| 84 /// | 86 /// |
| 85 /// If this is set to `null`, it will reset itself to the current working | 87 /// If this is set to `null`, it will reset itself to the current working |
| 86 /// directory. | 88 /// directory. |
| 87 String get defaultRoot => _defaultRoot == null ? path.current : _defaultRoot; | 89 String get defaultRoot => _defaultRoot == null ? path.current : _defaultRoot; |
| 88 set defaultRoot(String value) { | 90 set defaultRoot(String value) { |
| 89 _defaultRoot = value; | 91 _defaultRoot = value; |
| 90 } | 92 } |
| 91 String _defaultRoot; | 93 String _defaultRoot; |
| 92 | 94 |
| 93 /// Creates a new text [File] descriptor with [name] and [contents]. | 95 /// Creates a new text [FileDescriptor] with [name] and [contents]. |
| 94 File file(Pattern name, [String contents='']) => new File(name, contents); | 96 FileDescriptor file(String name, [String contents='']) => |
| 97 new FileDescriptor(name, contents); |
| 95 | 98 |
| 96 /// Creates a new binary [File] descriptor with [name] and [contents]. | 99 /// Creates a new binary [FileDescriptor] descriptor with [name] and [contents]. |
| 97 File binaryFile(Pattern name, List<int> contents) => | 100 FileDescriptor binaryFile(String name, List<int> contents) => |
| 98 new File.binary(name, contents); | 101 new FileDescriptor.binary(name, contents); |
| 99 | 102 |
| 100 /// Creates a new [Directory] descriptor with [name] and [contents]. | 103 /// Creates a new [DirectoryDescriptor] descriptor with [name] and [contents]. |
| 101 Directory dir(Pattern name, [Iterable<Entry> contents]) => | 104 DirectoryDescriptor dir(String name, [Iterable<Descriptor> contents]) => |
| 102 new Directory(name, contents == null ? <Entry>[] : contents); | 105 new DirectoryDescriptor(name, contents == null? <Descriptor>[] : contents); |
| 103 | 106 |
| 104 /// Creates a new descriptor wrapping a [Future]. This descriptor forwards all | 107 /// Creates a new descriptor wrapping a [Future]. This descriptor forwards all |
| 105 /// asynchronous operations to the result of [future]. | 108 /// asynchronous operations to the result of [future]. |
| 106 Async async(Future<Entry> future) => new Async(future); | 109 AsyncDescriptor async(Future<Descriptor> future) => |
| 110 new AsyncDescriptor(future); |
| 107 | 111 |
| 108 /// Creates a new [Nothing] descriptor that asserts that no entry named [name] | 112 /// Creates a new [NothingDescriptor] descriptor that asserts that no entry |
| 109 /// exists. | 113 /// named [name] exists. |
| 110 Nothing nothing(Pattern name) => new Nothing(name); | 114 NothingDescriptor nothing(String name) => new NothingDescriptor(name); |
| 115 |
| 116 /// Creates a new [PatternDescriptor] descriptor that asserts than an entry with |
| 117 /// a name matching [pattern] exists, and matches the [Descriptor] returned |
| 118 /// by [fn]. |
| 119 PatternDescriptor pattern(Pattern name, EntryCreator fn) => |
| 120 new PatternDescriptor(name, fn); |
| 121 |
| 122 /// A convenience method for creating a [PatternDescriptor] descriptor that |
| 123 /// constructs a [FileDescriptor] descriptor. |
| 124 PatternDescriptor filePattern(Pattern name, [String contents='']) => |
| 125 pattern(name, (realName) => file(realName, contents)); |
| 126 |
| 127 /// A convenience method for creating a [PatternDescriptor] descriptor that |
| 128 /// constructs a [DirectoryDescriptor] descriptor. |
| 129 PatternDescriptor dirPattern(Pattern name, [Iterable<Descriptor> contents]) => |
| 130 pattern(name, (realName) => dir(realName, contents)); |
| OLD | NEW |