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

Side by Side Diff: pkg/analysis_server/test/src/plugin/request_converter_test.dart

Issue 2879273002: Make server use the common protocol classes (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 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 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 import 'package:analysis_server/protocol/protocol_generated.dart' as server; 5 import 'package:analysis_server/protocol/protocol_generated.dart' as server;
6 import 'package:analysis_server/src/plugin/request_converter.dart'; 6 import 'package:analysis_server/src/plugin/request_converter.dart';
7 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server; 7 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server;
8 import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; 8 import 'package:analyzer_plugin/protocol/protocol_common.dart';
9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; 9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; 11 import 'package:test_reflective_loader/test_reflective_loader.dart';
12 12
13 import 'protocol_test_utilities.dart'; 13 import 'protocol_test_utilities.dart';
14 14
15 main() { 15 main() {
16 defineReflectiveSuite(() { 16 defineReflectiveSuite(() {
17 defineReflectiveTests(RequestConverterTest); 17 defineReflectiveTests(RequestConverterTest);
18 }); 18 });
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 Map<plugin.AnalysisService, List<String>> pluginSubscriptions = 60 Map<plugin.AnalysisService, List<String>> pluginSubscriptions =
61 result.subscriptions; 61 result.subscriptions;
62 expect(pluginSubscriptions, hasLength(2)); 62 expect(pluginSubscriptions, hasLength(2));
63 expect( 63 expect(
64 pluginSubscriptions[plugin.AnalysisService.HIGHLIGHTS], hasLength(2)); 64 pluginSubscriptions[plugin.AnalysisService.HIGHLIGHTS], hasLength(2));
65 expect(pluginSubscriptions[plugin.AnalysisService.OUTLINE], hasLength(1)); 65 expect(pluginSubscriptions[plugin.AnalysisService.OUTLINE], hasLength(1));
66 } 66 }
67 67
68 void test_convertAnalysisUpdateContentParams() { 68 void test_convertAnalysisUpdateContentParams() {
69 Map<String, dynamic> serverFiles = <String, dynamic>{ 69 Map<String, dynamic> serverFiles = <String, dynamic>{
70 'file1': new server.AddContentOverlay('content1'), 70 'file1': new AddContentOverlay('content1'),
71 'file2': new server.AddContentOverlay('content2'), 71 'file2': new AddContentOverlay('content2'),
72 }; 72 };
73 plugin.AnalysisUpdateContentParams result = 73 plugin.AnalysisUpdateContentParams result =
74 converter.convertAnalysisUpdateContentParams( 74 converter.convertAnalysisUpdateContentParams(
75 new server.AnalysisUpdateContentParams(serverFiles)); 75 new server.AnalysisUpdateContentParams(serverFiles));
76 expect(result, isNotNull); 76 expect(result, isNotNull);
77 Map<String, dynamic> pluginFiles = result.files; 77 Map<String, dynamic> pluginFiles = result.files;
78 expect(pluginFiles, hasLength(2)); 78 expect(pluginFiles, hasLength(2));
79 expect(pluginFiles['file1'], new isInstanceOf<plugin.AddContentOverlay>()); 79 expect(pluginFiles['file1'], new isInstanceOf<AddContentOverlay>());
80 expect(pluginFiles['file2'], new isInstanceOf<plugin.AddContentOverlay>()); 80 expect(pluginFiles['file2'], new isInstanceOf<AddContentOverlay>());
81 }
82
83 void test_convertFileOverlay_add() {
84 String content = 'content';
85 plugin.AddContentOverlay result =
86 converter.convertFileOverlay(new server.AddContentOverlay(content));
87 expect(result, isNotNull);
88 expect(result.content, content);
89 }
90
91 void test_convertFileOverlay_change() {
92 List<server.SourceEdit> serverEdits = <server.SourceEdit>[
93 new server.SourceEdit(10, 5, 'a'),
94 new server.SourceEdit(20, 6, 'b'),
95 new server.SourceEdit(30, 7, 'c'),
96 ];
97 plugin.ChangeContentOverlay result = converter
98 .convertFileOverlay(new server.ChangeContentOverlay(serverEdits));
99 expect(result, isNotNull);
100 List<plugin.SourceEdit> pluginEdits = result.edits;
101 int editCount = serverEdits.length;
102 expect(pluginEdits, hasLength(editCount));
103 for (int i = 0; i < editCount; i++) {
104 server.SourceEdit serverEdit = serverEdits[i];
105 plugin.SourceEdit pluginEdit = pluginEdits[i];
106 expect(pluginEdit.offset, serverEdit.offset);
107 expect(pluginEdit.length, serverEdit.length);
108 expect(pluginEdit.replacement, serverEdit.replacement);
109 }
110 }
111
112 void test_convertFileOverlay_remove() {
113 plugin.RemoveContentOverlay result =
114 converter.convertFileOverlay(new server.RemoveContentOverlay());
115 expect(result, isNotNull);
116 }
117
118 void test_convertSourceEdit() {
119 int offset = 5;
120 int length = 3;
121 String replacement = 'x';
122 plugin.SourceEdit result = converter
123 .convertSourceEdit(new server.SourceEdit(offset, length, replacement));
124 expect(result, isNotNull);
125 expect(result.offset, offset);
126 expect(result.length, length);
127 expect(result.replacement, replacement);
128 } 81 }
129 } 82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698