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

Side by Side Diff: pkg/analysis_server/test/resource_test.dart

Issue 351813002: A local file-based Index implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks Created 6 years, 6 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 | « pkg/analysis_server/test/index/test_all.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 test.resource; 5 library test.resource;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'mocks.dart';
10
11 import 'package:analysis_server/src/resource.dart'; 9 import 'package:analysis_server/src/resource.dart';
12 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
13 import 'package:analyzer/src/generated/source_io.dart'; 11 import 'package:analyzer/src/generated/source.dart';
14 import 'package:path/path.dart'; 12 import 'package:path/path.dart';
15 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
16 import 'package:watcher/watcher.dart'; 14 import 'package:watcher/watcher.dart';
17 15
16 import 'mocks.dart';
17
18
19 var _isFile = new isInstanceOf<File>();
20 var _isFolder = new isInstanceOf<Folder>();
21 var _isMemoryResourceException = new isInstanceOf<MemoryResourceException>();
22
23
18 main() { 24 main() {
19 groupSep = ' | '; 25 groupSep = ' | ';
20 26
21 group('MemoryResourceProvider', () { 27 group('MemoryResourceProvider', () {
22 MemoryResourceProvider provider; 28 MemoryResourceProvider provider;
23 29
24 setUp(() { 30 setUp(() {
25 provider = new MemoryResourceProvider(); 31 provider = new MemoryResourceProvider();
26 }); 32 });
27 33
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 expect(changesReceived, hasLength(1)); 113 expect(changesReceived, hasLength(1));
108 expect(changesReceived[0].type, equals(ChangeType.REMOVE)); 114 expect(changesReceived[0].type, equals(ChangeType.REMOVE));
109 expect(changesReceived[0].path, equals(path)); 115 expect(changesReceived[0].path, equals(path));
110 }); 116 });
111 }); 117 });
112 }); 118 });
113 }); 119 });
114 120
115 group('newFolder', () { 121 group('newFolder', () {
116 test('empty path', () { 122 test('empty path', () {
117 expect( 123 expect(() {
118 () { 124 provider.newFolder('');
119 provider.newFolder(''); 125 }, throwsA(new isInstanceOf<ArgumentError>()));
120 },
121 throwsA(new isInstanceOf<ArgumentError>())
122 );
123 }); 126 });
124 127
125 test('not absolute', () { 128 test('not absolute', () {
126 expect( 129 expect(() {
127 () { 130 provider.newFolder('not/absolute');
128 provider.newFolder('not/absolute'); 131 }, throwsA(new isInstanceOf<ArgumentError>()));
129 },
130 throwsA(new isInstanceOf<ArgumentError>())
131 );
132 }); 132 });
133 133
134 group('already exists', () { 134 group('already exists', () {
135 test('as folder', () { 135 test('as folder', () {
136 Folder folder = provider.newFolder('/my/folder'); 136 Folder folder = provider.newFolder('/my/folder');
137 Folder newFolder = provider.newFolder('/my/folder'); 137 Folder newFolder = provider.newFolder('/my/folder');
138 expect(newFolder, folder); 138 expect(newFolder, folder);
139 }); 139 });
140 140
141 test('as file', () { 141 test('as file', () {
142 File file = provider.newFile('/my/file', 'qwerty'); 142 File file = provider.newFile('/my/file', 'qwerty');
143 expect( 143 expect(() {
144 () {
145 provider.newFolder('/my/file'); 144 provider.newFolder('/my/file');
146 }, 145 }, throwsA(new isInstanceOf<ArgumentError>()));
147 throwsA(new isInstanceOf<ArgumentError>())
148 );
149 }); 146 });
150 }); 147 });
151 }); 148 });
152 149
153 group('modifyFile', () { 150 group('modifyFile', () {
154 test('nonexistent', () { 151 test('nonexistent', () {
155 String path = '/my/file'; 152 String path = '/my/file';
156 expect(() { provider.modifyFile(path, 'contents'); }, 153 expect(() {
157 throwsA(new isInstanceOf<ArgumentError>())); 154 provider.modifyFile(path, 'contents');
155 }, throwsA(new isInstanceOf<ArgumentError>()));
158 Resource file = provider.getResource(path); 156 Resource file = provider.getResource(path);
159 expect(file, isNotNull); 157 expect(file, isNotNull);
160 expect(file.exists, isFalse); 158 expect(file.exists, isFalse);
161 }); 159 });
162 160
163 test('is folder', () { 161 test('is folder', () {
164 String path = '/my/file'; 162 String path = '/my/file';
165 provider.newFolder(path); 163 provider.newFolder(path);
166 expect(() { provider.modifyFile(path, 'contents'); }, 164 expect(() {
167 throwsA(new isInstanceOf<ArgumentError>())); 165 provider.modifyFile(path, 'contents');
166 }, throwsA(new isInstanceOf<ArgumentError>()));
168 expect(provider.getResource(path), new isInstanceOf<Folder>()); 167 expect(provider.getResource(path), new isInstanceOf<Folder>());
169 }); 168 });
170 169
171 test('successful', () { 170 test('successful', () {
172 String path = '/my/file'; 171 String path = '/my/file';
173 provider.newFile(path, 'contents 1'); 172 provider.newFile(path, 'contents 1');
174 Resource file = provider.getResource(path); 173 Resource file = provider.getResource(path);
175 expect(file, new isInstanceOf<File>()); 174 expect(file, new isInstanceOf<File>());
176 Source source = (file as File).createSource(UriKind.FILE_URI); 175 Source source = (file as File).createSource(UriKind.FILE_URI);
177 expect(source.contents.data, equals('contents 1')); 176 expect(source.contents.data, equals('contents 1'));
178 provider.modifyFile(path, 'contents 2'); 177 provider.modifyFile(path, 'contents 2');
179 expect(source.contents.data, equals('contents 2')); 178 expect(source.contents.data, equals('contents 2'));
180 }); 179 });
181 }); 180 });
182 181
183 group('deleteFile', () { 182 group('deleteFile', () {
184 test('nonexistent', () { 183 test('nonexistent', () {
185 String path = '/my/file'; 184 String path = '/my/file';
186 expect(() { provider.deleteFile(path); }, 185 expect(() {
187 throwsA(new isInstanceOf<ArgumentError>())); 186 provider.deleteFile(path);
187 }, throwsA(new isInstanceOf<ArgumentError>()));
188 Resource file = provider.getResource(path); 188 Resource file = provider.getResource(path);
189 expect(file, isNotNull); 189 expect(file, isNotNull);
190 expect(file.exists, isFalse); 190 expect(file.exists, isFalse);
191 }); 191 });
192 192
193 test('is folder', () { 193 test('is folder', () {
194 String path = '/my/file'; 194 String path = '/my/file';
195 provider.newFolder(path); 195 provider.newFolder(path);
196 expect(() { provider.deleteFile(path); }, 196 expect(() {
197 throwsA(new isInstanceOf<ArgumentError>())); 197 provider.deleteFile(path);
198 }, throwsA(new isInstanceOf<ArgumentError>()));
198 expect(provider.getResource(path), new isInstanceOf<Folder>()); 199 expect(provider.getResource(path), new isInstanceOf<Folder>());
199 }); 200 });
200 201
201 test('successful', () { 202 test('successful', () {
202 String path = '/my/file'; 203 String path = '/my/file';
203 provider.newFile(path, 'contents'); 204 provider.newFile(path, 'contents');
204 Resource file = provider.getResource(path); 205 Resource file = provider.getResource(path);
205 expect(file, new isInstanceOf<File>()); 206 expect(file, new isInstanceOf<File>());
206 expect(file.exists, isTrue); 207 expect(file.exists, isTrue);
207 provider.deleteFile(path); 208 provider.deleteFile(path);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 }); 386 });
386 }); 387 });
387 388
388 group('non-existent', () { 389 group('non-existent', () {
389 setUp(() { 390 setUp(() {
390 File file = provider.getResource('/foo/test.dart'); 391 File file = provider.getResource('/foo/test.dart');
391 source = file.createSource(UriKind.FILE_URI); 392 source = file.createSource(UriKind.FILE_URI);
392 }); 393 });
393 394
394 test('contents', () { 395 test('contents', () {
395 expect( 396 expect(() {
396 () { 397 source.contents;
397 source.contents; 398 }, throwsA(_isMemoryResourceException));
398 },
399 throwsA(_isMemoryResourceException)
400 );
401 }); 399 });
402 400
403 test('encoding', () { 401 test('encoding', () {
404 expect(source.encoding, 'f/foo/test.dart'); 402 expect(source.encoding, 'f/foo/test.dart');
405 }); 403 });
406 404
407 test('exists', () { 405 test('exists', () {
408 expect(source.exists(), isFalse); 406 expect(source.exists(), isFalse);
409 }); 407 });
410 408
411 test('fullName', () { 409 test('fullName', () {
412 expect(source.fullName, '/foo/test.dart'); 410 expect(source.fullName, '/foo/test.dart');
413 }); 411 });
414 412
415 test('shortName', () { 413 test('shortName', () {
416 expect(source.shortName, 'test.dart'); 414 expect(source.shortName, 'test.dart');
417 }); 415 });
418 416
419 test('resolveRelative', () { 417 test('resolveRelative', () {
420 var relative = source.resolveRelative(new Uri.file('bar/baz.dart')); 418 var relative = source.resolveRelative(new Uri.file('bar/baz.dart'));
421 expect(relative.fullName, '/foo/bar/baz.dart'); 419 expect(relative.fullName, '/foo/bar/baz.dart');
422 }); 420 });
423 }); 421 });
424 }); 422 });
425 }); 423 });
424
425 group('ResourceUriResolver', testResourceResourceUriResolver);
426 } 426 }
427 427
428 var _isFile = new isInstanceOf<File>(); 428
429 var _isFolder = new isInstanceOf<Folder>(); 429 void testResourceResourceUriResolver() {
430 var _isMemoryResourceException = new isInstanceOf<MemoryResourceException>(); 430 MemoryResourceProvider provider;
431 ResourceUriResolver resolver;
432
433 setUp(() {
434 provider = new MemoryResourceProvider();
435 resolver = new ResourceUriResolver(provider);
436 provider.newFile('/test.dart', '');
437 provider.newFolder('/folder');
438 });
439
440 group('fromEncoding', () {
441 test('file', () {
442 var uri = new Uri(path: '/test.dart');
443 Source source = resolver.fromEncoding(UriKind.FILE_URI, uri);
444 expect(source, isNotNull);
445 expect(source.exists(), isTrue);
446 expect(source.fullName, '/test.dart');
447 });
448
449 test('not a UriKind.FILE_URI', () {
450 var uri = new Uri(path: '/test.dart');
451 Source source = resolver.fromEncoding(UriKind.DART_URI, uri);
452 expect(source, isNull);
453 });
454 });
455
456 group('resolveAbsolute', () {
457 test('file', () {
458 var uri = new Uri(scheme: 'file', path: '/test.dart');
459 Source source = resolver.resolveAbsolute(uri);
460 expect(source, isNotNull);
461 expect(source.exists(), isTrue);
462 expect(source.fullName, '/test.dart');
463 });
464
465 test('folder', () {
466 var uri = new Uri(scheme: 'file', path: '/folder');
467 Source source = resolver.resolveAbsolute(uri);
468 expect(source, isNull);
469 });
470
471 test('not a file URI', () {
472 var uri = new Uri(scheme: 'https', path: '127.0.0.1/test.dart');
473 Source source = resolver.resolveAbsolute(uri);
474 expect(source, isNull);
475 });
476 });
477 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/index/test_all.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698