| 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.file; | 5 library descriptor.file; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 /// The contents of the file, in bytes. | 21 /// The contents of the file, in bytes. |
| 22 final List<int> contents; | 22 final List<int> contents; |
| 23 | 23 |
| 24 /// The contents of the file as a String. Assumes UTF-8 encoding. | 24 /// The contents of the file as a String. Assumes UTF-8 encoding. |
| 25 String get textContents => new String.fromCharCodes(contents); | 25 String get textContents => new String.fromCharCodes(contents); |
| 26 | 26 |
| 27 /// Creates a new text [FileDescriptor] with [name] that matches its String | 27 /// Creates a new text [FileDescriptor] with [name] that matches its String |
| 28 /// contents against [matcher]. If the file is created, it's considered to be | 28 /// contents against [matcher]. If the file is created, it's considered to be |
| 29 /// empty. | 29 /// empty. |
| 30 factory FileDescriptor.matcher(String name, Matcher matcher) => | 30 factory FileDescriptor.matcher(String name, Matcher matcher) => |
| 31 new _MatcherFileDescriptor(name, matcher, isBinary: false); | 31 new _MatcherFileDescriptor(name, matcher, isBinary: false); |
| 32 | 32 |
| 33 /// Creates a new binary [FileDescriptor] with [name] that matches its binary | 33 /// Creates a new binary [FileDescriptor] with [name] that matches its binary |
| 34 /// contents against [matcher]. If the file is created, it's considered to be | 34 /// contents against [matcher]. If the file is created, it's considered to be |
| 35 /// empty. | 35 /// empty. |
| 36 factory FileDescriptor.binaryMatcher(String name, Matcher matcher) => | 36 factory FileDescriptor.binaryMatcher(String name, Matcher matcher) => |
| 37 new _MatcherFileDescriptor(name, matcher, isBinary: true); | 37 new _MatcherFileDescriptor(name, matcher, isBinary: true); |
| 38 | 38 |
| 39 /// Creates a new binary [FileDescriptor] descriptor with [name] and | 39 /// Creates a new binary [FileDescriptor] descriptor with [name] and |
| 40 /// [contents]. | 40 /// [contents]. |
| 41 factory FileDescriptor.binary(String name, List<int> contents) => | 41 factory FileDescriptor.binary(String name, List<int> contents) => |
| 42 new _BinaryFileDescriptor(name, contents); | 42 new _BinaryFileDescriptor(name, contents); |
| 43 | 43 |
| 44 /// Creates a new text [FileDescriptor] with [name] and [contents]. | 44 /// Creates a new text [FileDescriptor] with [name] and [contents]. |
| 45 factory FileDescriptor(String name, String contents) => | 45 factory FileDescriptor(String name, String contents) => |
| 46 new _StringFileDescriptor(name, contents); | 46 new _StringFileDescriptor(name, contents); |
| 47 | 47 |
| 48 FileDescriptor._(String name, this.contents) | 48 FileDescriptor._(String name, this.contents) |
| 49 : super(name); | 49 : super(name); |
| 50 | 50 |
| 51 Future create([String parent]) => schedule(() { | 51 Future create([String parent]) => schedule(() { |
| 52 if (parent == null) parent = defaultRoot; | 52 if (parent == null) parent = defaultRoot; |
| 53 return Chain.track(new File(path.join(parent, name)) | 53 return Chain.track(new File(path.join(parent, name)) |
| 54 .writeAsBytes(contents)); | 54 .writeAsBytes(contents)); |
| 55 }, "creating file '$name'"); | 55 }, "creating file '$name'"); |
| 56 | 56 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 _MatcherFileDescriptor(String name, this._matcher, {bool isBinary}) | 143 _MatcherFileDescriptor(String name, this._matcher, {bool isBinary}) |
| 144 : _isBinary = isBinary == true ? true : false, | 144 : _isBinary = isBinary == true ? true : false, |
| 145 super._(name, <int>[]); | 145 super._(name, <int>[]); |
| 146 | 146 |
| 147 void _validateNow(List<int> actualContents) => | 147 void _validateNow(List<int> actualContents) => |
| 148 expect( | 148 expect( |
| 149 _isBinary ? actualContents : new String.fromCharCodes(actualContents), | 149 _isBinary ? actualContents : new String.fromCharCodes(actualContents), |
| 150 _matcher); | 150 _matcher); |
| 151 } | 151 } |
| OLD | NEW |