Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: test/lock_file_test.dart

Issue 2079303003: Track Source objects in PackageNames. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/validator/dependency.dart ('k') | test/pubspec_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'package:pub/src/lock_file.dart'; 5 import 'package:pub/src/lock_file.dart';
6 import 'package:pub/src/package.dart'; 6 import 'package:pub/src/package.dart';
7 import 'package:pub/src/source.dart'; 7 import 'package:pub/src/source.dart';
8 import 'package:pub/src/source_registry.dart'; 8 import 'package:pub/src/source_registry.dart';
9 import 'package:pub/src/system_cache.dart'; 9 import 'package:pub/src/system_cache.dart';
10 import 'package:pub_semver/pub_semver.dart'; 10 import 'package:pub_semver/pub_semver.dart';
11 import 'package:test/test.dart'; 11 import 'package:test/test.dart';
12 import 'package:yaml/yaml.dart'; 12 import 'package:yaml/yaml.dart';
13 13
14 class MockSource extends Source { 14 class MockSource extends Source {
15 final String name = 'mock'; 15 final String name = 'mock';
16 16
17 BoundSource bind(SystemCache cache) => 17 BoundSource bind(SystemCache cache) =>
18 throw new UnsupportedError("Cannot download mock packages."); 18 throw new UnsupportedError("Cannot download mock packages.");
19 19
20 PackageRef parseRef(String name, description, {String containingPath}) { 20 PackageRef parseRef(String name, description, {String containingPath}) {
21 if (!description.endsWith(' desc')) throw new FormatException('Bad'); 21 if (!description.endsWith(' desc')) throw new FormatException('Bad');
22 return new PackageRef(name, this.name, description); 22 return new PackageRef(name, this, description);
23 } 23 }
24 24
25 PackageId parseId(String name, Version version, description) { 25 PackageId parseId(String name, Version version, description) {
26 if (!description.endsWith(' desc')) throw new FormatException('Bad'); 26 if (!description.endsWith(' desc')) throw new FormatException('Bad');
27 return new PackageId(name, this.name, version, description); 27 return new PackageId(name, this, version, description);
28 } 28 }
29 29
30 bool descriptionsEqual(description1, description2) => 30 bool descriptionsEqual(description1, description2) =>
31 description1 == description2; 31 description1 == description2;
32 32
33 int hashDescription(description) => description.hashCode;
34
33 String packageName(String description) { 35 String packageName(String description) {
34 // Strip off ' desc'. 36 // Strip off ' desc'.
35 return description.substring(0, description.length - 5); 37 return description.substring(0, description.length - 5);
36 } 38 }
37 } 39 }
38 40
39 main() { 41 main() {
40 var sources = new SourceRegistry(); 42 var sources = new SourceRegistry();
41 var mockSource = new MockSource(); 43 var mockSource = new MockSource();
42 sources.register(mockSource); 44 sources.register(mockSource);
(...skipping 21 matching lines...) Expand all
64 version: 2.3.4 66 version: 2.3.4
65 source: mock 67 source: mock
66 description: foo desc 68 description: foo desc
67 ''', sources); 69 ''', sources);
68 70
69 expect(lockFile.packages.length, equals(2)); 71 expect(lockFile.packages.length, equals(2));
70 72
71 var bar = lockFile.packages['bar']; 73 var bar = lockFile.packages['bar'];
72 expect(bar.name, equals('bar')); 74 expect(bar.name, equals('bar'));
73 expect(bar.version, equals(new Version(1, 2, 3))); 75 expect(bar.version, equals(new Version(1, 2, 3)));
74 expect(bar.source, equals(mockSource.name)); 76 expect(bar.source, equals(mockSource));
75 expect(bar.description, equals('bar desc')); 77 expect(bar.description, equals('bar desc'));
76 78
77 var foo = lockFile.packages['foo']; 79 var foo = lockFile.packages['foo'];
78 expect(foo.name, equals('foo')); 80 expect(foo.name, equals('foo'));
79 expect(foo.version, equals(new Version(2, 3, 4))); 81 expect(foo.version, equals(new Version(2, 3, 4)));
80 expect(foo.source, equals(mockSource.name)); 82 expect(foo.source, equals(mockSource));
81 expect(foo.description, equals('foo desc')); 83 expect(foo.description, equals('foo desc'));
82 }); 84 });
83 85
84 test("allows an unknown source", () { 86 test("allows an unknown source", () {
85 var lockFile = new LockFile.parse(''' 87 var lockFile = new LockFile.parse('''
86 packages: 88 packages:
87 foo: 89 foo:
88 source: bad 90 source: bad
89 version: 1.2.3 91 version: 1.2.3
90 description: foo desc 92 description: foo desc
91 ''', sources); 93 ''', sources);
92 var foo = lockFile.packages['foo']; 94 var foo = lockFile.packages['foo'];
93 expect(foo.source, equals('bad')); 95 expect(foo.source, equals(sources['bad']));
94 }); 96 });
95 97
96 test("allows an empty dependency map", () { 98 test("allows an empty dependency map", () {
97 var lockFile = new LockFile.parse(''' 99 var lockFile = new LockFile.parse('''
98 packages: 100 packages:
99 ''', sources); 101 ''', sources);
100 expect(lockFile.packages, isEmpty); 102 expect(lockFile.packages, isEmpty);
101 }); 103 });
102 104
103 test("throws if the top level is not a map", () { 105 test("throws if the top level is not a map", () {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 version: 1.2.3 185 version: 1.2.3
184 source: mock 186 source: mock
185 description: foo desc 187 description: foo desc
186 ''', sources); 188 ''', sources);
187 }); 189 });
188 }); 190 });
189 191
190 test('serialize() dumps the lockfile to YAML', () { 192 test('serialize() dumps the lockfile to YAML', () {
191 var lockfile = new LockFile([ 193 var lockfile = new LockFile([
192 new PackageId( 194 new PackageId(
193 'foo', mockSource.name, new Version.parse('1.2.3'), 'foo desc'), 195 'foo', mockSource, new Version.parse('1.2.3'), 'foo desc'),
194 new PackageId( 196 new PackageId('bar', mockSource, new Version.parse('3.2.1'), 'bar desc')
195 'bar', mockSource.name, new Version.parse('3.2.1'), 'bar desc') 197 ]);
196 ], sources);
197 198
198 expect(loadYaml(lockfile.serialize(null)), equals({ 199 expect(loadYaml(lockfile.serialize(null)), equals({
199 'sdk': 'any', 200 'sdk': 'any',
200 'packages': { 201 'packages': {
201 'foo': { 202 'foo': {
202 'version': '1.2.3', 203 'version': '1.2.3',
203 'source': 'mock', 204 'source': 'mock',
204 'description': 'foo desc' 205 'description': 'foo desc'
205 }, 206 },
206 'bar': { 207 'bar': {
207 'version': '3.2.1', 208 'version': '3.2.1',
208 'source': 'mock', 209 'source': 'mock',
209 'description': 'bar desc' 210 'description': 'bar desc'
210 } 211 }
211 } 212 }
212 })); 213 }));
213 }); 214 });
214 }); 215 });
215 } 216 }
OLDNEW
« no previous file with comments | « lib/src/validator/dependency.dart ('k') | test/pubspec_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698