OLD | NEW |
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.memory_file_system; | 5 library test.memory_file_system; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; | 9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; |
10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 provider.modifyFile(path, 'contents'); | 164 provider.modifyFile(path, 'contents'); |
165 }, throwsA(new isInstanceOf<ArgumentError>())); | 165 }, throwsA(new isInstanceOf<ArgumentError>())); |
166 expect(provider.getResource(path), new isInstanceOf<Folder>()); | 166 expect(provider.getResource(path), new isInstanceOf<Folder>()); |
167 }); | 167 }); |
168 | 168 |
169 test('successful', () { | 169 test('successful', () { |
170 String path = '/my/file'; | 170 String path = '/my/file'; |
171 provider.newFile(path, 'contents 1'); | 171 provider.newFile(path, 'contents 1'); |
172 Resource file = provider.getResource(path); | 172 Resource file = provider.getResource(path); |
173 expect(file, new isInstanceOf<File>()); | 173 expect(file, new isInstanceOf<File>()); |
174 Source source = (file as File).createSource(UriKind.FILE_URI); | 174 Source source = (file as File).createSource(); |
175 expect(source.contents.data, equals('contents 1')); | 175 expect(source.contents.data, equals('contents 1')); |
176 provider.modifyFile(path, 'contents 2'); | 176 provider.modifyFile(path, 'contents 2'); |
177 expect(source.contents.data, equals('contents 2')); | 177 expect(source.contents.data, equals('contents 2')); |
178 }); | 178 }); |
179 }); | 179 }); |
180 | 180 |
181 group('deleteFile', () { | 181 group('deleteFile', () { |
182 test('nonexistent', () { | 182 test('nonexistent', () { |
183 String path = '/my/file'; | 183 String path = '/my/file'; |
184 expect(() { | 184 expect(() { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 expect(folder.canonicalizePath('/a/b/./c'), equals('/a/b/c')); | 366 expect(folder.canonicalizePath('/a/b/./c'), equals('/a/b/c')); |
367 }); | 367 }); |
368 }); | 368 }); |
369 | 369 |
370 group('_MemoryFileSource', () { | 370 group('_MemoryFileSource', () { |
371 Source source; | 371 Source source; |
372 | 372 |
373 group('existent', () { | 373 group('existent', () { |
374 setUp(() { | 374 setUp(() { |
375 File file = provider.newFile('/foo/test.dart', 'library test;'); | 375 File file = provider.newFile('/foo/test.dart', 'library test;'); |
376 source = file.createSource(UriKind.FILE_URI); | 376 source = file.createSource(); |
377 }); | 377 }); |
378 | 378 |
379 group('==', () { | 379 group('==', () { |
380 group('true', () { | 380 group('true', () { |
381 test('self', () { | 381 test('self', () { |
382 File file = provider.newFile('/foo/test.dart', ''); | 382 File file = provider.newFile('/foo/test.dart', ''); |
383 Source source = file.createSource(UriKind.FILE_URI); | 383 Source source = file.createSource(); |
384 expect(source == source, isTrue); | 384 expect(source == source, isTrue); |
385 }); | 385 }); |
386 | 386 |
387 test('same file', () { | 387 test('same file', () { |
388 File file = provider.newFile('/foo/test.dart', ''); | 388 File file = provider.newFile('/foo/test.dart', ''); |
389 Source sourceA = file.createSource(UriKind.FILE_URI); | 389 Source sourceA = file.createSource(); |
390 Source sourceB = file.createSource(UriKind.FILE_URI); | 390 Source sourceB = file.createSource(); |
391 expect(sourceA == sourceB, isTrue); | 391 expect(sourceA == sourceB, isTrue); |
392 }); | 392 }); |
393 }); | 393 }); |
394 | 394 |
395 group('false', () { | 395 group('false', () { |
396 test('not a memory Source', () { | 396 test('not a memory Source', () { |
397 File file = provider.newFile('/foo/test.dart', ''); | 397 File file = provider.newFile('/foo/test.dart', ''); |
398 Source source = file.createSource(UriKind.FILE_URI); | 398 Source source = file.createSource(); |
399 expect(source == new Object(), isFalse); | 399 expect(source == new Object(), isFalse); |
400 }); | 400 }); |
401 | 401 |
402 test('different file', () { | 402 test('different file', () { |
403 File fileA = provider.newFile('/foo/a.dart', ''); | 403 File fileA = provider.newFile('/foo/a.dart', ''); |
404 File fileB = provider.newFile('/foo/b.dart', ''); | 404 File fileB = provider.newFile('/foo/b.dart', ''); |
405 Source sourceA = fileA.createSource(UriKind.FILE_URI); | 405 Source sourceA = fileA.createSource(); |
406 Source sourceB = fileB.createSource(UriKind.FILE_URI); | 406 Source sourceB = fileB.createSource(); |
407 expect(sourceA == sourceB, isFalse); | 407 expect(sourceA == sourceB, isFalse); |
408 }); | 408 }); |
409 }); | 409 }); |
410 }); | 410 }); |
411 | 411 |
412 test('contents', () { | 412 test('contents', () { |
413 TimestampedData<String> contents = source.contents; | 413 TimestampedData<String> contents = source.contents; |
414 expect(contents.data, 'library test;'); | 414 expect(contents.data, 'library test;'); |
415 }); | 415 }); |
416 | 416 |
417 test('encoding', () { | 417 test('encoding', () { |
418 expect(source.encoding, 'f/foo/test.dart'); | 418 expect(source.encoding, 'file:///foo/test.dart'); |
419 }); | 419 }); |
420 | 420 |
421 test('exists', () { | 421 test('exists', () { |
422 expect(source.exists(), isTrue); | 422 expect(source.exists(), isTrue); |
423 }); | 423 }); |
424 | 424 |
425 test('fullName', () { | 425 test('fullName', () { |
426 expect(source.fullName, '/foo/test.dart'); | 426 expect(source.fullName, '/foo/test.dart'); |
427 }); | 427 }); |
428 | 428 |
429 test('hashCode', () { | 429 test('hashCode', () { |
430 source.hashCode; | 430 source.hashCode; |
431 }); | 431 }); |
432 | 432 |
433 test('shortName', () { | 433 test('shortName', () { |
434 expect(source.shortName, 'test.dart'); | 434 expect(source.shortName, 'test.dart'); |
435 }); | 435 }); |
436 | 436 |
437 test('resolveRelative', () { | 437 test('resolveRelative', () { |
438 var relative = source.resolveRelative(new Uri.file('bar/baz.dart')); | 438 Uri relative = source.resolveRelative(new Uri.file('bar/baz.dart')); |
439 expect(relative.fullName, '/foo/bar/baz.dart'); | 439 expect(relative.path, '/foo/bar/baz.dart'); |
440 }); | 440 }); |
441 }); | 441 }); |
442 | 442 |
443 group('non-existent', () { | 443 group('non-existent', () { |
444 setUp(() { | 444 setUp(() { |
445 File file = provider.getResource('/foo/test.dart'); | 445 File file = provider.getResource('/foo/test.dart'); |
446 source = file.createSource(UriKind.FILE_URI); | 446 source = file.createSource(); |
447 }); | 447 }); |
448 | 448 |
449 test('contents', () { | 449 test('contents', () { |
450 expect(() { | 450 expect(() { |
451 source.contents; | 451 source.contents; |
452 }, throwsA(_isMemoryResourceException)); | 452 }, throwsA(_isMemoryResourceException)); |
453 }); | 453 }); |
454 | 454 |
455 test('encoding', () { | 455 test('encoding', () { |
456 expect(source.encoding, 'f/foo/test.dart'); | 456 expect(source.encoding, 'file:///foo/test.dart'); |
457 }); | 457 }); |
458 | 458 |
459 test('exists', () { | 459 test('exists', () { |
460 expect(source.exists(), isFalse); | 460 expect(source.exists(), isFalse); |
461 }); | 461 }); |
462 | 462 |
463 test('fullName', () { | 463 test('fullName', () { |
464 expect(source.fullName, '/foo/test.dart'); | 464 expect(source.fullName, '/foo/test.dart'); |
465 }); | 465 }); |
466 | 466 |
467 test('shortName', () { | 467 test('shortName', () { |
468 expect(source.shortName, 'test.dart'); | 468 expect(source.shortName, 'test.dart'); |
469 }); | 469 }); |
470 | 470 |
471 test('resolveRelative', () { | 471 test('resolveRelative', () { |
472 var relative = source.resolveRelative(new Uri.file('bar/baz.dart')); | 472 Uri relative = source.resolveRelative(new Uri.file('bar/baz.dart')); |
473 expect(relative.fullName, '/foo/bar/baz.dart'); | 473 expect(relative.path, '/foo/bar/baz.dart'); |
474 }); | 474 }); |
475 }); | 475 }); |
476 }); | 476 }); |
477 }); | 477 }); |
478 } | 478 } |
OLD | NEW |