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

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

Issue 12285010: Support relative paths in path dependencies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Generate relative or absolute symlinks based on the path dep. Created 7 years, 10 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
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 lock_file_test; 5 library lock_file_test;
6 6
7 import '../../../pkg/unittest/lib/unittest.dart'; 7 import '../../../pkg/unittest/lib/unittest.dart';
8 import '../../../pkg/yaml/lib/yaml.dart'; 8 import '../../../pkg/yaml/lib/yaml.dart';
9 import '../../pub/lock_file.dart'; 9 import '../../pub/lock_file.dart';
10 import '../../pub/package.dart'; 10 import '../../pub/package.dart';
11 import '../../pub/source.dart'; 11 import '../../pub/source.dart';
12 import '../../pub/source_registry.dart'; 12 import '../../pub/source_registry.dart';
13 import '../../pub/utils.dart'; 13 import '../../pub/utils.dart';
14 import '../../pub/version.dart'; 14 import '../../pub/version.dart';
15 15
16 class MockSource extends Source { 16 class MockSource extends Source {
17 final String name = 'mock'; 17 final String name = 'mock';
18 final bool shouldCache = false; 18 final bool shouldCache = false;
19 19
20 void validateDescription(String description, {bool fromLockFile: false}) { 20 dynamic parseDescription(String filePath, String description,
21 {bool fromLockFile: false}) {
21 if (!description.endsWith(' desc')) throw new FormatException(); 22 if (!description.endsWith(' desc')) throw new FormatException();
23 return description;
22 } 24 }
23 25
24 String packageName(String description) { 26 String packageName(String description) {
25 // Strip off ' desc'. 27 // Strip off ' desc'.
26 return description.substring(0, description.length - 5); 28 return description.substring(0, description.length - 5);
27 } 29 }
28 } 30 }
29 31
30 main() { 32 main() {
31 var sources = new SourceRegistry(); 33 var sources = new SourceRegistry();
32 var mockSource = new MockSource(); 34 var mockSource = new MockSource();
33 sources.register(mockSource); 35 sources.register(mockSource);
34 36
35 group('LockFile', () { 37 group('LockFile', () {
36 group('parse()', () { 38 group('parse()', () {
37 test('returns an empty lockfile if the contents are empty', () { 39 test('returns an empty lockfile if the contents are empty', () {
38 var lockFile = new LockFile.parse('', sources); 40 var lockFile = new LockFile.parse(null, '', sources);
39 expect(lockFile.packages.length, equals(0)); 41 expect(lockFile.packages.length, equals(0));
40 }); 42 });
41 43
42 test('returns an empty lockfile if the contents are whitespace', () { 44 test('returns an empty lockfile if the contents are whitespace', () {
43 var lockFile = new LockFile.parse(' \t\n ', sources); 45 var lockFile = new LockFile.parse(null, ' \t\n ', sources);
44 expect(lockFile.packages.length, equals(0)); 46 expect(lockFile.packages.length, equals(0));
45 }); 47 });
46 48
47 test('parses a series of package descriptions', () { 49 test('parses a series of package descriptions', () {
48 var lockFile = new LockFile.parse(''' 50 var lockFile = new LockFile.parse(null, '''
49 packages: 51 packages:
50 bar: 52 bar:
51 version: 1.2.3 53 version: 1.2.3
52 source: mock 54 source: mock
53 description: bar desc 55 description: bar desc
54 foo: 56 foo:
55 version: 2.3.4 57 version: 2.3.4
56 source: mock 58 source: mock
57 description: foo desc 59 description: foo desc
58 ''', sources); 60 ''', sources);
59 61
60 expect(lockFile.packages.length, equals(2)); 62 expect(lockFile.packages.length, equals(2));
61 63
62 var bar = lockFile.packages['bar']; 64 var bar = lockFile.packages['bar'];
63 expect(bar.name, equals('bar')); 65 expect(bar.name, equals('bar'));
64 expect(bar.version, equals(new Version(1, 2, 3))); 66 expect(bar.version, equals(new Version(1, 2, 3)));
65 expect(bar.source, equals(mockSource)); 67 expect(bar.source, equals(mockSource));
66 expect(bar.description, equals('bar desc')); 68 expect(bar.description, equals('bar desc'));
67 69
68 var foo = lockFile.packages['foo']; 70 var foo = lockFile.packages['foo'];
69 expect(foo.name, equals('foo')); 71 expect(foo.name, equals('foo'));
70 expect(foo.version, equals(new Version(2, 3, 4))); 72 expect(foo.version, equals(new Version(2, 3, 4)));
71 expect(foo.source, equals(mockSource)); 73 expect(foo.source, equals(mockSource));
72 expect(foo.description, equals('foo desc')); 74 expect(foo.description, equals('foo desc'));
73 }); 75 });
74 76
75 test("throws if the version is missing", () { 77 test("throws if the version is missing", () {
76 expect(() { 78 expect(() {
77 new LockFile.parse(''' 79 new LockFile.parse(null, '''
78 packages: 80 packages:
79 foo: 81 foo:
80 source: mock 82 source: mock
81 description: foo desc 83 description: foo desc
82 ''', sources); 84 ''', sources);
83 }, throwsFormatException); 85 }, throwsFormatException);
84 }); 86 });
85 87
86 test("throws if the version is invalid", () { 88 test("throws if the version is invalid", () {
87 expect(() { 89 expect(() {
88 new LockFile.parse(''' 90 new LockFile.parse(null, '''
89 packages: 91 packages:
90 foo: 92 foo:
91 version: vorpal 93 version: vorpal
92 source: mock 94 source: mock
93 description: foo desc 95 description: foo desc
94 ''', sources); 96 ''', sources);
95 }, throwsFormatException); 97 }, throwsFormatException);
96 }); 98 });
97 99
98 test("throws if the source is missing", () { 100 test("throws if the source is missing", () {
99 expect(() { 101 expect(() {
100 new LockFile.parse(''' 102 new LockFile.parse(null, '''
101 packages: 103 packages:
102 foo: 104 foo:
103 version: 1.2.3 105 version: 1.2.3
104 description: foo desc 106 description: foo desc
105 ''', sources); 107 ''', sources);
106 }, throwsFormatException); 108 }, throwsFormatException);
107 }); 109 });
108 110
109 test("throws if the source is unknown", () { 111 test("throws if the source is unknown", () {
110 expect(() { 112 expect(() {
111 new LockFile.parse(''' 113 new LockFile.parse(null, '''
112 packages: 114 packages:
113 foo: 115 foo:
114 version: 1.2.3 116 version: 1.2.3
115 source: notreal 117 source: notreal
116 description: foo desc 118 description: foo desc
117 ''', sources); 119 ''', sources);
118 }, throwsFormatException); 120 }, throwsFormatException);
119 }); 121 });
120 122
121 test("throws if the description is missing", () { 123 test("throws if the description is missing", () {
122 expect(() { 124 expect(() {
123 new LockFile.parse(''' 125 new LockFile.parse(null, '''
124 packages: 126 packages:
125 foo: 127 foo:
126 version: 1.2.3 128 version: 1.2.3
127 source: mock 129 source: mock
128 ''', sources); 130 ''', sources);
129 }, throwsFormatException); 131 }, throwsFormatException);
130 }); 132 });
131 133
132 test("throws if the description is invalid", () { 134 test("throws if the description is invalid", () {
133 expect(() { 135 expect(() {
134 new LockFile.parse(''' 136 new LockFile.parse(null, '''
135 packages: 137 packages:
136 foo: 138 foo:
137 version: 1.2.3 139 version: 1.2.3
138 source: mock 140 source: mock
139 description: foo desc is bad 141 description: foo desc is bad
140 ''', sources); 142 ''', sources);
141 }, throwsFormatException); 143 }, throwsFormatException);
142 }); 144 });
143 145
144 test("ignores extra stuff in file", () { 146 test("ignores extra stuff in file", () {
145 var lockFile = new LockFile.parse(''' 147 var lockFile = new LockFile.parse(null, '''
146 extra: 148 extra:
147 some: stuff 149 some: stuff
148 packages: 150 packages:
149 foo: 151 foo:
150 bonus: not used 152 bonus: not used
151 version: 1.2.3 153 version: 1.2.3
152 source: mock 154 source: mock
153 description: foo desc 155 description: foo desc
154 ''', sources); 156 ''', sources);
155 }); 157 });
(...skipping 18 matching lines...) Expand all
174 'version': '3.2.1', 176 'version': '3.2.1',
175 'source': 'mock', 177 'source': 'mock',
176 'description': 'bar desc' 178 'description': 'bar desc'
177 } 179 }
178 } 180 }
179 })); 181 }));
180 }); 182 });
181 }); 183 });
182 }); 184 });
183 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698