| 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.services.correction.change; | 5 library test.services.correction.change; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/constants.dart'; | 7 import 'package:analysis_server/src/constants.dart'; |
| 8 import 'package:analysis_server/src/protocol.dart'; | 8 import 'package:analysis_server/src/protocol_server.dart'; |
| 9 import '../../reflective_tests.dart'; | |
| 10 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 12 | 11 |
| 12 import '../../reflective_tests.dart'; |
| 13 |
| 13 | 14 |
| 14 main() { | 15 main() { |
| 15 groupSep = ' | '; | 16 groupSep = ' | '; |
| 16 runReflectiveTests(ChangeTest); | 17 runReflectiveTests(ChangeTest); |
| 17 runReflectiveTests(EditTest); | 18 runReflectiveTests(EditTest); |
| 18 runReflectiveTests(FileEditTest); | 19 runReflectiveTests(FileEditTest); |
| 19 runReflectiveTests(LinkedEditGroupTest); | 20 runReflectiveTests(LinkedEditGroupTest); |
| 20 runReflectiveTests(LinkedEditSuggestionTest); | 21 runReflectiveTests(LinkedEditSuggestionTest); |
| 21 runReflectiveTests(PositionTest); | 22 runReflectiveTests(PositionTest); |
| 22 } | 23 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 change.toString(); | 139 change.toString(); |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 | 142 |
| 142 | 143 |
| 143 @ReflectiveTestCase() | 144 @ReflectiveTestCase() |
| 144 class EditTest { | 145 class EditTest { |
| 145 void test_applySequence() { | 146 void test_applySequence() { |
| 146 SourceEdit edit1 = new SourceEdit(5, 2, 'abc'); | 147 SourceEdit edit1 = new SourceEdit(5, 2, 'abc'); |
| 147 SourceEdit edit2 = new SourceEdit(1, 0, '!'); | 148 SourceEdit edit2 = new SourceEdit(1, 0, '!'); |
| 148 expect(SourceEdit.applySequence('0123456789', [edit1, edit2]), '0!1234abc789
'); | 149 expect( |
| 150 SourceEdit.applySequence('0123456789', [edit1, edit2]), |
| 151 '0!1234abc789'); |
| 152 } |
| 153 |
| 154 void test_editFromRange() { |
| 155 SourceRange range = new SourceRange(1, 2); |
| 156 SourceEdit edit = newSourceEdit_range(range, 'foo'); |
| 157 expect(edit.offset, 1); |
| 158 expect(edit.length, 2); |
| 159 expect(edit.replacement, 'foo'); |
| 149 } | 160 } |
| 150 | 161 |
| 151 void test_eqEq() { | 162 void test_eqEq() { |
| 152 SourceEdit a = new SourceEdit(1, 2, 'aaa'); | 163 SourceEdit a = new SourceEdit(1, 2, 'aaa'); |
| 153 SourceEdit a2 = new SourceEdit(1, 2, 'aaa'); | 164 SourceEdit a2 = new SourceEdit(1, 2, 'aaa'); |
| 154 SourceEdit b = new SourceEdit(1, 2, 'aaa'); | 165 SourceEdit b = new SourceEdit(1, 2, 'aaa'); |
| 155 expect(a == a, isTrue); | 166 expect(a == a, isTrue); |
| 156 expect(a == new SourceEdit(1, 2, 'aaa'), isTrue); | 167 expect(a == new SourceEdit(1, 2, 'aaa'), isTrue); |
| 157 expect(a == this, isFalse); | 168 expect(a == this, isFalse); |
| 158 expect(a == new SourceEdit(1, 2, 'bbb'), isFalse); | 169 expect(a == new SourceEdit(1, 2, 'bbb'), isFalse); |
| 159 expect(a == new SourceEdit(10, 2, 'aaa'), isFalse); | 170 expect(a == new SourceEdit(10, 2, 'aaa'), isFalse); |
| 160 } | 171 } |
| 161 | 172 |
| 162 void test_new() { | 173 void test_new() { |
| 163 SourceEdit edit = new SourceEdit(1, 2, 'foo', id: 'my-id'); | 174 SourceEdit edit = new SourceEdit(1, 2, 'foo', id: 'my-id'); |
| 164 expect(edit.offset, 1); | 175 expect(edit.offset, 1); |
| 165 expect(edit.length, 2); | 176 expect(edit.length, 2); |
| 166 expect(edit.replacement, 'foo'); | 177 expect(edit.replacement, 'foo'); |
| 167 expect( | 178 expect(edit.toJson(), { |
| 168 edit.toJson(), | 179 'offset': 1, |
| 169 {'offset': 1, 'length': 2, 'replacement': 'foo', 'id': 'my-id'}); | 180 'length': 2, |
| 170 } | 181 'replacement': 'foo', |
| 171 | 182 'id': 'my-id' |
| 172 void test_editFromRange() { | 183 }); |
| 173 SourceRange range = new SourceRange(1, 2); | |
| 174 SourceEdit edit = new SourceEdit.range(range, 'foo'); | |
| 175 expect(edit.offset, 1); | |
| 176 expect(edit.length, 2); | |
| 177 expect(edit.replacement, 'foo'); | |
| 178 } | 184 } |
| 179 void test_toJson() { | 185 void test_toJson() { |
| 180 SourceEdit edit = new SourceEdit(1, 2, 'foo'); | 186 SourceEdit edit = new SourceEdit(1, 2, 'foo'); |
| 181 var expectedJson = { | 187 var expectedJson = { |
| 182 OFFSET: 1, | 188 OFFSET: 1, |
| 183 LENGTH: 2, | 189 LENGTH: 2, |
| 184 REPLACEMENT: 'foo' | 190 REPLACEMENT: 'foo' |
| 185 }; | 191 }; |
| 186 expect(edit.toJson(), expectedJson); | 192 expect(edit.toJson(), expectedJson); |
| 187 } | 193 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 254 |
| 249 | 255 |
| 250 @ReflectiveTestCase() | 256 @ReflectiveTestCase() |
| 251 class LinkedEditGroupTest { | 257 class LinkedEditGroupTest { |
| 252 void test_new() { | 258 void test_new() { |
| 253 LinkedEditGroup group = new LinkedEditGroup.empty(); | 259 LinkedEditGroup group = new LinkedEditGroup.empty(); |
| 254 group.addPosition(new Position('/a.dart', 1), 2); | 260 group.addPosition(new Position('/a.dart', 1), 2); |
| 255 group.addPosition(new Position('/b.dart', 10), 2); | 261 group.addPosition(new Position('/b.dart', 10), 2); |
| 256 expect( | 262 expect( |
| 257 group.toString(), | 263 group.toString(), |
| 258 '{"positions":[' | 264 '{"positions":[' '{"file":"/a.dart","offset":1},' |
| 259 '{"file":"/a.dart","offset":1},' | |
| 260 '{"file":"/b.dart","offset":10}],"length":2,"suggestions":[]}'); | 265 '{"file":"/b.dart","offset":10}],"length":2,"suggestions":[]}'); |
| 261 } | 266 } |
| 262 | 267 |
| 263 void test_toJson() { | 268 void test_toJson() { |
| 264 LinkedEditGroup group = new LinkedEditGroup.empty(); | 269 LinkedEditGroup group = new LinkedEditGroup.empty(); |
| 265 group.addPosition(new Position('/a.dart', 1), 2); | 270 group.addPosition(new Position('/a.dart', 1), 2); |
| 266 group.addPosition(new Position('/b.dart', 10), 2); | 271 group.addPosition(new Position('/b.dart', 10), 2); |
| 267 group.addSuggestion( | 272 group.addSuggestion( |
| 268 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE)); | 273 new LinkedEditSuggestion('AA', LinkedEditSuggestionKind.TYPE)); |
| 269 group.addSuggestion( | 274 group.addSuggestion( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 336 |
| 332 void test_toJson() { | 337 void test_toJson() { |
| 333 Position position = new Position('/test.dart', 1); | 338 Position position = new Position('/test.dart', 1); |
| 334 var expectedJson = { | 339 var expectedJson = { |
| 335 FILE: '/test.dart', | 340 FILE: '/test.dart', |
| 336 OFFSET: 1 | 341 OFFSET: 1 |
| 337 }; | 342 }; |
| 338 expect(position.toJson(), expectedJson); | 343 expect(position.toJson(), expectedJson); |
| 339 } | 344 } |
| 340 } | 345 } |
| OLD | NEW |