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

Side by Side Diff: pkg/analysis_services/test/refactoring/abstract_refactoring.dart

Issue 484733003: Import analysis_services.dart into analysis_server.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.services.refactoring.rename;
6
7 import 'dart:async';
8
9 import 'package:analysis_services/correction/change.dart';
10 import 'package:analysis_services/correction/status.dart';
11 import 'package:analysis_services/index/index.dart';
12 import 'package:analysis_services/index/local_memory_index.dart';
13 import 'package:analysis_services/refactoring/refactoring.dart';
14 import 'package:analysis_services/src/search/search_engine.dart';
15 import 'package:analysis_testing/abstract_single_unit.dart';
16 import 'package:analyzer/src/generated/ast.dart';
17 import 'package:analyzer/src/generated/source.dart';
18 import 'package:unittest/unittest.dart';
19
20
21 int findIdentifierLength(String search) {
22 int length = 0;
23 while (length < search.length) {
24 int c = search.codeUnitAt(length);
25 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) ||
26 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) ||
27 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) {
28 break;
29 }
30 length++;
31 }
32 return length;
33 }
34
35
36 /**
37 * The base class for all [Refactoring] tests.
38 */
39 abstract class RefactoringTest extends AbstractSingleUnitTest {
40 Index index;
41 SearchEngineImpl searchEngine;
42
43 Change refactoringChange;
44
45 Refactoring get refactoring;
46
47 /**
48 * Asserts that [refactoring] initial/final conditions status is OK.
49 */
50 Future assertRefactoringConditionsOK() {
51 return refactoring.checkInitialConditions().then((status) {
52 assertRefactoringStatusOK(status);
53 return refactoring.checkFinalConditions().then((status) {
54 assertRefactoringStatusOK(status);
55 });
56 });
57 }
58
59 /**
60 * Asserts that [status] has expected severity and message.
61 */
62 void assertRefactoringStatus(RefactoringStatus status,
63 RefactoringStatusSeverity expectedSeverity, {String expectedMessage,
64 SourceRange expectedContextRange, String expectedContextSearch}) {
65 expect(status.severity, expectedSeverity, reason: status.message);
66 if (expectedSeverity != RefactoringStatusSeverity.OK) {
67 RefactoringStatusEntry entry = status.entryWithHighestSeverity;
68 expect(entry.severity, expectedSeverity);
69 if (expectedMessage != null) {
70 expect(entry.message, expectedMessage);
71 }
72 if (expectedContextRange != null) {
73 expect(entry.context.range, expectedContextRange);
74 }
75 if (expectedContextSearch != null) {
76 SourceRange contextRange = entry.context.range;
77 int expectedOffset = findOffset(expectedContextSearch);
78 int expectedLength = findIdentifierLength(expectedContextSearch);
79 expect(contextRange.offset, expectedOffset);
80 expect(contextRange.length, expectedLength);
81 }
82 }
83 }
84
85 /**
86 * Asserts that [refactoring] status is OK.
87 */
88 void assertRefactoringStatusOK(RefactoringStatus status) {
89 assertRefactoringStatus(status, RefactoringStatusSeverity.OK);
90 }
91
92 void indexTestUnit(String code) {
93 resolveTestUnit(code);
94 index.indexUnit(context, testUnit);
95 }
96
97 void indexUnit(String file, String code) {
98 Source source = addSource(file, code);
99 CompilationUnit unit = resolveLibraryUnit(source);
100 index.indexUnit(context, unit);
101 }
102
103 void setUp() {
104 super.setUp();
105 index = createLocalMemoryIndex();
106 searchEngine = new SearchEngineImpl(index);
107 }
108 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/test/index/test_all.dart ('k') | pkg/analysis_services/test/refactoring/abstract_rename.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698