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

Unified Diff: pkg/analysis_services/test/correction/change_test.dart

Issue 447613002: Make Change implementation consistent with the server spec. (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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_services/test/correction/change_test.dart
diff --git a/pkg/analysis_services/test/correction/change_test.dart b/pkg/analysis_services/test/correction/change_test.dart
index 895454bf9b80d5ba5ac56cc45d71a4e26380ab4b..9982edb4d3cd725af5eaea9e7f1891da7d85f4a7 100644
--- a/pkg/analysis_services/test/correction/change_test.dart
+++ b/pkg/analysis_services/test/correction/change_test.dart
@@ -18,129 +18,14 @@ main() {
runReflectiveTests(ChangeTest);
runReflectiveTests(EditTest);
runReflectiveTests(FileEditTest);
- runReflectiveTests(LinkedPositionGroupTest);
+ runReflectiveTests(LinkedEditGroupTest);
+ runReflectiveTests(LinkedEditSuggestionTest);
runReflectiveTests(PositionTest);
}
@ReflectiveTestCase()
class ChangeTest {
- void test_fromJson() {
- var json = {
- MESSAGE: 'msg',
- EDITS: [{
- FILE: '/a.dart',
- EDITS: [{
- OFFSET: 1,
- LENGTH: 2,
- REPLACEMENT: 'aaa'
- }, {
- OFFSET: 10,
- LENGTH: 20,
- REPLACEMENT: 'bbb'
- }]
- }, {
- FILE: '/b.dart',
- EDITS: [{
- OFFSET: 21,
- LENGTH: 22,
- REPLACEMENT: 'xxx'
- }, {
- OFFSET: 210,
- LENGTH: 220,
- REPLACEMENT: 'yyy'
- }]
- }],
- LINKED_POSITION_GROUPS: [{
- ID: 'id-a',
- POSITIONS: [{
- FILE: '/ga.dart',
- OFFSET: 1,
- LENGTH: 2
- }, {
- FILE: '/ga.dart',
- OFFSET: 10,
- LENGTH: 2
- }]
- }, {
- ID: 'id-b',
- POSITIONS: [{
- FILE: '/gb.dart',
- OFFSET: 10,
- LENGTH: 5
- }, {
- FILE: '/gb.dart',
- OFFSET: 100,
- LENGTH: 5
- }]
- }]
- };
- Change change = Change.fromJson(json);
- expect(change.message, 'msg');
- // edits
- expect(change.edits, hasLength(2));
- {
- FileEdit fileEdit = change.edits[0];
- expect(fileEdit.file, '/a.dart');
- expect(fileEdit.edits, hasLength(2));
- expect(fileEdit.edits[0], new Edit(1, 2, 'aaa'));
- expect(fileEdit.edits[1], new Edit(10, 20, 'bbb'));
- }
- {
- FileEdit fileEdit = change.edits[1];
- expect(fileEdit.file, '/b.dart');
- expect(fileEdit.edits, hasLength(2));
- expect(fileEdit.edits[0], new Edit(21, 22, 'xxx'));
- expect(fileEdit.edits[1], new Edit(210, 220, 'yyy'));
- }
- // linked position groups
- expect(change.linkedPositionGroups, hasLength(2));
- {
- LinkedPositionGroup group = change.linkedPositionGroups[0];
- expect(group.id, 'id-a');
- expect(group.positions, hasLength(2));
- expect(group.positions[0], new Position('/ga.dart', 1, 2));
- expect(group.positions[1], new Position('/ga.dart', 10, 2));
- }
- {
- LinkedPositionGroup group = change.linkedPositionGroups[1];
- expect(group.id, 'id-b');
- expect(group.positions, hasLength(2));
- expect(group.positions[0], new Position('/gb.dart', 10, 5));
- expect(group.positions[1], new Position('/gb.dart', 100, 5));
- }
- }
-
- void test_new() {
- Change change = new Change('msg');
- change.add(new FileEdit('/a.dart')
- ..add(new Edit(1, 2, 'aaa'))
- ..add(new Edit(10, 20, 'bbb')));
- change.add(new FileEdit('/b.dart')
- ..add(new Edit(21, 22, 'xxx'))
- ..add(new Edit(210, 220, 'yyy')));
- change.addLinkedPositionGroup(new LinkedPositionGroup('id-a')
- ..addPosition(new Position('/ga.dart', 1, 2))
- ..addPosition(new Position('/ga.dart', 10, 2)));
- change.addLinkedPositionGroup(new LinkedPositionGroup('id-b')
- ..addPosition(new Position('/gb.dart', 10, 5))
- ..addPosition(new Position('/gb.dart', 100, 5)));
- expect(
- change.toString(),
- 'Change(message=msg, edits=[FileEdit(file=/a.dart, edits=['
- 'Edit(offset=1, length=2, replacement=:>aaa<:), '
- 'Edit(offset=10, length=20, replacement=:>bbb<:)]), '
- 'FileEdit(file=/b.dart, edits=['
- 'Edit(offset=21, length=22, replacement=:>xxx<:), '
- 'Edit(offset=210, length=220, replacement=:>yyy<:)])], '
- 'linkedPositionGroups=[' 'LinkedPositionGroup(id=id-a, positions=['
- 'Position(file=/ga.dart, offset=1, length=2), '
- 'Position(file=/ga.dart, offset=10, length=2)]), '
- 'LinkedPositionGroup(id=id-b, positions=['
- 'Position(file=/gb.dart, offset=10, length=5), '
- 'Position(file=/gb.dart, offset=100, length=5)])])');
- }
-
void test_toJson() {
Change change = new Change('msg');
change.add(new FileEdit('/a.dart')
@@ -149,62 +34,77 @@ class ChangeTest {
change.add(new FileEdit('/b.dart')
..add(new Edit(21, 22, 'xxx'))
..add(new Edit(210, 220, 'yyy')));
- change.addLinkedPositionGroup(new LinkedPositionGroup('id-a')
- ..addPosition(new Position('/ga.dart', 1, 2))
- ..addPosition(new Position('/ga.dart', 10, 2)));
- change.addLinkedPositionGroup(new LinkedPositionGroup('id-b')
- ..addPosition(new Position('/gb.dart', 10, 5))
- ..addPosition(new Position('/gb.dart', 100, 5)));
+ {
+ var group = new LinkedEditGroup('id-a');
+ change.addLinkedEditGroup(group
+ ..addPosition(new Position('/ga.dart', 1), 2)
+ ..addPosition(new Position('/ga.dart', 10), 2));
+ group.addSuggestion(
+ new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA'));
+ group.addSuggestion(
+ new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB'));
+ }
+ change.addLinkedEditGroup(new LinkedEditGroup('id-b')
+ ..addPosition(new Position('/gb.dart', 10), 5)
+ ..addPosition(new Position('/gb.dart', 100), 5));
var expectedJson = {
- MESSAGE: 'msg',
- EDITS: [{
- FILE: '/a.dart',
- EDITS: [{
- OFFSET: 1,
- LENGTH: 2,
- REPLACEMENT: 'aaa'
+ 'message': 'msg',
+ 'edits': [{
+ 'file': '/a.dart',
+ 'edits': [{
+ 'offset': 1,
+ 'length': 2,
+ 'relacement': 'aaa'
}, {
- OFFSET: 10,
- LENGTH: 20,
- REPLACEMENT: 'bbb'
+ 'offset': 10,
+ 'length': 20,
+ 'relacement': 'bbb'
}]
}, {
- FILE: '/b.dart',
- EDITS: [{
- OFFSET: 21,
- LENGTH: 22,
- REPLACEMENT: 'xxx'
+ 'file': '/b.dart',
+ 'edits': [{
+ 'offset': 21,
+ 'length': 22,
+ 'relacement': 'xxx'
}, {
- OFFSET: 210,
- LENGTH: 220,
- REPLACEMENT: 'yyy'
+ 'offset': 210,
+ 'length': 220,
+ 'relacement': 'yyy'
}]
}],
- LINKED_POSITION_GROUPS: [{
- ID: 'id-a',
- POSITIONS: [{
- FILE: '/ga.dart',
- OFFSET: 1,
- LENGTH: 2
+ 'linkedEditGroups': [{
+ 'id': 'id-a',
+ 'length': 2,
+ 'positions': [{
+ 'file': '/ga.dart',
+ 'offset': 1
}, {
- FILE: '/ga.dart',
- OFFSET: 10,
- LENGTH: 2
+ 'file': '/ga.dart',
+ 'offset': 10
+ }],
+ 'suggestions': [{
+ 'kind': 'TYPE',
+ 'value': 'AA'
+ }, {
+ 'kind': 'TYPE',
+ 'value': 'BB'
}]
}, {
- ID: 'id-b',
- POSITIONS: [{
- FILE: '/gb.dart',
- OFFSET: 10,
- LENGTH: 5
+ 'id': 'id-b',
+ 'length': 5,
+ 'positions': [{
+ 'file': '/gb.dart',
+ 'offset': 10
}, {
- FILE: '/gb.dart',
- OFFSET: 100,
- LENGTH: 5
- }]
+ 'file': '/gb.dart',
+ 'offset': 100
+ }],
+ 'suggestions': []
}]
};
expect(change.toJson(), expectedJson);
+ // some toString()
+ change.toString();
}
}
@@ -216,18 +116,6 @@ class EditTest {
expect(edit.end, 3);
}
- void test_fromJson() {
- var json = {
- OFFSET: 1,
- LENGTH: 2,
- REPLACEMENT: 'foo'
- };
- Edit edit = Edit.fromJson(json);
- expect(edit.offset, 1);
- expect(edit.length, 2);
- expect(edit.replacement, 'foo');
- }
-
void test_new() {
Edit edit = new Edit(1, 2, 'foo');
expect(edit.offset, 1);
@@ -261,26 +149,6 @@ class EditTest {
@ReflectiveTestCase()
class FileEditTest {
- void test_fromJson() {
- var json = {
- FILE: '/test.dart',
- EDITS: [{
- OFFSET: 1,
- LENGTH: 2,
- REPLACEMENT: 'aaa'
- }, {
- OFFSET: 10,
- LENGTH: 20,
- REPLACEMENT: 'bbb'
- },]
- };
- var fileEdit = FileEdit.fromJson(json);
- expect(fileEdit.file, '/test.dart');
- expect(fileEdit.edits, hasLength(2));
- expect(fileEdit.edits[0], new Edit(1, 2, 'aaa'));
- expect(fileEdit.edits[1], new Edit(10, 20, 'bbb'));
- }
-
void test_new() {
FileEdit fileEdit = new FileEdit('/test.dart');
fileEdit.add(new Edit(1, 2, 'aaa'));
@@ -296,7 +164,7 @@ class FileEditTest {
FileEdit fileEdit = new FileEdit('/test.dart');
fileEdit.add(new Edit(1, 2, 'aaa'));
fileEdit.add(new Edit(10, 20, 'bbb'));
- expect(fileEdit.toJson(), {
+ var expectedJson = {
FILE: '/test.dart',
EDITS: [{
OFFSET: 1,
@@ -307,69 +175,67 @@ class FileEditTest {
LENGTH: 20,
REPLACEMENT: 'bbb'
},]
- });
+ };
+ expect(fileEdit.toJson(), expectedJson);
}
}
@ReflectiveTestCase()
-class LinkedPositionGroupTest {
- void test_addWrongLength() {
- LinkedPositionGroup group = new LinkedPositionGroup('my-id');
- group.addPosition(new Position('/a.dart', 1, 2));
- expect(() {
- group.addPosition(new Position('/b.dart', 10, 20));
- }, throws);
+class LinkedEditSuggestionTest {
+ void test_eqEq() {
+ var a = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'a');
+ var a2 = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'a');
+ var b = new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'a');
+ var c = new LinkedEditSuggestion(LinkedEditSuggestionKind.METHOD, 'c');
+ expect(a == a, isTrue);
+ expect(a == a2, isTrue);
+ expect(a == this, isFalse);
+ expect(a == b, isFalse);
+ expect(a == c, isFalse);
}
+}
- void test_fromJson() {
- var json = {
- ID: 'my-id',
- POSITIONS: [{
- FILE: '/a.dart',
- OFFSET: 1,
- LENGTH: 2
- }, {
- FILE: '/b.dart',
- OFFSET: 10,
- LENGTH: 2
- }]
- };
- LinkedPositionGroup group = LinkedPositionGroup.fromJson(json);
- expect(group.id, 'my-id');
- expect(group.positions, hasLength(2));
- expect(group.positions[0], new Position('/a.dart', 1, 2));
- expect(group.positions[1], new Position('/b.dart', 10, 2));
- }
+@ReflectiveTestCase()
+class LinkedEditGroupTest {
void test_new() {
- LinkedPositionGroup group = new LinkedPositionGroup('my-id');
- group.addPosition(new Position('/a.dart', 1, 2));
- group.addPosition(new Position('/b.dart', 10, 2));
+ LinkedEditGroup group = new LinkedEditGroup('my-id');
+ group.addPosition(new Position('/a.dart', 1), 2);
+ group.addPosition(new Position('/b.dart', 10), 2);
expect(
group.toString(),
- 'LinkedPositionGroup(id=my-id, positions=['
- 'Position(file=/a.dart, offset=1, length=2), '
- 'Position(file=/b.dart, offset=10, length=2)])');
+ 'LinkedEditGroup(id=my-id, length=2, positions=['
+ 'Position(file=/a.dart, offset=1), '
+ 'Position(file=/b.dart, offset=10)], suggestions=[])');
}
void test_toJson() {
- LinkedPositionGroup group = new LinkedPositionGroup('my-id');
- group.addPosition(new Position('/a.dart', 1, 2));
- group.addPosition(new Position('/b.dart', 10, 2));
- var expectedJson = {
- ID: 'my-id',
- POSITIONS: [{
- FILE: '/a.dart',
- OFFSET: 1,
- LENGTH: 2
+ LinkedEditGroup group = new LinkedEditGroup('my-id');
+ group.addPosition(new Position('/a.dart', 1), 2);
+ group.addPosition(new Position('/b.dart', 10), 2);
+ group.addSuggestion(
+ new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'AA'));
+ group.addSuggestion(
+ new LinkedEditSuggestion(LinkedEditSuggestionKind.TYPE, 'BB'));
+ expect(group.toJson(), {
+ 'id': 'my-id',
+ 'length': 2,
+ 'positions': [{
+ 'file': '/a.dart',
+ 'offset': 1
}, {
- FILE: '/b.dart',
- OFFSET: 10,
- LENGTH: 2
+ 'file': '/b.dart',
+ 'offset': 10
+ }],
+ 'suggestions': [{
+ 'kind': 'TYPE',
+ 'value': 'AA'
+ }, {
+ 'kind': 'TYPE',
+ 'value': 'BB'
}]
- };
- expect(group.toJson(), expectedJson);
+ });
}
}
@@ -377,48 +243,32 @@ class LinkedPositionGroupTest {
@ReflectiveTestCase()
class PositionTest {
void test_eqEq() {
- Position a = new Position('/a.dart', 1, 2);
- Position a2 = new Position('/a.dart', 1, 2);
- Position b = new Position('/b.dart', 1, 2);
+ Position a = new Position('/a.dart', 1);
+ Position a2 = new Position('/a.dart', 1);
+ Position b = new Position('/b.dart', 1);
expect(a == a, isTrue);
expect(a == a2, isTrue);
expect(a == b, isFalse);
expect(a == this, isFalse);
}
- void test_fromJson() {
- var json = {
- FILE: '/test.dart',
- OFFSET: 1,
- LENGTH: 2
- };
- Position position = Position.fromJson(json);
- expect(position.file, '/test.dart');
- expect(position.offset, 1);
- expect(position.length, 2);
- }
-
void test_hashCode() {
- Position position = new Position('/test.dart', 1, 2);
+ Position position = new Position('/test.dart', 1);
position.hashCode;
}
void test_new() {
- Position position = new Position('/test.dart', 1, 2);
+ Position position = new Position('/test.dart', 1);
expect(position.file, '/test.dart');
expect(position.offset, 1);
- expect(position.length, 2);
- expect(
- position.toString(),
- 'Position(file=/test.dart, offset=1, length=2)');
+ expect(position.toString(), 'Position(file=/test.dart, offset=1)');
}
void test_toJson() {
- Position position = new Position('/test.dart', 1, 2);
+ Position position = new Position('/test.dart', 1);
var expectedJson = {
FILE: '/test.dart',
- OFFSET: 1,
- LENGTH: 2
+ OFFSET: 1
};
expect(position.toJson(), expectedJson);
}
« no previous file with comments | « pkg/analysis_services/test/correction/assist_test.dart ('k') | pkg/analysis_services/test/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698