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

Side by Side Diff: utils/tests/pub/pubspec_test.dart

Issue 11235067: Apply patch from other client. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « utils/pub/pubspec.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '../../../pkg/unittest/unittest.dart'; 7 import '../../../pkg/unittest/unittest.dart';
8 import '../../pub/pubspec.dart'; 8 import '../../pub/pubspec.dart';
9 import '../../pub/source.dart'; 9 import '../../pub/source.dart';
10 import '../../pub/source_registry.dart'; 10 import '../../pub/source_registry.dart';
11 import '../../pub/utils.dart'; 11 import '../../pub/utils.dart';
12 import '../../pub/version.dart'; 12 import '../../pub/version.dart';
13 13
14 class MockSource extends Source { 14 class MockSource extends Source {
15 final String name = "mock"; 15 final String name = "mock";
16 final bool shouldCache = false; 16 final bool shouldCache = false;
17 void validateDescription(description, {bool fromLockFile: false}) { 17 void validateDescription(description, {bool fromLockFile: false}) {
18 if (description != 'ok') throw new FormatException('Bad'); 18 if (description != 'ok') throw new FormatException('Bad');
19 } 19 }
20 String packageName(description) => 'foo'; 20 String packageName(description) => 'foo';
21 } 21 }
22 22
23 main() { 23 main() {
24 group('Pubspec', () { 24 group('Pubspec', () {
25 group('parse()', () { 25 group('parse()', () {
26 var sources = new SourceRegistry();
27 sources.register(new MockSource());
28
26 test("allows a version constraint for dependencies", () { 29 test("allows a version constraint for dependencies", () {
27 var sources = new SourceRegistry();
28 sources.register(new MockSource());
29
30 var pubspec = new Pubspec.parse(''' 30 var pubspec = new Pubspec.parse('''
31 dependencies: 31 dependencies:
32 foo: 32 foo:
33 mock: ok 33 mock: ok
34 version: ">=1.2.3 <3.4.5" 34 version: ">=1.2.3 <3.4.5"
35 ''', sources); 35 ''', sources);
36 36
37 var foo = pubspec.dependencies[0]; 37 var foo = pubspec.dependencies[0];
38 expect(foo.name, equals('foo')); 38 expect(foo.name, equals('foo'));
39 expect(foo.constraint.allows(new Version(1, 2, 3))); 39 expect(foo.constraint.allows(new Version(1, 2, 3)));
40 expect(foo.constraint.allows(new Version(1, 2, 5))); 40 expect(foo.constraint.allows(new Version(1, 2, 5)));
41 expect(!foo.constraint.allows(new Version(3, 4, 5))); 41 expect(!foo.constraint.allows(new Version(3, 4, 5)));
42 }); 42 });
43 43
44 test("throws if the description isn't valid", () { 44 test("throws if the description isn't valid", () {
45 var sources = new SourceRegistry();
46 sources.register(new MockSource());
47
48 expect(() { 45 expect(() {
49 new Pubspec.parse(''' 46 new Pubspec.parse('''
50 dependencies: 47 dependencies:
51 foo: 48 foo:
52 mock: bad 49 mock: bad
53 ''', sources); 50 ''', sources);
54 }, throwsFormatException); 51 }, throwsFormatException);
55 }); 52 });
56 53
54 test("throws if 'name' is not a string", () {
55 expect(() => new Pubspec.parse('name: [not, a, string]', sources),
56 throwsFormatException);
57 });
58
59 test("throws if 'homepage' is not a string", () {
60 expect(() => new Pubspec.parse('homepage: [not, a, string]', sources),
61 throwsFormatException);
62 });
63
64 test("throws if 'authors' is not a string or a list of strings", () {
65 new Pubspec.parse('authors: ok fine', sources);
66 new Pubspec.parse('authors: [also, ok, fine]', sources);
67
68 expect(() => new Pubspec.parse('authors: 123', sources),
69 throwsFormatException);
70
71 expect(() => new Pubspec.parse('authors: {not: {a: string}}', sources),
72 throwsFormatException);
73
74 expect(() => new Pubspec.parse('authors: [ok, {not: ok}]', sources),
75 throwsFormatException);
76 });
77
78 test("throws if 'author' is not a string", () {
79 new Pubspec.parse('author: ok fine', sources);
80
81 expect(() => new Pubspec.parse('author: 123', sources),
82 throwsFormatException);
83
84 expect(() => new Pubspec.parse('author: {not: {a: string}}', sources),
85 throwsFormatException);
86
87 expect(() => new Pubspec.parse('author: [not, ok]', sources),
88 throwsFormatException);
89 });
90
91 test("throws if both 'author' and 'authors' are present", () {
92 expect(() => new Pubspec.parse('{author: abe, authors: ted}', sources),
93 throwsFormatException);
94 });
95
57 test("allows comment-only files", () { 96 test("allows comment-only files", () {
58 var sources = new SourceRegistry();
59 sources.register(new MockSource());
60
61 var pubspec = new Pubspec.parse(''' 97 var pubspec = new Pubspec.parse('''
62 # No external dependencies yet 98 # No external dependencies yet
63 # Including for completeness 99 # Including for completeness
64 # ...and hoping the spec expands to include details about author, version, etc 100 # ...and hoping the spec expands to include details about author, version, etc
65 # See http://www.dartlang.org/docs/pub-package-manager/ for details 101 # See http://www.dartlang.org/docs/pub-package-manager/ for details
66 ''', sources); 102 ''', sources);
67 expect(pubspec.version, equals(Version.none)); 103 expect(pubspec.version, equals(Version.none));
68 expect(pubspec.dependencies, isEmpty); 104 expect(pubspec.dependencies, isEmpty);
69 }); 105 });
70 }); 106 });
71 }); 107 });
72 } 108 }
OLDNEW
« no previous file with comments | « utils/pub/pubspec.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698