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

Side by Side Diff: sdk/lib/_internal/pub_generated/test/lock_file_test.dart

Issue 557563002: Store the async-await compiled pub code directly in the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library lock_file_test; 1 library lock_file_test;
6
7 import 'dart:async'; 2 import 'dart:async';
8
9 import 'package:unittest/unittest.dart'; 3 import 'package:unittest/unittest.dart';
10 import 'package:yaml/yaml.dart'; 4 import 'package:yaml/yaml.dart';
11
12 import '../lib/src/lock_file.dart'; 5 import '../lib/src/lock_file.dart';
13 import '../lib/src/package.dart'; 6 import '../lib/src/package.dart';
14 import '../lib/src/pubspec.dart'; 7 import '../lib/src/pubspec.dart';
15 import '../lib/src/source.dart'; 8 import '../lib/src/source.dart';
16 import '../lib/src/source_registry.dart'; 9 import '../lib/src/source_registry.dart';
17 import '../lib/src/version.dart'; 10 import '../lib/src/version.dart';
18 import 'test_pub.dart'; 11 import 'test_pub.dart';
19
20 class MockSource extends Source { 12 class MockSource extends Source {
21 final String name = 'mock'; 13 final String name = 'mock';
22 14 Future<Pubspec> doDescribe(PackageId id) =>
23 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( 15 throw new UnsupportedError("Cannot describe mock packages.");
24 "Cannot describe mock packages."); 16 Future get(PackageId id, String symlink) =>
25 17 throw new UnsupportedError("Cannot get a mock package.");
26 Future get(PackageId id, String symlink) => throw new UnsupportedError( 18 Future<String> getDirectory(PackageId id) =>
27 "Cannot get a mock package."); 19 throw new UnsupportedError("Cannot get the directory for mock packages.");
28
29 Future<String> getDirectory(PackageId id) => throw new UnsupportedError(
30 "Cannot get the directory for mock packages.");
31
32 dynamic parseDescription(String filePath, String description, 20 dynamic parseDescription(String filePath, String description,
33 {bool fromLockFile: false}) { 21 {bool fromLockFile: false}) {
34 if (!description.endsWith(' desc')) throw new FormatException(); 22 if (!description.endsWith(' desc')) throw new FormatException();
35 return description; 23 return description;
36 } 24 }
37
38 bool descriptionsEqual(description1, description2) => 25 bool descriptionsEqual(description1, description2) =>
39 description1 == description2; 26 description1 == description2;
40
41 String packageName(String description) { 27 String packageName(String description) {
42 // Strip off ' desc'.
43 return description.substring(0, description.length - 5); 28 return description.substring(0, description.length - 5);
44 } 29 }
45 } 30 }
46
47 main() { 31 main() {
48 initConfig(); 32 initConfig();
49
50 var sources = new SourceRegistry(); 33 var sources = new SourceRegistry();
51 var mockSource = new MockSource(); 34 var mockSource = new MockSource();
52 sources.register(mockSource); 35 sources.register(mockSource);
53
54 group('LockFile', () { 36 group('LockFile', () {
55 group('parse()', () { 37 group('parse()', () {
56 test('returns an empty lockfile if the contents are empty', () { 38 test('returns an empty lockfile if the contents are empty', () {
57 var lockFile = new LockFile.parse('', sources); 39 var lockFile = new LockFile.parse('', sources);
58 expect(lockFile.packages.length, equals(0)); 40 expect(lockFile.packages.length, equals(0));
59 }); 41 });
60
61 test('returns an empty lockfile if the contents are whitespace', () { 42 test('returns an empty lockfile if the contents are whitespace', () {
62 var lockFile = new LockFile.parse(' \t\n ', sources); 43 var lockFile = new LockFile.parse(' \t\n ', sources);
63 expect(lockFile.packages.length, equals(0)); 44 expect(lockFile.packages.length, equals(0));
64 }); 45 });
65
66 test('parses a series of package descriptions', () { 46 test('parses a series of package descriptions', () {
67 var lockFile = new LockFile.parse(''' 47 var lockFile = new LockFile.parse('''
68 packages: 48 packages:
69 bar: 49 bar:
70 version: 1.2.3 50 version: 1.2.3
71 source: mock 51 source: mock
72 description: bar desc 52 description: bar desc
73 foo: 53 foo:
74 version: 2.3.4 54 version: 2.3.4
75 source: mock 55 source: mock
76 description: foo desc 56 description: foo desc
77 ''', sources); 57 ''', sources);
78
79 expect(lockFile.packages.length, equals(2)); 58 expect(lockFile.packages.length, equals(2));
80
81 var bar = lockFile.packages['bar']; 59 var bar = lockFile.packages['bar'];
82 expect(bar.name, equals('bar')); 60 expect(bar.name, equals('bar'));
83 expect(bar.version, equals(new Version(1, 2, 3))); 61 expect(bar.version, equals(new Version(1, 2, 3)));
84 expect(bar.source, equals(mockSource.name)); 62 expect(bar.source, equals(mockSource.name));
85 expect(bar.description, equals('bar desc')); 63 expect(bar.description, equals('bar desc'));
86
87 var foo = lockFile.packages['foo']; 64 var foo = lockFile.packages['foo'];
88 expect(foo.name, equals('foo')); 65 expect(foo.name, equals('foo'));
89 expect(foo.version, equals(new Version(2, 3, 4))); 66 expect(foo.version, equals(new Version(2, 3, 4)));
90 expect(foo.source, equals(mockSource.name)); 67 expect(foo.source, equals(mockSource.name));
91 expect(foo.description, equals('foo desc')); 68 expect(foo.description, equals('foo desc'));
92 }); 69 });
93
94 test("allows an unknown source", () { 70 test("allows an unknown source", () {
95 var lockFile = new LockFile.parse(''' 71 var lockFile = new LockFile.parse('''
96 packages: 72 packages:
97 foo: 73 foo:
98 source: bad 74 source: bad
99 version: 1.2.3 75 version: 1.2.3
100 description: foo desc 76 description: foo desc
101 ''', sources); 77 ''', sources);
102 var foo = lockFile.packages['foo']; 78 var foo = lockFile.packages['foo'];
103 expect(foo.source, equals('bad')); 79 expect(foo.source, equals('bad'));
104 }); 80 });
105
106 test("allows an empty dependency map", () { 81 test("allows an empty dependency map", () {
107 var lockFile = new LockFile.parse(''' 82 var lockFile = new LockFile.parse('''
108 packages: 83 packages:
109 ''', sources); 84 ''', sources);
110 expect(lockFile.packages, isEmpty); 85 expect(lockFile.packages, isEmpty);
111 }); 86 });
112
113 test("throws if the top level is not a map", () { 87 test("throws if the top level is not a map", () {
114 expect(() { 88 expect(() {
115 new LockFile.parse(''' 89 new LockFile.parse('''
116 not a map 90 not a map
117 ''', sources); 91 ''', sources);
118 }, throwsFormatException); 92 }, throwsFormatException);
119 }); 93 });
120
121 test("throws if the contents of 'packages' is not a map", () { 94 test("throws if the contents of 'packages' is not a map", () {
122 expect(() { 95 expect(() {
123 new LockFile.parse(''' 96 new LockFile.parse('''
124 packages: not a map 97 packages: not a map
125 ''', sources); 98 ''', sources);
126 }, throwsFormatException); 99 }, throwsFormatException);
127 }); 100 });
128
129 test("throws if the version is missing", () { 101 test("throws if the version is missing", () {
130 expect(() { 102 expect(() {
131 new LockFile.parse(''' 103 new LockFile.parse('''
132 packages: 104 packages:
133 foo: 105 foo:
134 source: mock 106 source: mock
135 description: foo desc 107 description: foo desc
136 ''', sources); 108 ''', sources);
137 }, throwsFormatException); 109 }, throwsFormatException);
138 }); 110 });
139
140 test("throws if the version is invalid", () { 111 test("throws if the version is invalid", () {
141 expect(() { 112 expect(() {
142 new LockFile.parse(''' 113 new LockFile.parse('''
143 packages: 114 packages:
144 foo: 115 foo:
145 version: vorpal 116 version: vorpal
146 source: mock 117 source: mock
147 description: foo desc 118 description: foo desc
148 ''', sources); 119 ''', sources);
149 }, throwsFormatException); 120 }, throwsFormatException);
150 }); 121 });
151
152 test("throws if the source is missing", () { 122 test("throws if the source is missing", () {
153 expect(() { 123 expect(() {
154 new LockFile.parse(''' 124 new LockFile.parse('''
155 packages: 125 packages:
156 foo: 126 foo:
157 version: 1.2.3 127 version: 1.2.3
158 description: foo desc 128 description: foo desc
159 ''', sources); 129 ''', sources);
160 }, throwsFormatException); 130 }, throwsFormatException);
161 }); 131 });
162
163 test("throws if the description is missing", () { 132 test("throws if the description is missing", () {
164 expect(() { 133 expect(() {
165 new LockFile.parse(''' 134 new LockFile.parse('''
166 packages: 135 packages:
167 foo: 136 foo:
168 version: 1.2.3 137 version: 1.2.3
169 source: mock 138 source: mock
170 ''', sources); 139 ''', sources);
171 }, throwsFormatException); 140 }, throwsFormatException);
172 }); 141 });
173
174 test("throws if the description is invalid", () { 142 test("throws if the description is invalid", () {
175 expect(() { 143 expect(() {
176 new LockFile.parse(''' 144 new LockFile.parse('''
177 packages: 145 packages:
178 foo: 146 foo:
179 version: 1.2.3 147 version: 1.2.3
180 source: mock 148 source: mock
181 description: foo desc is bad 149 description: foo desc is bad
182 ''', sources); 150 ''', sources);
183 }, throwsFormatException); 151 }, throwsFormatException);
184 }); 152 });
185
186 test("ignores extra stuff in file", () { 153 test("ignores extra stuff in file", () {
187 var lockFile = new LockFile.parse(''' 154 var lockFile = new LockFile.parse('''
188 extra: 155 extra:
189 some: stuff 156 some: stuff
190 packages: 157 packages:
191 foo: 158 foo:
192 bonus: not used 159 bonus: not used
193 version: 1.2.3 160 version: 1.2.3
194 source: mock 161 source: mock
195 description: foo desc 162 description: foo desc
196 ''', sources); 163 ''', sources);
197 }); 164 });
198 }); 165 });
199
200 group('serialize()', () { 166 group('serialize()', () {
201 var lockfile; 167 var lockfile;
202 setUp(() { 168 setUp(() {
203 lockfile = new LockFile.empty(); 169 lockfile = new LockFile.empty();
204 }); 170 });
205
206 test('dumps the lockfile to YAML', () { 171 test('dumps the lockfile to YAML', () {
207 lockfile.packages['foo'] = new PackageId( 172 lockfile.packages['foo'] =
208 'foo', mockSource.name, new Version.parse('1.2.3'), 'foo desc'); 173 new PackageId('foo', mockSource.name, new Version.parse('1.2.3'), 'f oo desc');
209 lockfile.packages['bar'] = new PackageId( 174 lockfile.packages['bar'] =
210 'bar', mockSource.name, new Version.parse('3.2.1'), 'bar desc'); 175 new PackageId('bar', mockSource.name, new Version.parse('3.2.1'), 'b ar desc');
211
212 expect(loadYaml(lockfile.serialize(null, sources)), equals({ 176 expect(loadYaml(lockfile.serialize(null, sources)), equals({
213 'packages': { 177 'packages': {
214 'foo': { 178 'foo': {
215 'version': '1.2.3', 179 'version': '1.2.3',
216 'source': 'mock', 180 'source': 'mock',
217 'description': 'foo desc' 181 'description': 'foo desc'
218 }, 182 },
219 'bar': { 183 'bar': {
220 'version': '3.2.1', 184 'version': '3.2.1',
221 'source': 'mock', 185 'source': 'mock',
222 'description': 'bar desc' 186 'description': 'bar desc'
223 } 187 }
224 } 188 }
225 })); 189 }));
226 }); 190 });
227 }); 191 });
228 }); 192 });
229 } 193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698