OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 return null; | 66 return null; |
67 } | 67 } |
68 | 68 |
69 private int selectionOffset = 0; | 69 private int selectionOffset = 0; |
70 private int selectionLength = 0; | 70 private int selectionLength = 0; |
71 | 71 |
72 private SourceCorrectionProposal resultProposal; | 72 private SourceCorrectionProposal resultProposal; |
73 private String resultSource; | 73 private String resultSource; |
74 | 74 |
75 public void test_addJson_ignoreOtherLibraryPrivates() throws Exception { | |
76 addSource( | |
77 "/my_lib.dart", | |
78 makeSource( | |
79 "// filler filler filler filler filler filler filler filler filler f
iller", | |
80 "library lib;", | |
81 "class HasCost {", | |
82 " int _cost;", | |
83 "}")); | |
84 String initial = makeSource( | |
85 "// filler filler filler filler filler filler filler filler filler fille
r", | |
86 "import 'my_lib.dart';", | |
87 "class Unit extends HasCost {", | |
88 " int health;", | |
89 " int mana;", | |
90 "}"); | |
91 String expected = makeSource( | |
92 "// filler filler filler filler filler filler filler filler filler fille
r", | |
93 "import 'my_lib.dart';", | |
94 "class Unit extends HasCost {", | |
95 " int health;", | |
96 " int mana;", | |
97 "", | |
98 " Unit.fromJson(Map json) {", | |
99 " health = json['health'];", | |
100 " mana = json['mana'];", | |
101 " }", | |
102 "", | |
103 " Map toJson() {", | |
104 " return {'health' : health, 'mana' : mana};", | |
105 " }", | |
106 "}"); | |
107 assert_addJson(initial, "class Unit", expected); | |
108 } | |
109 | |
110 public void test_addJson_insert() throws Exception { | |
111 String initial = makeSource( | |
112 "// filler filler filler filler filler filler filler filler filler fille
r", | |
113 "class HasCost {", | |
114 " int cost;", | |
115 "}", | |
116 "class Unit extends HasCost {", | |
117 " int health;", | |
118 " int mana;", | |
119 "}"); | |
120 String expected = makeSource( | |
121 "// filler filler filler filler filler filler filler filler filler fille
r", | |
122 "class HasCost {", | |
123 " int cost;", | |
124 "}", | |
125 "class Unit extends HasCost {", | |
126 " int health;", | |
127 " int mana;", | |
128 "", | |
129 " Unit.fromJson(Map json) {", | |
130 " cost = json['cost'];", | |
131 " health = json['health'];", | |
132 " mana = json['mana'];", | |
133 " }", | |
134 "", | |
135 " Map toJson() {", | |
136 " return {'cost' : cost, 'health' : health, 'mana' : mana};", | |
137 " }", | |
138 "}"); | |
139 assert_addJson(initial, "class Unit", expected); | |
140 assert_addJson(initial, "Unit extends", expected); | |
141 } | |
142 | |
143 public void test_addJson_noFields() throws Exception { | |
144 String initial = makeSource( | |
145 "// filler filler filler filler filler filler filler filler filler fille
r", | |
146 "class Unit {", | |
147 " void attack() {}", | |
148 "}"); | |
149 String expected = makeSource( | |
150 "// filler filler filler filler filler filler filler filler filler fille
r", | |
151 "class Unit {", | |
152 " void attack() {}", | |
153 "}"); | |
154 assert_addJson(initial, "class Unit", expected); | |
155 } | |
156 | |
157 public void test_addJson_replace() throws Exception { | |
158 String initial = makeSource( | |
159 "// filler filler filler filler filler filler filler filler filler fille
r", | |
160 "class HasCost {", | |
161 " int cost;", | |
162 "}", | |
163 "class Unit extends HasCost {", | |
164 " int health;", | |
165 " int mana;", | |
166 "", | |
167 " Unit.fromJson(Map json) {", | |
168 " // empty", | |
169 " }", | |
170 "", | |
171 " Map toJson() {", | |
172 " // empty", | |
173 " }", | |
174 "}"); | |
175 String expected = makeSource( | |
176 "// filler filler filler filler filler filler filler filler filler fille
r", | |
177 "class HasCost {", | |
178 " int cost;", | |
179 "}", | |
180 "class Unit extends HasCost {", | |
181 " int health;", | |
182 " int mana;", | |
183 "", | |
184 " Unit.fromJson(Map json) {", | |
185 " cost = json['cost'];", | |
186 " health = json['health'];", | |
187 " mana = json['mana'];", | |
188 " }", | |
189 "", | |
190 " Map toJson() {", | |
191 " return {'cost' : cost, 'health' : health, 'mana' : mana};", | |
192 " }", | |
193 "}"); | |
194 assert_addJson(initial, "class Unit", expected); | |
195 } | |
196 | |
197 public void test_addPartDirective() throws Exception { | 75 public void test_addPartDirective() throws Exception { |
198 String libCode = makeSource( | 76 String libCode = makeSource( |
199 "// filler filler filler filler filler filler filler filler filler fille
r", | 77 "// filler filler filler filler filler filler filler filler filler fille
r", |
200 "library app;"); | 78 "library app;"); |
201 String testCode = makeSource( | 79 String testCode = makeSource( |
202 "// filler filler filler filler filler filler filler filler filler fille
r", | 80 "// filler filler filler filler filler filler filler filler filler fille
r", |
203 "part of app;"); | 81 "part of app;"); |
204 // add sources | 82 // add sources |
205 addSource("/my_app.dart", libCode); | 83 addSource("/my_app.dart", libCode); |
206 Source testSource = addSource("/test.dart", testCode); | 84 Source testSource = addSource("/test.dart", testCode); |
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2132 "// start", | 2010 "// start", |
2133 " while (condition) {", | 2011 " while (condition) {", |
2134 " print(0);", | 2012 " print(0);", |
2135 " print(1);", | 2013 " print(1);", |
2136 " }", | 2014 " }", |
2137 "// end", | 2015 "// end", |
2138 "}"); | 2016 "}"); |
2139 assert_surroundsWith(initial, CorrectionKind.QA_SURROUND_WITH_WHILE, expecte
d); | 2017 assert_surroundsWith(initial, CorrectionKind.QA_SURROUND_WITH_WHILE, expecte
d); |
2140 } | 2018 } |
2141 | 2019 |
2142 private void assert_addJson(String initialSource, String offsetPattern, String
expectedSource) | |
2143 throws Exception { | |
2144 assert_runProcessor(CorrectionKind.QA_ADD_JSON, initialSource, offsetPattern
, expectedSource); | |
2145 } | |
2146 | |
2147 private void assert_addTypeAnnotation(String initialSource, String offsetPatte
rn, | 2020 private void assert_addTypeAnnotation(String initialSource, String offsetPatte
rn, |
2148 String expectedSource) throws Exception { | 2021 String expectedSource) throws Exception { |
2149 assert_runProcessor( | 2022 assert_runProcessor( |
2150 CorrectionKind.QA_ADD_TYPE_ANNOTATION, | 2023 CorrectionKind.QA_ADD_TYPE_ANNOTATION, |
2151 initialSource, | 2024 initialSource, |
2152 offsetPattern, | 2025 offsetPattern, |
2153 expectedSource); | 2026 expectedSource); |
2154 } | 2027 } |
2155 | 2028 |
2156 private void assert_addTypeAnnotation_classField(String initialDeclaration, St
ring offsetPattern, | 2029 private void assert_addTypeAnnotation_classField(String initialDeclaration, St
ring offsetPattern, |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2503 ranges.add(getResultRange(wordPattern)); | 2376 ranges.add(getResultRange(wordPattern)); |
2504 } | 2377 } |
2505 return ranges; | 2378 return ranges; |
2506 } | 2379 } |
2507 | 2380 |
2508 private void setSelectionFromStartEndComments() throws Exception { | 2381 private void setSelectionFromStartEndComments() throws Exception { |
2509 selectionOffset = findEnd("// start") + EOL.length(); | 2382 selectionOffset = findEnd("// start") + EOL.length(); |
2510 selectionLength = findOffset("// end") - selectionOffset; | 2383 selectionLength = findOffset("// end") - selectionOffset; |
2511 } | 2384 } |
2512 } | 2385 } |
OLD | NEW |