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 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'; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 expect(foo.source, equals(sources['bad'])); | 95 expect(foo.source, equals(sources['bad'])); |
96 }); | 96 }); |
97 | 97 |
98 test("allows an empty dependency map", () { | 98 test("allows an empty dependency map", () { |
99 var lockFile = new LockFile.parse(''' | 99 var lockFile = new LockFile.parse(''' |
100 packages: | 100 packages: |
101 ''', sources); | 101 ''', sources); |
102 expect(lockFile.packages, isEmpty); | 102 expect(lockFile.packages, isEmpty); |
103 }); | 103 }); |
104 | 104 |
| 105 test("allows an old-style SDK constraint", () { |
| 106 var lockFile = new LockFile.parse('sdk: ">=1.2.3 <4.0.0"', sources); |
| 107 expect(lockFile.dartSdkConstraint, |
| 108 equals(new VersionConstraint.parse('>=1.2.3 <4.0.0'))); |
| 109 expect(lockFile.flutterSdkConstraint, isNull); |
| 110 }); |
| 111 |
| 112 test("allows new-style SDK constraints", () { |
| 113 var lockFile = new LockFile.parse(''' |
| 114 sdks: |
| 115 dart: ">=1.2.3 <4.0.0" |
| 116 flutter: ^0.1.2 |
| 117 ''', sources); |
| 118 expect(lockFile.dartSdkConstraint, |
| 119 equals(new VersionConstraint.parse('>=1.2.3 <4.0.0'))); |
| 120 expect(lockFile.flutterSdkConstraint, |
| 121 equals(new VersionConstraint.parse('^0.1.2'))); |
| 122 }); |
| 123 |
105 test("throws if the top level is not a map", () { | 124 test("throws if the top level is not a map", () { |
106 expect(() { | 125 expect(() { |
107 new LockFile.parse(''' | 126 new LockFile.parse(''' |
108 not a map | 127 not a map |
109 ''', sources); | 128 ''', sources); |
110 }, throwsFormatException); | 129 }, throwsFormatException); |
111 }); | 130 }); |
112 | 131 |
113 test("throws if the contents of 'packages' is not a map", () { | 132 test("throws if the contents of 'packages' is not a map", () { |
114 expect(() { | 133 expect(() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 new LockFile.parse(''' | 187 new LockFile.parse(''' |
169 packages: | 188 packages: |
170 foo: | 189 foo: |
171 version: 1.2.3 | 190 version: 1.2.3 |
172 source: mock | 191 source: mock |
173 description: foo desc is bad | 192 description: foo desc is bad |
174 ''', sources); | 193 ''', sources); |
175 }, throwsFormatException); | 194 }, throwsFormatException); |
176 }); | 195 }); |
177 | 196 |
| 197 test("throws if the old-style SDK constraint isn't a string", () { |
| 198 expect(() => new LockFile.parse('sdk: 1.0', sources), |
| 199 throwsFormatException); |
| 200 }); |
| 201 |
| 202 test("throws if the old-style SDK constraint is invalid", () { |
| 203 expect(() => new LockFile.parse('sdk: oops', sources), |
| 204 throwsFormatException); |
| 205 }); |
| 206 |
| 207 test("throws if the sdks field isn't a map", () { |
| 208 expect(() => new LockFile.parse('sdks: oops', sources), |
| 209 throwsFormatException); |
| 210 }); |
| 211 |
| 212 test("throws if an sdk constraint isn't a string", () { |
| 213 expect(() => new LockFile.parse('sdks: {dart: 1.0}', sources), |
| 214 throwsFormatException); |
| 215 expect(() { |
| 216 new LockFile.parse('sdks: {dart: 1.0.0, flutter: 1.0}', sources); |
| 217 }, throwsFormatException); |
| 218 }); |
| 219 |
| 220 test("throws if an sdk constraint is invalid", () { |
| 221 expect(() => new LockFile.parse('sdks: {dart: oops}', sources), |
| 222 throwsFormatException); |
| 223 expect(() { |
| 224 new LockFile.parse('sdks: {dart: 1.0.0, flutter: oops}', sources); |
| 225 }, throwsFormatException); |
| 226 }); |
| 227 |
178 test("ignores extra stuff in file", () { | 228 test("ignores extra stuff in file", () { |
179 new LockFile.parse(''' | 229 new LockFile.parse(''' |
180 extra: | 230 extra: |
181 some: stuff | 231 some: stuff |
182 packages: | 232 packages: |
183 foo: | 233 foo: |
184 bonus: not used | 234 bonus: not used |
185 version: 1.2.3 | 235 version: 1.2.3 |
186 source: mock | 236 source: mock |
187 description: foo desc | 237 description: foo desc |
188 ''', sources); | 238 ''', sources); |
189 }); | 239 }); |
190 }); | 240 }); |
191 | 241 |
192 test('serialize() dumps the lockfile to YAML', () { | 242 test('serialize() dumps the lockfile to YAML', () { |
193 var lockfile = new LockFile([ | 243 var lockfile = new LockFile([ |
194 new PackageId( | 244 new PackageId( |
195 'foo', mockSource, new Version.parse('1.2.3'), 'foo desc'), | 245 'foo', mockSource, new Version.parse('1.2.3'), 'foo desc'), |
196 new PackageId('bar', mockSource, new Version.parse('3.2.1'), 'bar desc') | 246 new PackageId('bar', mockSource, new Version.parse('3.2.1'), 'bar desc') |
197 ]); | 247 ]); |
198 | 248 |
199 expect(loadYaml(lockfile.serialize(null)), equals({ | 249 expect(loadYaml(lockfile.serialize(null)), equals({ |
200 'sdk': 'any', | 250 'sdks': {'dart': 'any'}, |
201 'packages': { | 251 'packages': { |
202 'foo': { | 252 'foo': { |
203 'version': '1.2.3', | 253 'version': '1.2.3', |
204 'source': 'mock', | 254 'source': 'mock', |
205 'description': 'foo desc' | 255 'description': 'foo desc' |
206 }, | 256 }, |
207 'bar': { | 257 'bar': { |
208 'version': '3.2.1', | 258 'version': '3.2.1', |
209 'source': 'mock', | 259 'source': 'mock', |
210 'description': 'bar desc' | 260 'description': 'bar desc' |
211 } | 261 } |
212 } | 262 } |
213 })); | 263 })); |
214 }); | 264 }); |
215 }); | 265 }); |
216 } | 266 } |
OLD | NEW |