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

Side by Side Diff: pkg/analysis_server/test/src/computer/import_elements_computer_test.dart

Issue 2965243002: Add unit tests for copy/paste support (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/src/computer/imported_elements_computer_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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:analysis_server/protocol/protocol_generated.dart';
6 import 'package:analysis_server/src/computer/import_elements_computer.dart';
7 import 'package:analyzer/dart/analysis/results.dart';
8 import 'package:analyzer_plugin/protocol/protocol_common.dart';
9 import 'package:test/test.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart';
11
12 import '../../abstract_context.dart';
13
14 main() {
15 defineReflectiveSuite(() {
16 defineReflectiveTests(ImportElementsComputerTest);
17 });
18 }
19
20 /**
21 * Tests that the [ImportElementsComputer] will correctly update imports. The
22 * tests are generally labeled based on the kind of import in the source (from
23 * which the text was copied) and the kind of import in the target (into which
24 * the text was pasted). Kinds are a combination of "prefix", "hide", "show" and
25 * "deferred", or "bare" when there are none of the previous, or "none" when
26 * there is no import.
27 */
28 @reflectiveTest
29 class ImportElementsComputerTest extends AbstractContextTest {
30 String targetPath;
31 String targetCode;
32
33 ResolveResult result;
34
35 setUp() async {
36 super.setUp();
37 packageMap['p'] = [provider.newFolder(provider.convertPath('/p/lib'))];
38 targetPath = provider.convertPath('/p/lib/target.dart');
39 targetCode = '''
40 main() {}
41 ''';
42 provider.newFile(targetPath, targetCode);
43 result = await driver.getResult(targetPath);
44 }
45
46 @failingTest
47 test_bare_none() {
48 List<ImportedElements> elements = <ImportedElements>[
49 new ImportedElements(provider.convertPath('/p/lib/a.dart'),
50 'package:p/a.dart', '', <String>['A']),
51 ];
52 List<SourceEdit> edits = _computeEditsFor(elements);
53 expect(edits, hasLength(1));
54 SourceEdit edit = edits[0];
55 expect(edit, isNotNull);
56 expect(edit.offset, 0);
57 expect(edit.length, 0);
58 expect(
59 edit.apply(targetCode),
60 """
61 import 'source.dart';
62
63 main() {}
64 """);
65 }
66
67 test_none_none() {
68 List<ImportedElements> elements = <ImportedElements>[];
69 List<SourceEdit> edits = _computeEditsFor(elements);
70 expect(edits, hasLength(0));
71 }
72
73 List<SourceEdit> _computeEditsFor(List<ImportedElements> elements) {
74 ImportElementsComputer computer =
75 new ImportElementsComputer(result, targetPath, elements);
76 return computer.compute();
77 }
78 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698