| 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/package.dart'; | 5 import 'package:pub/src/package.dart'; |
| 6 import 'package:pub/src/pubspec.dart'; | 6 import 'package:pub/src/pubspec.dart'; |
| 7 import 'package:pub/src/source.dart'; | 7 import 'package:pub/src/source.dart'; |
| 8 import 'package:pub/src/source/path.dart'; | 8 import 'package:pub/src/source/path.dart'; |
| 9 import 'package:pub/src/source_registry.dart'; | 9 import 'package:pub/src/source_registry.dart'; |
| 10 import 'package:pub/src/system_cache.dart'; | 10 import 'package:pub/src/system_cache.dart'; |
| 11 import 'package:pub_semver/pub_semver.dart'; | 11 import 'package:pub_semver/pub_semver.dart'; |
| 12 import 'package:test/test.dart'; | 12 import 'package:test/test.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 != 'ok') throw new FormatException('Bad'); | 21 if (description != 'ok') 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 new PackageId(name, this.name, version, description); | 26 new PackageId(name, this, version, description); |
| 27 | 27 |
| 28 bool descriptionsEqual(description1, description2) => | 28 bool descriptionsEqual(description1, description2) => |
| 29 description1 == description2; | 29 description1 == description2; |
| 30 | 30 |
| 31 int hashDescription(description) => description.hashCode; |
| 32 |
| 31 String packageName(description) => 'foo'; | 33 String packageName(description) => 'foo'; |
| 32 } | 34 } |
| 33 | 35 |
| 34 main() { | 36 main() { |
| 35 group('parse()', () { | 37 group('parse()', () { |
| 36 var sources = new SourceRegistry(); | 38 var sources = new SourceRegistry(); |
| 37 sources.register(new MockSource()); | 39 sources.register(new MockSource()); |
| 38 | 40 |
| 39 var throwsPubspecException = | 41 var throwsPubspecException = |
| 40 throwsA(new isInstanceOf<PubspecException>()); | 42 throwsA(new isInstanceOf<PubspecException>()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 142 |
| 141 test("allows an unknown source", () { | 143 test("allows an unknown source", () { |
| 142 var pubspec = new Pubspec.parse(''' | 144 var pubspec = new Pubspec.parse(''' |
| 143 dependencies: | 145 dependencies: |
| 144 foo: | 146 foo: |
| 145 unknown: blah | 147 unknown: blah |
| 146 ''', sources); | 148 ''', sources); |
| 147 | 149 |
| 148 var foo = pubspec.dependencies[0]; | 150 var foo = pubspec.dependencies[0]; |
| 149 expect(foo.name, equals('foo')); | 151 expect(foo.name, equals('foo')); |
| 150 expect(foo.source, equals('unknown')); | 152 expect(foo.source, equals(sources['unknown'])); |
| 151 }); | 153 }); |
| 152 | 154 |
| 153 test("throws if a package is in dependencies and dev_dependencies", () { | 155 test("throws if a package is in dependencies and dev_dependencies", () { |
| 154 expectPubspecException(''' | 156 expectPubspecException(''' |
| 155 dependencies: | 157 dependencies: |
| 156 foo: | 158 foo: |
| 157 mock: ok | 159 mock: ok |
| 158 dev_dependencies: | 160 dev_dependencies: |
| 159 foo: | 161 foo: |
| 160 mock: ok | 162 mock: ok |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 test("uses the key if the value is null", () { | 522 test("uses the key if the value is null", () { |
| 521 var pubspec = new Pubspec.parse(''' | 523 var pubspec = new Pubspec.parse(''' |
| 522 executables: | 524 executables: |
| 523 command: | 525 command: |
| 524 ''', sources); | 526 ''', sources); |
| 525 expect(pubspec.executables['command'], equals('command')); | 527 expect(pubspec.executables['command'], equals('command')); |
| 526 }); | 528 }); |
| 527 }); | 529 }); |
| 528 }); | 530 }); |
| 529 } | 531 } |
| OLD | NEW |