| 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 '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 | 11 |
| 12 import '../lib/src/package.dart'; | 12 import '../lib/src/package.dart'; |
| 13 import '../lib/src/pubspec.dart'; | 13 import '../lib/src/pubspec.dart'; |
| 14 import '../lib/src/source.dart'; | 14 import '../lib/src/source.dart'; |
| 15 import '../lib/src/source/path.dart'; | 15 import '../lib/src/source/path.dart'; |
| 16 import '../lib/src/source_registry.dart'; | 16 import '../lib/src/source_registry.dart'; |
| 17 import 'test_pub.dart'; | 17 import 'test_pub.dart'; |
| 18 | 18 |
| 19 class MockSource extends Source { | 19 class MockSource extends Source { |
| 20 final String name = "mock"; | 20 final String name = "mock"; |
| 21 | 21 |
| 22 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( | 22 Future<Pubspec> doDescribe(PackageId id) => |
| 23 "Cannot describe mock packages."); | 23 throw new UnsupportedError("Cannot describe mock packages."); |
| 24 | 24 |
| 25 Future get(PackageId id, String symlink) => throw new UnsupportedError( | 25 Future get(PackageId id, String symlink) => |
| 26 "Cannot get a mock package."); | 26 throw new UnsupportedError("Cannot get a mock package."); |
| 27 | 27 |
| 28 Future<String> getDirectory(PackageId id) => throw new UnsupportedError( | 28 Future<String> getDirectory(PackageId id) => |
| 29 "Cannot get the directory for mock packages."); | 29 throw new UnsupportedError("Cannot get the directory for mock packages."); |
| 30 | 30 |
| 31 dynamic parseDescription(String filePath, description, | 31 dynamic parseDescription(String filePath, description, {bool fromLockFile: |
| 32 {bool fromLockFile: false}) { | 32 false}) { |
| 33 if (description != 'ok') throw new FormatException('Bad'); | 33 if (description != 'ok') throw new FormatException('Bad'); |
| 34 return description; | 34 return description; |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool descriptionsEqual(description1, description2) => | 37 bool descriptionsEqual(description1, description2) => |
| 38 description1 == description2; | 38 description1 == description2; |
| 39 | 39 |
| 40 String packageName(description) => 'foo'; | 40 String packageName(description) => 'foo'; |
| 41 } | 41 } |
| 42 | 42 |
| 43 main() { | 43 main() { |
| 44 initConfig(); | 44 initConfig(); |
| 45 group('parse()', () { | 45 group('parse()', () { |
| 46 var sources = new SourceRegistry(); | 46 var sources = new SourceRegistry(); |
| 47 sources.register(new MockSource()); | 47 sources.register(new MockSource()); |
| 48 sources.register(new PathSource()); | 48 sources.register(new PathSource()); |
| 49 | 49 |
| 50 var throwsPubspecException = | 50 var throwsPubspecException = |
| 51 throwsA(new isInstanceOf<PubspecException>('PubspecException')); | 51 throwsA(new isInstanceOf<PubspecException>('PubspecException')); |
| 52 | 52 |
| 53 expectPubspecException(String contents, fn(Pubspec pubspec), | 53 expectPubspecException(String contents, fn(Pubspec pubspec), |
| 54 [String expectedContains]) { | 54 [String expectedContains]) { |
| 55 var expectation = throwsPubspecException; | 55 var expectation = throwsPubspecException; |
| 56 if (expectedContains != null) { | 56 if (expectedContains != null) { |
| 57 expectation = throwsA(allOf( | 57 expectation = throwsA( |
| 58 new isInstanceOf<PubspecException>('PubspecException'), | 58 allOf( |
| 59 predicate((error) => error.message.contains(expectedContains)))); | 59 new isInstanceOf<PubspecException>('PubspecException'), |
| 60 predicate((error) => error.message.contains(expectedContains))))
; |
| 60 } | 61 } |
| 61 | 62 |
| 62 var pubspec = new Pubspec.parse(contents, sources); | 63 var pubspec = new Pubspec.parse(contents, sources); |
| 63 expect(() => fn(pubspec), expectation); | 64 expect(() => fn(pubspec), expectation); |
| 64 } | 65 } |
| 65 | 66 |
| 66 test("doesn't eagerly throw an error for an invalid field", () { | 67 test("doesn't eagerly throw an error for an invalid field", () { |
| 67 // Shouldn't throw an error. | 68 // Shouldn't throw an error. |
| 68 new Pubspec.parse('version: not a semver', sources); | 69 new Pubspec.parse('version: not a semver', sources); |
| 69 }); | 70 }); |
| 70 | 71 |
| 71 test("eagerly throws an error if the pubspec name doesn't match the " | 72 test( |
| 72 "expected name", () { | 73 "eagerly throws an error if the pubspec name doesn't match the " |
| 73 expect(() => new Pubspec.parse("name: foo", sources, expectedName: 'bar'), | 74 "expected name", |
| 75 () { |
| 76 expect( |
| 77 () => new Pubspec.parse("name: foo", sources, expectedName: 'bar'), |
| 74 throwsPubspecException); | 78 throwsPubspecException); |
| 75 }); | 79 }); |
| 76 | 80 |
| 77 test("eagerly throws an error if the pubspec doesn't have a name and an " | 81 test( |
| 78 "expected name is passed", () { | 82 "eagerly throws an error if the pubspec doesn't have a name and an " |
| 79 expect(() => new Pubspec.parse("{}", sources, expectedName: 'bar'), | 83 "expected name is passed", |
| 84 () { |
| 85 expect( |
| 86 () => new Pubspec.parse("{}", sources, expectedName: 'bar'), |
| 80 throwsPubspecException); | 87 throwsPubspecException); |
| 81 }); | 88 }); |
| 82 | 89 |
| 83 test("allows a version constraint for dependencies", () { | 90 test("allows a version constraint for dependencies", () { |
| 84 var pubspec = new Pubspec.parse(''' | 91 var pubspec = new Pubspec.parse(''' |
| 85 dependencies: | 92 dependencies: |
| 86 foo: | 93 foo: |
| 87 mock: ok | 94 mock: ok |
| 88 version: ">=1.2.3 <3.4.5" | 95 version: ">=1.2.3 <3.4.5" |
| 89 ''', sources); | 96 ''', sources); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 test("throws if version is not a version constraint", () { | 231 test("throws if version is not a version constraint", () { |
| 225 expectPubspecException(''' | 232 expectPubspecException(''' |
| 226 dependencies: | 233 dependencies: |
| 227 foo: | 234 foo: |
| 228 mock: ok | 235 mock: ok |
| 229 version: not constraint | 236 version: not constraint |
| 230 ''', (pubspec) => pubspec.dependencies); | 237 ''', (pubspec) => pubspec.dependencies); |
| 231 }); | 238 }); |
| 232 | 239 |
| 233 test("throws if 'name' is not a string", () { | 240 test("throws if 'name' is not a string", () { |
| 234 expectPubspecException('name: [not, a, string]', | 241 expectPubspecException( |
| 242 'name: [not, a, string]', |
| 235 (pubspec) => pubspec.name); | 243 (pubspec) => pubspec.name); |
| 236 }); | 244 }); |
| 237 | 245 |
| 238 test("throws if version is not a string", () { | 246 test("throws if version is not a string", () { |
| 239 expectPubspecException('version: [2, 0, 0]', | 247 expectPubspecException( |
| 248 'version: [2, 0, 0]', |
| 240 (pubspec) => pubspec.version, | 249 (pubspec) => pubspec.version, |
| 241 '"version" field must be a string'); | 250 '"version" field must be a string'); |
| 242 }); | 251 }); |
| 243 | 252 |
| 244 test("throws if version is malformed (looking like a double)", () { | 253 test("throws if version is malformed (looking like a double)", () { |
| 245 expectPubspecException('version: 2.1', | 254 expectPubspecException( |
| 255 'version: 2.1', |
| 246 (pubspec) => pubspec.version, | 256 (pubspec) => pubspec.version, |
| 247 '"version" field must have three numeric components: major, minor, ' | 257 '"version" field must have three numeric components: major, minor, ' |
| 248 'and patch. Instead of "2.1", consider "2.1.0"'); | 258 'and patch. Instead of "2.1", consider "2.1.0"'); |
| 249 }); | 259 }); |
| 250 | 260 |
| 251 test("throws if version is malformed (looking like an int)", () { | 261 test("throws if version is malformed (looking like an int)", () { |
| 252 expectPubspecException('version: 2', | 262 expectPubspecException( |
| 263 'version: 2', |
| 253 (pubspec) => pubspec.version, | 264 (pubspec) => pubspec.version, |
| 254 '"version" field must have three numeric components: major, minor, ' | 265 '"version" field must have three numeric components: major, minor, ' |
| 255 'and patch. Instead of "2", consider "2.0.0"'); | 266 'and patch. Instead of "2", consider "2.0.0"'); |
| 256 }); | 267 }); |
| 257 | 268 |
| 258 test("throws if version is not a version", () { | 269 test("throws if version is not a version", () { |
| 259 expectPubspecException('version: not version', | 270 expectPubspecException( |
| 271 'version: not version', |
| 260 (pubspec) => pubspec.version); | 272 (pubspec) => pubspec.version); |
| 261 }); | 273 }); |
| 262 | 274 |
| 263 test("throws if transformers isn't a list", () { | 275 test("throws if transformers isn't a list", () { |
| 264 expectPubspecException('transformers: "not list"', | 276 expectPubspecException( |
| 277 'transformers: "not list"', |
| 265 (pubspec) => pubspec.transformers, | 278 (pubspec) => pubspec.transformers, |
| 266 '"transformers" field must be a list'); | 279 '"transformers" field must be a list'); |
| 267 }); | 280 }); |
| 268 | 281 |
| 269 test("throws if a transformer isn't a string or map", () { | 282 test("throws if a transformer isn't a string or map", () { |
| 270 expectPubspecException('transformers: [12]', | 283 expectPubspecException( |
| 284 'transformers: [12]', |
| 271 (pubspec) => pubspec.transformers, | 285 (pubspec) => pubspec.transformers, |
| 272 'A transformer must be a string or map.'); | 286 'A transformer must be a string or map.'); |
| 273 }); | 287 }); |
| 274 | 288 |
| 275 test("throws if a transformer's configuration isn't a map", () { | 289 test("throws if a transformer's configuration isn't a map", () { |
| 276 expectPubspecException('transformers: [{pkg: 12}]', | 290 expectPubspecException( |
| 291 'transformers: [{pkg: 12}]', |
| 277 (pubspec) => pubspec.transformers, | 292 (pubspec) => pubspec.transformers, |
| 278 "A transformer's configuration must be a map."); | 293 "A transformer's configuration must be a map."); |
| 279 }); | 294 }); |
| 280 | 295 |
| 281 test("throws if a transformer's configuration contains an unknown " | 296 test( |
| 282 "reserved key at the top level", () { | 297 "throws if a transformer's configuration contains an unknown " |
| 298 "reserved key at the top level", |
| 299 () { |
| 283 expectPubspecException(''' | 300 expectPubspecException(''' |
| 284 name: pkg | 301 name: pkg |
| 285 transformers: [{pkg: {\$key: "value"}}]''', | 302 transformers: [{pkg: {\$key: "value"}}]''', |
| 286 (pubspec) => pubspec.transformers, | 303 (pubspec) => pubspec.transformers, |
| 287 'Invalid transformer config: Unknown reserved field.'); | 304 'Invalid transformer config: Unknown reserved field.'); |
| 288 }); | 305 }); |
| 289 | 306 |
| 290 test("doesn't throw if a transformer's configuration contains a " | 307 test( |
| 291 "non-top-level key beginning with a dollar sign", () { | 308 "doesn't throw if a transformer's configuration contains a " |
| 309 "non-top-level key beginning with a dollar sign", |
| 310 () { |
| 292 var pubspec = new Pubspec.parse(''' | 311 var pubspec = new Pubspec.parse(''' |
| 293 name: pkg | 312 name: pkg |
| 294 transformers: | 313 transformers: |
| 295 - pkg: {outer: {\$inner: value}} | 314 - pkg: {outer: {\$inner: value}} |
| 296 ''', sources); | 315 ''', sources); |
| 297 | 316 |
| 298 var pkg = pubspec.transformers[0].single; | 317 var pkg = pubspec.transformers[0].single; |
| 299 expect(pkg.configuration["outer"]["\$inner"], equals("value")); | 318 expect(pkg.configuration["outer"]["\$inner"], equals("value")); |
| 300 }); | 319 }); |
| 301 | 320 |
| 302 test("throws if the \$include value is not a string or list", () { | 321 test("throws if the \$include value is not a string or list", () { |
| 303 expectPubspecException(''' | 322 expectPubspecException(''' |
| 304 name: pkg | 323 name: pkg |
| 305 transformers: | 324 transformers: |
| 306 - pkg: {\$include: 123}''', | 325 - pkg: {\$include: 123}''', |
| 307 (pubspec) => pubspec.transformers, | 326 (pubspec) => pubspec.transformers, |
| 308 'Invalid transformer config: "\$include" field must be a string or ' | 327 'Invalid transformer config: "\$include" field must be a string or ' '
list.'); |
| 309 'list.'); | |
| 310 }); | 328 }); |
| 311 | 329 |
| 312 test("throws if the \$include list contains a non-string", () { | 330 test("throws if the \$include list contains a non-string", () { |
| 313 expectPubspecException(''' | 331 expectPubspecException(''' |
| 314 name: pkg | 332 name: pkg |
| 315 transformers: | 333 transformers: |
| 316 - pkg: {\$include: ["ok", 123, "alright", null]}''', | 334 - pkg: {\$include: ["ok", 123, "alright", null]}''', |
| 317 (pubspec) => pubspec.transformers, | 335 (pubspec) => pubspec.transformers, |
| 318 'Invalid transformer config: "\$include" field may contain only ' | 336 'Invalid transformer config: "\$include" field may contain only ' 'str
ings.'); |
| 319 'strings.'); | |
| 320 }); | 337 }); |
| 321 | 338 |
| 322 test("throws if the \$exclude value is not a string or list", () { | 339 test("throws if the \$exclude value is not a string or list", () { |
| 323 expectPubspecException(''' | 340 expectPubspecException(''' |
| 324 name: pkg | 341 name: pkg |
| 325 transformers: | 342 transformers: |
| 326 - pkg: {\$exclude: 123}''', | 343 - pkg: {\$exclude: 123}''', |
| 327 (pubspec) => pubspec.transformers, | 344 (pubspec) => pubspec.transformers, |
| 328 'Invalid transformer config: "\$exclude" field must be a string or ' | 345 'Invalid transformer config: "\$exclude" field must be a string or ' '
list.'); |
| 329 'list.'); | |
| 330 }); | 346 }); |
| 331 | 347 |
| 332 test("throws if the \$exclude list contains a non-string", () { | 348 test("throws if the \$exclude list contains a non-string", () { |
| 333 expectPubspecException(''' | 349 expectPubspecException(''' |
| 334 name: pkg | 350 name: pkg |
| 335 transformers: | 351 transformers: |
| 336 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', | 352 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', |
| 337 (pubspec) => pubspec.transformers, | 353 (pubspec) => pubspec.transformers, |
| 338 'Invalid transformer config: "\$exclude" field may contain only ' | 354 'Invalid transformer config: "\$exclude" field may contain only ' 'str
ings.'); |
| 339 'strings.'); | |
| 340 }); | 355 }); |
| 341 | 356 |
| 342 test("throws if a transformer is not from a dependency", () { | 357 test("throws if a transformer is not from a dependency", () { |
| 343 expectPubspecException(''' | 358 expectPubspecException(''' |
| 344 name: pkg | 359 name: pkg |
| 345 transformers: [foo] | 360 transformers: [foo] |
| 346 ''', | 361 ''', (pubspec) => pubspec.transformers, '"foo" is not a dependency.'); |
| 347 (pubspec) => pubspec.transformers, | |
| 348 '"foo" is not a dependency.'); | |
| 349 }); | 362 }); |
| 350 | 363 |
| 351 test("allows a transformer from a normal dependency", () { | 364 test("allows a transformer from a normal dependency", () { |
| 352 var pubspec = new Pubspec.parse(''' | 365 var pubspec = new Pubspec.parse(''' |
| 353 name: pkg | 366 name: pkg |
| 354 dependencies: | 367 dependencies: |
| 355 foo: | 368 foo: |
| 356 mock: ok | 369 mock: ok |
| 357 transformers: | 370 transformers: |
| 358 - foo''', sources); | 371 - foo''', sources); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 ''', sources); | 406 ''', sources); |
| 394 expect(pubspec.version, equals(Version.none)); | 407 expect(pubspec.version, equals(Version.none)); |
| 395 expect(pubspec.dependencies, isEmpty); | 408 expect(pubspec.dependencies, isEmpty); |
| 396 }); | 409 }); |
| 397 | 410 |
| 398 test("throws a useful error for unresolvable path dependencies", () { | 411 test("throws a useful error for unresolvable path dependencies", () { |
| 399 expectPubspecException(''' | 412 expectPubspecException(''' |
| 400 name: pkg | 413 name: pkg |
| 401 dependencies: | 414 dependencies: |
| 402 from_path: {path: non_local_path} | 415 from_path: {path: non_local_path} |
| 403 ''', (pubspec) => pubspec.dependencies, | 416 ''', |
| 404 '"non_local_path" is a relative path, but this isn\'t a local ' | 417 (pubspec) => pubspec.dependencies, |
| 405 'pubspec.'); | 418 '"non_local_path" is a relative path, but this isn\'t a local ' 'pubsp
ec.'); |
| 406 }); | 419 }); |
| 407 | 420 |
| 408 group("environment", () { | 421 group("environment", () { |
| 409 test("defaults to any SDK constraint if environment is omitted", () { | 422 test("defaults to any SDK constraint if environment is omitted", () { |
| 410 var pubspec = new Pubspec.parse('', sources); | 423 var pubspec = new Pubspec.parse('', sources); |
| 411 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); | 424 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); |
| 412 }); | 425 }); |
| 413 | 426 |
| 414 test("allows an empty environment map", () { | 427 test("allows an empty environment map", () { |
| 415 var pubspec = new Pubspec.parse(''' | 428 var pubspec = new Pubspec.parse(''' |
| 416 environment: | 429 environment: |
| 417 ''', sources); | 430 ''', sources); |
| 418 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); | 431 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); |
| 419 }); | 432 }); |
| 420 | 433 |
| 421 test("throws if the environment value isn't a map", () { | 434 test("throws if the environment value isn't a map", () { |
| 422 expectPubspecException('environment: []', | 435 expectPubspecException( |
| 436 'environment: []', |
| 423 (pubspec) => pubspec.environment); | 437 (pubspec) => pubspec.environment); |
| 424 }); | 438 }); |
| 425 | 439 |
| 426 test("allows a version constraint for the sdk", () { | 440 test("allows a version constraint for the sdk", () { |
| 427 var pubspec = new Pubspec.parse(''' | 441 var pubspec = new Pubspec.parse(''' |
| 428 environment: | 442 environment: |
| 429 sdk: ">=1.2.3 <2.3.4" | 443 sdk: ">=1.2.3 <2.3.4" |
| 430 ''', sources); | 444 ''', sources); |
| 431 expect(pubspec.environment.sdkVersion, | 445 expect( |
| 446 pubspec.environment.sdkVersion, |
| 432 equals(new VersionConstraint.parse(">=1.2.3 <2.3.4"))); | 447 equals(new VersionConstraint.parse(">=1.2.3 <2.3.4"))); |
| 433 }); | 448 }); |
| 434 | 449 |
| 435 test("throws if the sdk isn't a string", () { | 450 test("throws if the sdk isn't a string", () { |
| 436 expectPubspecException('environment: {sdk: []}', | 451 expectPubspecException( |
| 452 'environment: {sdk: []}', |
| 437 (pubspec) => pubspec.environment); | 453 (pubspec) => pubspec.environment); |
| 438 expectPubspecException('environment: {sdk: 1.0}', | 454 expectPubspecException( |
| 455 'environment: {sdk: 1.0}', |
| 439 (pubspec) => pubspec.environment); | 456 (pubspec) => pubspec.environment); |
| 440 }); | 457 }); |
| 441 | 458 |
| 442 test("throws if the sdk isn't a valid version constraint", () { | 459 test("throws if the sdk isn't a valid version constraint", () { |
| 443 expectPubspecException('environment: {sdk: "oopies"}', | 460 expectPubspecException( |
| 461 'environment: {sdk: "oopies"}', |
| 444 (pubspec) => pubspec.environment); | 462 (pubspec) => pubspec.environment); |
| 445 }); | 463 }); |
| 446 }); | 464 }); |
| 447 | 465 |
| 448 group("publishTo", () { | 466 group("publishTo", () { |
| 449 test("defaults to null if omitted", () { | 467 test("defaults to null if omitted", () { |
| 450 var pubspec = new Pubspec.parse('', sources); | 468 var pubspec = new Pubspec.parse('', sources); |
| 451 expect(pubspec.publishTo, isNull); | 469 expect(pubspec.publishTo, isNull); |
| 452 }); | 470 }); |
| 453 | 471 |
| 454 test("throws if not a string", () { | 472 test("throws if not a string", () { |
| 455 expectPubspecException('publish_to: 123', | 473 expectPubspecException( |
| 474 'publish_to: 123', |
| 456 (pubspec) => pubspec.publishTo); | 475 (pubspec) => pubspec.publishTo); |
| 457 }); | 476 }); |
| 458 | 477 |
| 459 test("allows a URL", () { | 478 test("allows a URL", () { |
| 460 var pubspec = new Pubspec.parse(''' | 479 var pubspec = new Pubspec.parse(''' |
| 461 publish_to: http://example.com | 480 publish_to: http://example.com |
| 462 ''', sources); | 481 ''', sources); |
| 463 expect(pubspec.publishTo, equals("http://example.com")); | 482 expect(pubspec.publishTo, equals("http://example.com")); |
| 464 }); | 483 }); |
| 465 | 484 |
| 466 test("allows none", () { | 485 test("allows none", () { |
| 467 var pubspec = new Pubspec.parse(''' | 486 var pubspec = new Pubspec.parse(''' |
| 468 publish_to: none | 487 publish_to: none |
| 469 ''', sources); | 488 ''', sources); |
| 470 expect(pubspec.publishTo, equals("none")); | 489 expect(pubspec.publishTo, equals("none")); |
| 471 }); | 490 }); |
| 472 | 491 |
| 473 test("throws on other strings", () { | 492 test("throws on other strings", () { |
| 474 expectPubspecException('publish_to: http://bad.url:not-port', | 493 expectPubspecException( |
| 494 'publish_to: http://bad.url:not-port', |
| 475 (pubspec) => pubspec.publishTo); | 495 (pubspec) => pubspec.publishTo); |
| 476 }); | 496 }); |
| 477 }); | 497 }); |
| 478 | 498 |
| 479 group("executables", () { | 499 group("executables", () { |
| 480 test("defaults to an empty map if omitted", () { | 500 test("defaults to an empty map if omitted", () { |
| 481 var pubspec = new Pubspec.parse('', sources); | 501 var pubspec = new Pubspec.parse('', sources); |
| 482 expect(pubspec.executables, isEmpty); | 502 expect(pubspec.executables, isEmpty); |
| 483 }); | 503 }); |
| 484 | 504 |
| 485 test("allows simple names for keys and most characters in values", () { | 505 test("allows simple names for keys and most characters in values", () { |
| 486 var pubspec = new Pubspec.parse(''' | 506 var pubspec = new Pubspec.parse(''' |
| 487 executables: | 507 executables: |
| 488 abcDEF-123_: "abc DEF-123._" | 508 abcDEF-123_: "abc DEF-123._" |
| 489 ''', sources); | 509 ''', sources); |
| 490 expect(pubspec.executables['abcDEF-123_'], equals('abc DEF-123._')); | 510 expect(pubspec.executables['abcDEF-123_'], equals('abc DEF-123._')); |
| 491 }); | 511 }); |
| 492 | 512 |
| 493 test("throws if not a map", () { | 513 test("throws if not a map", () { |
| 494 expectPubspecException('executables: not map', | 514 expectPubspecException( |
| 515 'executables: not map', |
| 495 (pubspec) => pubspec.executables); | 516 (pubspec) => pubspec.executables); |
| 496 }); | 517 }); |
| 497 | 518 |
| 498 test("throws if key is not a string", () { | 519 test("throws if key is not a string", () { |
| 499 expectPubspecException('executables: {123: value}', | 520 expectPubspecException( |
| 521 'executables: {123: value}', |
| 500 (pubspec) => pubspec.executables); | 522 (pubspec) => pubspec.executables); |
| 501 }); | 523 }); |
| 502 | 524 |
| 503 test("throws if a key isn't a simple name", () { | 525 test("throws if a key isn't a simple name", () { |
| 504 expectPubspecException('executables: {funny/name: ok}', | 526 expectPubspecException( |
| 527 'executables: {funny/name: ok}', |
| 505 (pubspec) => pubspec.executables); | 528 (pubspec) => pubspec.executables); |
| 506 }); | 529 }); |
| 507 | 530 |
| 508 test("throws if a value is not a string", () { | 531 test("throws if a value is not a string", () { |
| 509 expectPubspecException('executables: {command: 123}', | 532 expectPubspecException( |
| 533 'executables: {command: 123}', |
| 510 (pubspec) => pubspec.executables); | 534 (pubspec) => pubspec.executables); |
| 511 }); | 535 }); |
| 512 | 536 |
| 513 test("throws if a value contains a path separator", () { | 537 test("throws if a value contains a path separator", () { |
| 514 expectPubspecException('executables: {command: funny_name/part}', | 538 expectPubspecException( |
| 539 'executables: {command: funny_name/part}', |
| 515 (pubspec) => pubspec.executables); | 540 (pubspec) => pubspec.executables); |
| 516 }); | 541 }); |
| 517 | 542 |
| 518 test("throws if a value contains a windows path separator", () { | 543 test("throws if a value contains a windows path separator", () { |
| 519 expectPubspecException(r'executables: {command: funny_name\part}', | 544 expectPubspecException( |
| 545 r'executables: {command: funny_name\part}', |
| 520 (pubspec) => pubspec.executables); | 546 (pubspec) => pubspec.executables); |
| 521 }); | 547 }); |
| 522 | 548 |
| 523 test("uses the key if the value is null", () { | 549 test("uses the key if the value is null", () { |
| 524 var pubspec = new Pubspec.parse(''' | 550 var pubspec = new Pubspec.parse(''' |
| 525 executables: | 551 executables: |
| 526 command: | 552 command: |
| 527 ''', sources); | 553 ''', sources); |
| 528 expect(pubspec.executables['command'], equals('command')); | 554 expect(pubspec.executables['command'], equals('command')); |
| 529 }); | 555 }); |
| 530 }); | 556 }); |
| 531 }); | 557 }); |
| 532 } | 558 } |
| OLD | NEW |