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 pubspec_test; | 5 library pubspec_test; |
6 | 6 |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 | 8 |
9 import '../lib/src/pubspec.dart'; | 9 import '../lib/src/pubspec.dart'; |
10 import '../lib/src/source.dart'; | 10 import '../lib/src/source.dart'; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 (pubspec) => pubspec.transformers, | 234 (pubspec) => pubspec.transformers, |
235 '"transformers" field must be a string or map'); | 235 '"transformers" field must be a string or map'); |
236 }); | 236 }); |
237 | 237 |
238 test("throws if a transformer's configuration isn't a map", () { | 238 test("throws if a transformer's configuration isn't a map", () { |
239 expectPubspecException('transformers: [{pkg: 12}]', | 239 expectPubspecException('transformers: [{pkg: 12}]', |
240 (pubspec) => pubspec.transformers, | 240 (pubspec) => pubspec.transformers, |
241 '"transformers.pkg" field must be a map'); | 241 '"transformers.pkg" field must be a map'); |
242 }); | 242 }); |
243 | 243 |
244 test("throws if a transformer's configuration contains a top-level key " | 244 test("throws if a transformer's configuration contains an unknown " |
245 "beginning with a dollar sign", () { | 245 "reserved key at the top level", () { |
246 expectPubspecException(''' | 246 expectPubspecException(''' |
247 name: pkg | 247 name: pkg |
248 transformers: [{pkg: {\$key: "value"}}]''', | 248 transformers: [{pkg: {\$key: "value"}}]''', |
249 (pubspec) => pubspec.transformers, | 249 (pubspec) => pubspec.transformers, |
250 '"transformers.pkg" field cannot contain reserved field "\$key"'); | 250 'Invalid transformer configuration for "transformers.pkg": ' |
| 251 'Unknown reserved field "\$key"'); |
251 }); | 252 }); |
252 | 253 |
253 test("doesn't throw if a transformer's configuration contains a " | 254 test("doesn't throw if a transformer's configuration contains a " |
254 "non-top-level key beginning with a dollar sign", () { | 255 "non-top-level key beginning with a dollar sign", () { |
255 var pubspec = new Pubspec.parse(''' | 256 var pubspec = new Pubspec.parse(''' |
256 name: pkg | 257 name: pkg |
257 transformers: | 258 transformers: |
258 - pkg: {outer: {\$inner: value}} | 259 - pkg: {outer: {\$inner: value}} |
259 ''', sources); | 260 ''', sources); |
260 | 261 |
261 var pkg = pubspec.transformers[0].single; | 262 var pkg = pubspec.transformers[0].single; |
262 expect(pkg.configuration["outer"]["\$inner"], equals("value")); | 263 expect(pkg.configuration["outer"]["\$inner"], equals("value")); |
263 }); | 264 }); |
264 | 265 |
| 266 test("throws if the \$include value is not a string or list", () { |
| 267 expectPubspecException(''' |
| 268 name: pkg |
| 269 transformers: |
| 270 - pkg: {\$include: 123}''', |
| 271 (pubspec) => pubspec.transformers, |
| 272 'Invalid transformer configuration for "transformers.pkg": ' |
| 273 '"\$include" field must be a string or list, but was "123"'); |
| 274 }); |
| 275 |
| 276 test("throws if the \$include list contains a non-string", () { |
| 277 expectPubspecException(''' |
| 278 name: pkg |
| 279 transformers: |
| 280 - pkg: {\$include: ["ok", 123, "alright", null]}''', |
| 281 (pubspec) => pubspec.transformers, |
| 282 'Invalid transformer configuration for "transformers.pkg": ' |
| 283 '"\$include" list field may only contain strings, but contained ' |
| 284 '"123" and "null"'); |
| 285 }); |
| 286 |
| 287 test("throws if the \$exclude value is not a string or list", () { |
| 288 expectPubspecException(''' |
| 289 name: pkg |
| 290 transformers: |
| 291 - pkg: {\$exclude: 123}''', |
| 292 (pubspec) => pubspec.transformers, |
| 293 'Invalid transformer configuration for "transformers.pkg": ' |
| 294 '"\$exclude" field must be a string or list, but was "123"'); |
| 295 }); |
| 296 |
| 297 test("throws if the \$exclude list contains a non-string", () { |
| 298 expectPubspecException(''' |
| 299 name: pkg |
| 300 transformers: |
| 301 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', |
| 302 (pubspec) => pubspec.transformers, |
| 303 'Invalid transformer configuration for "transformers.pkg": ' |
| 304 '"\$exclude" list field may only contain strings, but contained ' |
| 305 '"123" and "null"'); |
| 306 }); |
| 307 |
265 test("throws if a transformer is not from a dependency", () { | 308 test("throws if a transformer is not from a dependency", () { |
266 expectPubspecException(''' | 309 expectPubspecException(''' |
267 name: pkg | 310 name: pkg |
268 transformers: [foo] | 311 transformers: [foo] |
269 ''', | 312 ''', |
270 (pubspec) => pubspec.transformers, | 313 (pubspec) => pubspec.transformers, |
271 '"transformers.foo" refers to a package that\'s not a dependency.'); | 314 '"transformers.foo" refers to a package that\'s not a dependency.'); |
272 }); | 315 }); |
273 | 316 |
274 test("allows a transformer from a normal dependency", () { | 317 test("allows a transformer from a normal dependency", () { |
275 var pubspec = new Pubspec.parse(''' | 318 var pubspec = new Pubspec.parse(''' |
276 name: pkg | 319 name: pkg |
277 dependencies: | 320 dependencies: |
278 foo: | 321 foo: |
279 mock: ok | 322 mock: ok |
280 transformers: | 323 transformers: |
281 - foo''', sources); | 324 - foo''', sources); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 (pubspec) => pubspec.environment); | 395 (pubspec) => pubspec.environment); |
353 }); | 396 }); |
354 | 397 |
355 test("throws if the sdk isn't a valid version constraint", () { | 398 test("throws if the sdk isn't a valid version constraint", () { |
356 expectPubspecException('environment: {sdk: "oopies"}', | 399 expectPubspecException('environment: {sdk: "oopies"}', |
357 (pubspec) => pubspec.environment); | 400 (pubspec) => pubspec.environment); |
358 }); | 401 }); |
359 }); | 402 }); |
360 }); | 403 }); |
361 } | 404 } |
OLD | NEW |