OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 lock_file_test; | 5 library lock_file_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:pub_semver/pub_semver.dart'; | 9 import 'package:pub_semver/pub_semver.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 import 'package:yaml/yaml.dart'; | 11 import 'package:yaml/yaml.dart'; |
12 | 12 |
13 import '../lib/src/lock_file.dart'; | 13 import '../lib/src/lock_file.dart'; |
14 import '../lib/src/package.dart'; | 14 import '../lib/src/package.dart'; |
15 import '../lib/src/pubspec.dart'; | 15 import '../lib/src/pubspec.dart'; |
16 import '../lib/src/source.dart'; | 16 import '../lib/src/source.dart'; |
17 import '../lib/src/source_registry.dart'; | 17 import '../lib/src/source_registry.dart'; |
18 import 'test_pub.dart'; | 18 import 'test_pub.dart'; |
19 | 19 |
20 class MockSource extends Source { | 20 class MockSource extends Source { |
21 final String name = 'mock'; | 21 final String name = 'mock'; |
22 | 22 |
23 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( | 23 Future<Pubspec> doDescribe(PackageId id) => |
24 "Cannot describe mock packages."); | 24 throw new UnsupportedError("Cannot describe mock packages."); |
25 | 25 |
26 Future get(PackageId id, String symlink) => throw new UnsupportedError( | 26 Future get(PackageId id, String symlink) => |
27 "Cannot get a mock package."); | 27 throw new UnsupportedError("Cannot get a mock package."); |
28 | 28 |
29 Future<String> getDirectory(PackageId id) => throw new UnsupportedError( | 29 Future<String> getDirectory(PackageId id) => |
30 "Cannot get the directory for mock packages."); | 30 throw new UnsupportedError("Cannot get the directory for mock packages."); |
31 | 31 |
32 dynamic parseDescription(String filePath, String description, | 32 dynamic parseDescription(String filePath, String description, |
33 {bool fromLockFile: false}) { | 33 {bool fromLockFile: false}) { |
34 if (!description.endsWith(' desc')) throw new FormatException(); | 34 if (!description.endsWith(' desc')) throw new FormatException(); |
35 return description; | 35 return description; |
36 } | 36 } |
37 | 37 |
38 bool descriptionsEqual(description1, description2) => | 38 bool descriptionsEqual(description1, description2) => |
39 description1 == description2; | 39 description1 == description2; |
40 | 40 |
41 String packageName(String description) { | 41 String packageName(String description) { |
42 // Strip off ' desc'. | 42 // Strip off ' desc'. |
43 return description.substring(0, description.length - 5); | 43 return description.substring(0, description.length - 5); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 }); | 197 }); |
198 }); | 198 }); |
199 | 199 |
200 group('serialize()', () { | 200 group('serialize()', () { |
201 var lockfile; | 201 var lockfile; |
202 setUp(() { | 202 setUp(() { |
203 lockfile = new LockFile.empty(); | 203 lockfile = new LockFile.empty(); |
204 }); | 204 }); |
205 | 205 |
206 test('dumps the lockfile to YAML', () { | 206 test('dumps the lockfile to YAML', () { |
207 lockfile.packages['foo'] = new PackageId( | 207 lockfile.packages['foo'] = |
208 'foo', mockSource.name, new Version.parse('1.2.3'), 'foo desc'); | 208 new PackageId('foo', mockSource.name, new Version.parse('1.2.3'), 'f
oo desc'); |
209 lockfile.packages['bar'] = new PackageId( | 209 lockfile.packages['bar'] = |
210 'bar', mockSource.name, new Version.parse('3.2.1'), 'bar desc'); | 210 new PackageId('bar', mockSource.name, new Version.parse('3.2.1'), 'b
ar desc'); |
211 | 211 |
212 expect(loadYaml(lockfile.serialize(null, sources)), equals({ | 212 expect(loadYaml(lockfile.serialize(null, sources)), equals({ |
213 'packages': { | 213 'packages': { |
214 'foo': { | 214 'foo': { |
215 'version': '1.2.3', | 215 'version': '1.2.3', |
216 'source': 'mock', | 216 'source': 'mock', |
217 'description': 'foo desc' | 217 'description': 'foo desc' |
218 }, | 218 }, |
219 'bar': { | 219 'bar': { |
220 'version': '3.2.1', | 220 'version': '3.2.1', |
221 'source': 'mock', | 221 'source': 'mock', |
222 'description': 'bar desc' | 222 'description': 'bar desc' |
223 } | 223 } |
224 } | 224 } |
225 })); | 225 })); |
226 }); | 226 }); |
227 }); | 227 }); |
228 }); | 228 }); |
229 } | 229 } |
OLD | NEW |