| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/error/listener.dart'; | |
| 6 import 'package:analyzer/src/generated/parser.dart'; | |
| 7 import 'package:analyzer/src/summary/summarize_ast.dart'; | |
| 8 import 'package:front_end/src/base/file_repository.dart'; | 5 import 'package:front_end/src/base/file_repository.dart'; |
| 9 import 'package:front_end/src/base/library_info.dart'; | |
| 10 import 'package:front_end/src/libraries_reader.dart'; | |
| 11 import 'package:front_end/src/scanner/errors.dart'; | |
| 12 import 'package:front_end/src/scanner/reader.dart'; | |
| 13 import 'package:front_end/src/scanner/scanner.dart'; | |
| 14 import 'package:test/test.dart'; | 6 import 'package:test/test.dart'; |
| 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 16 | 8 |
| 17 main() { | 9 main() { |
| 18 defineReflectiveSuite(() { | 10 defineReflectiveSuite(() { |
| 19 defineReflectiveTests(FileRepositoryTest); | 11 defineReflectiveTests(FileRepositoryTest); |
| 20 }); | 12 }); |
| 21 } | 13 } |
| 22 | 14 |
| 23 /// Generic URI resolver tests which do not depend on the particular path | 15 /// Generic URI resolver tests which do not depend on the particular path |
| 24 /// context in use. | 16 /// context in use. |
| 25 @reflectiveTest | 17 @reflectiveTest |
| 26 class FileRepositoryTest { | 18 class FileRepositoryTest { |
| 27 final fileRepository = new FileRepository(); | 19 final fileRepository = new FileRepository(); |
| 28 | 20 |
| 21 test_clearContents() { |
| 22 var uri = Uri.parse('file:///foo/bar.dart'); |
| 23 fileRepository.store(uri, 'contents1'); |
| 24 expect(fileRepository.getContentsForTesting(), isNotEmpty); |
| 25 fileRepository.clearContents(); |
| 26 expect(fileRepository.getContentsForTesting(), isEmpty); |
| 27 } |
| 28 |
| 29 test_contentsForPath() { | 29 test_contentsForPath() { |
| 30 var path1 = | 30 var path1 = |
| 31 fileRepository.store(Uri.parse('file:///foo/bar.dart'), 'contents1'); | 31 fileRepository.store(Uri.parse('file:///foo/bar.dart'), 'contents1'); |
| 32 var path2 = | 32 var path2 = |
| 33 fileRepository.store(Uri.parse('package:foo/bar.dart'), 'contents2'); | 33 fileRepository.store(Uri.parse('package:foo/bar.dart'), 'contents2'); |
| 34 expect(fileRepository.contentsForPath(path1), 'contents1'); | 34 expect(fileRepository.contentsForPath(path1), 'contents1'); |
| 35 expect(fileRepository.contentsForPath(path2), 'contents2'); | 35 expect(fileRepository.contentsForPath(path2), 'contents2'); |
| 36 } | 36 } |
| 37 | 37 |
| 38 test_pathForUri() { | 38 test_pathForUri() { |
| 39 var uri1 = Uri.parse('file:///foo/bar.dart'); | 39 var uri1 = Uri.parse('file:///foo/bar.dart'); |
| 40 var path1 = fileRepository.store(uri1, 'contents1'); | 40 var path1 = fileRepository.store(uri1, 'contents1'); |
| 41 var uri2 = Uri.parse('package:foo/bar.dart'); | 41 var uri2 = Uri.parse('package:foo/bar.dart'); |
| 42 var path2 = fileRepository.store(uri2, 'contents2'); | 42 var path2 = fileRepository.store(uri2, 'contents2'); |
| 43 expect(fileRepository.pathForUri(uri1), path1); | 43 expect(fileRepository.pathForUri(uri1), path1); |
| 44 expect(fileRepository.pathForUri(uri2), path2); | 44 expect(fileRepository.pathForUri(uri2), path2); |
| 45 } | 45 } |
| 46 | 46 |
| 47 test_store() { | 47 test_store() { |
| 48 var uri = Uri.parse('file:///foo/bar.dart'); | 48 var uri = Uri.parse('file:///foo/bar.dart'); |
| 49 var path = fileRepository.store(uri, 'contents1'); | 49 var path = fileRepository.store(uri, 'contents1'); |
| 50 expect(path, endsWith('.dart')); | 50 expect(path, endsWith('.dart')); |
| 51 expect(fileRepository.contentsForPath(path), 'contents1'); | 51 expect(fileRepository.contentsForPath(path), 'contents1'); |
| 52 expect(fileRepository.getContentsForTesting(), {path: 'contents1'}); |
| 52 expect(fileRepository.store(uri, 'contents2'), path); | 53 expect(fileRepository.store(uri, 'contents2'), path); |
| 53 expect(fileRepository.contentsForPath(path), 'contents2'); | 54 expect(fileRepository.contentsForPath(path), 'contents2'); |
| 55 expect(fileRepository.getContentsForTesting(), {path: 'contents2'}); |
| 54 } | 56 } |
| 55 | 57 |
| 56 test_uriForPath() { | 58 test_uriForPath() { |
| 57 var uri1 = Uri.parse('file:///foo/bar.dart'); | 59 var uri1 = Uri.parse('file:///foo/bar.dart'); |
| 58 var path1 = fileRepository.store(uri1, 'contents1'); | 60 var path1 = fileRepository.store(uri1, 'contents1'); |
| 59 var uri2 = Uri.parse('package:foo/bar.dart'); | 61 var uri2 = Uri.parse('package:foo/bar.dart'); |
| 60 var path2 = fileRepository.store(uri2, 'contents2'); | 62 var path2 = fileRepository.store(uri2, 'contents2'); |
| 61 expect(fileRepository.uriForPath(path1), uri1); | 63 expect(fileRepository.uriForPath(path1), uri1); |
| 62 expect(fileRepository.uriForPath(path2), uri2); | 64 expect(fileRepository.uriForPath(path2), uri2); |
| 63 } | 65 } |
| 64 } | 66 } |
| OLD | NEW |