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

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

Issue 14297021: Move pub into sdk/lib/_internal. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Disallow package: imports of pub. Created 7 years, 8 months 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/tests/pub/pub_uploader_test.dart ('k') | utils/tests/pub/real_version_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library pubspec_test;
6
7 import 'package:unittest/unittest.dart';
8
9 import '../../pub/pubspec.dart';
10 import '../../pub/source.dart';
11 import '../../pub/source_registry.dart';
12 import '../../pub/utils.dart';
13 import '../../pub/version.dart';
14 import 'test_pub.dart';
15
16 class MockSource extends Source {
17 final String name = "mock";
18 final bool shouldCache = false;
19 dynamic parseDescription(String filePath, description,
20 {bool fromLockFile: false}) {
21 if (description != 'ok') throw new FormatException('Bad');
22 return description;
23 }
24 String packageName(description) => 'foo';
25 }
26
27 main() {
28 initConfig();
29 group('parse()', () {
30 var sources = new SourceRegistry();
31 sources.register(new MockSource());
32
33 expectFormatError(String pubspec) {
34 expect(() => new Pubspec.parse(null, pubspec, sources),
35 throwsFormatException);
36 }
37
38 test("allows a version constraint for dependencies", () {
39 var pubspec = new Pubspec.parse(null, '''
40 dependencies:
41 foo:
42 mock: ok
43 version: ">=1.2.3 <3.4.5"
44 ''', sources);
45
46 var foo = pubspec.dependencies[0];
47 expect(foo.name, equals('foo'));
48 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue);
49 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue);
50 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse);
51 });
52
53 test("allows an empty dependencies map", () {
54 var pubspec = new Pubspec.parse(null, '''
55 dependencies:
56 ''', sources);
57
58 expect(pubspec.dependencies, isEmpty);
59 });
60
61 test("allows a version constraint for dev dependencies", () {
62 var pubspec = new Pubspec.parse(null, '''
63 dev_dependencies:
64 foo:
65 mock: ok
66 version: ">=1.2.3 <3.4.5"
67 ''', sources);
68
69 var foo = pubspec.devDependencies[0];
70 expect(foo.name, equals('foo'));
71 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue);
72 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue);
73 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse);
74 });
75
76 test("allows an empty dev dependencies map", () {
77 var pubspec = new Pubspec.parse(null, '''
78 dev_dependencies:
79 ''', sources);
80
81 expect(pubspec.devDependencies, isEmpty);
82 });
83
84 test("throws if a package is in dependencies and dev_dependencies", () {
85 expectFormatError('''
86 dependencies:
87 foo:
88 mock: ok
89 dev_dependencies:
90 foo:
91 mock: ok
92 ''');
93 });
94
95 test("throws if the description isn't valid", () {
96 expectFormatError('''
97 dependencies:
98 foo:
99 mock: bad
100 ''');
101 });
102
103 test("throws if 'name' is not a string", () {
104 expectFormatError('name: [not, a, string]');
105 });
106
107 test("throws if 'homepage' is not a string", () {
108 expectFormatError('homepage:');
109 expectFormatError('homepage: [not, a, string]');
110 });
111
112 test("throws if 'homepage' doesn't have an HTTP scheme", () {
113 new Pubspec.parse(null, 'homepage: http://ok.com', sources);
114 new Pubspec.parse(null, 'homepage: https://also-ok.com', sources);
115
116 expectFormatError('homepage: ftp://badscheme.com');
117 expectFormatError('homepage: javascript:alert("!!!")');
118 expectFormatError('homepage: data:image/png;base64,somedata');
119 expectFormatError('homepage: no-scheme.com');
120 });
121
122 test("throws if 'documentation' is not a string", () {
123 expectFormatError('documentation:');
124 expectFormatError('documentation: [not, a, string]');
125 });
126
127 test("throws if 'documentation' doesn't have an HTTP scheme", () {
128 new Pubspec.parse(null, 'documentation: http://ok.com', sources);
129 new Pubspec.parse(null, 'documentation: https://also-ok.com', sources);
130
131 expectFormatError('documentation: ftp://badscheme.com');
132 expectFormatError('documentation: javascript:alert("!!!")');
133 expectFormatError('documentation: data:image/png;base64,somedata');
134 expectFormatError('documentation: no-scheme.com');
135 });
136
137 test("throws if 'authors' is not a string or a list of strings", () {
138 new Pubspec.parse(null, 'authors: ok fine', sources);
139 new Pubspec.parse(null, 'authors: [also, ok, fine]', sources);
140
141 expectFormatError('authors: 123');
142 expectFormatError('authors: {not: {a: string}}');
143 expectFormatError('authors: [ok, {not: ok}]');
144 });
145
146 test("throws if 'author' is not a string", () {
147 new Pubspec.parse(null, 'author: ok fine', sources);
148
149 expectFormatError('author: 123');
150 expectFormatError('author: {not: {a: string}}');
151 expectFormatError('author: [not, ok]');
152 });
153
154 test("throws if both 'author' and 'authors' are present", () {
155 expectFormatError('{author: abe, authors: ted}');
156 });
157
158 test("allows comment-only files", () {
159 var pubspec = new Pubspec.parse(null, '''
160 # No external dependencies yet
161 # Including for completeness
162 # ...and hoping the spec expands to include details about author, version, etc
163 # See http://www.dartlang.org/docs/pub-package-manager/ for details
164 ''', sources);
165 expect(pubspec.version, equals(Version.none));
166 expect(pubspec.dependencies, isEmpty);
167 });
168
169 group("environment", () {
170 test("defaults to any SDK constraint if environment is omitted", () {
171 var pubspec = new Pubspec.parse(null, '', sources);
172 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any));
173 });
174
175 test("allows an empty environment map", () {
176 var pubspec = new Pubspec.parse(null, '''
177 environment:
178 ''', sources);
179 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any));
180 });
181
182 test("throws if the environment value isn't a map", () {
183 expectFormatError('''
184 environment: []
185 ''');
186 });
187
188 test("allows a version constraint for the sdk", () {
189 var pubspec = new Pubspec.parse(null, '''
190 environment:
191 sdk: ">=1.2.3 <2.3.4"
192 ''', sources);
193 expect(pubspec.environment.sdkVersion,
194 equals(new VersionConstraint.parse(">=1.2.3 <2.3.4")));
195 });
196
197 test("throws if the sdk isn't a string", () {
198 expectFormatError('''
199 environment:
200 sdk: []
201 ''');
202 });
203
204 test("throws if the sdk isn't a valid version constraint", () {
205 expectFormatError('''
206 environment:
207 sdk: "oopies"
208 ''');
209 });
210 });
211 });
212 }
OLDNEW
« no previous file with comments | « utils/tests/pub/pub_uploader_test.dart ('k') | utils/tests/pub/real_version_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698