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

Side by Side Diff: pkg/analysis_server/test/domain_context_test.dart

Issue 282993002: Leave "error" key out of response JSON when there is no error. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
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.domain.context; 5 library test.domain.context;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/generated/source_io.dart'; 9 import 'package:analyzer/src/generated/source_io.dart';
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
(...skipping 28 matching lines...) Expand all
39 request.setParameter(ContextDomainHandler.SOURCES_PARAM, []); 39 request.setParameter(ContextDomainHandler.SOURCES_PARAM, []);
40 request.setParameter(ContextDomainHandler.CHANGES_PARAM, { 40 request.setParameter(ContextDomainHandler.CHANGES_PARAM, {
41 ContextDomainHandler.ADDED_PARAM : ['ffile:/one.dart'], 41 ContextDomainHandler.ADDED_PARAM : ['ffile:/one.dart'],
42 ContextDomainHandler.MODIFIED_PARAM : ['ffile:/two.dart'], 42 ContextDomainHandler.MODIFIED_PARAM : ['ffile:/two.dart'],
43 ContextDomainHandler.REMOVED_PARAM : ['ffile:/three.dart'] 43 ContextDomainHandler.REMOVED_PARAM : ['ffile:/three.dart']
44 }); 44 });
45 expect(server.contextWorkQueue, isEmpty); 45 expect(server.contextWorkQueue, isEmpty);
46 Response response = handler.handleRequest(request); 46 Response response = handler.handleRequest(request);
47 expect(server.contextWorkQueue, hasLength(1)); 47 expect(server.contextWorkQueue, hasLength(1));
48 expect(response.toJson(), equals({ 48 expect(response.toJson(), equals({
49 Response.ID: '0', 49 Response.ID: '0'
50 Response.ERROR: null
51 })); 50 }));
52 } 51 }
53 52
54 static void createChangeSet() { 53 static void createChangeSet() {
55 AnalysisServer server = new AnalysisServer(new MockServerChannel()); 54 AnalysisServer server = new AnalysisServer(new MockServerChannel());
56 Request request = new Request('0', ContextDomainHandler.APPLY_CHANGES_NAME); 55 Request request = new Request('0', ContextDomainHandler.APPLY_CHANGES_NAME);
57 ContextDomainHandler handler = new ContextDomainHandler(server); 56 ContextDomainHandler handler = new ContextDomainHandler(server);
58 SourceFactory sourceFactory = new SourceFactory([new FileUriResolver()]); 57 SourceFactory sourceFactory = new SourceFactory([new FileUriResolver()]);
59 ChangeSet changeSet = handler.createChangeSet(request, sourceFactory, 58 ChangeSet changeSet = handler.createChangeSet(request, sourceFactory,
60 new RequestDatum(request, ContextDomainHandler.CHANGES_PARAM, { 59 new RequestDatum(request, ContextDomainHandler.CHANGES_PARAM, {
(...skipping 11 matching lines...) Expand all
72 AnalysisServer server = new AnalysisServer(new MockServerChannel()); 71 AnalysisServer server = new AnalysisServer(new MockServerChannel());
73 String contextId = _createContext(server); 72 String contextId = _createContext(server);
74 Map<String, Object> options = new Map<String, Object>(); 73 Map<String, Object> options = new Map<String, Object>();
75 ContextDomainHandler handler = new ContextDomainHandler(server); 74 ContextDomainHandler handler = new ContextDomainHandler(server);
76 75
77 Request request = new Request('0', ContextDomainHandler.SET_OPTIONS_NAME); 76 Request request = new Request('0', ContextDomainHandler.SET_OPTIONS_NAME);
78 request.setParameter(ContextDomainHandler.CONTEXT_ID_PARAM, contextId); 77 request.setParameter(ContextDomainHandler.CONTEXT_ID_PARAM, contextId);
79 request.setParameter(ContextDomainHandler.OPTIONS_PARAM, options); 78 request.setParameter(ContextDomainHandler.OPTIONS_PARAM, options);
80 Response response = handler.handleRequest(request); 79 Response response = handler.handleRequest(request);
81 expect(response.toJson(), equals({ 80 expect(response.toJson(), equals({
82 Response.ID: '0', 81 Response.ID: '0'
83 Response.ERROR: null
84 })); 82 }));
85 } 83 }
86 84
87 static void setPrioritySources_empty() { 85 static void setPrioritySources_empty() {
88 AnalysisServer server = new AnalysisServer(new MockServerChannel()); 86 AnalysisServer server = new AnalysisServer(new MockServerChannel());
89 String contextId = _createContext(server); 87 String contextId = _createContext(server);
90 List<String> sources = new List<String>(); 88 List<String> sources = new List<String>();
91 ContextDomainHandler handler = new ContextDomainHandler(server); 89 ContextDomainHandler handler = new ContextDomainHandler(server);
92 90
93 Request request = new Request('0', ContextDomainHandler.SET_PRIORITY_SOURCES _NAME); 91 Request request = new Request('0', ContextDomainHandler.SET_PRIORITY_SOURCES _NAME);
94 request.setParameter(ContextDomainHandler.CONTEXT_ID_PARAM, contextId); 92 request.setParameter(ContextDomainHandler.CONTEXT_ID_PARAM, contextId);
95 request.setParameter(ContextDomainHandler.SOURCES_PARAM, sources); 93 request.setParameter(ContextDomainHandler.SOURCES_PARAM, sources);
96 Response response = handler.handleRequest(request); 94 Response response = handler.handleRequest(request);
97 expect(response.toJson(), equals({ 95 expect(response.toJson(), equals({
98 Response.ID: '0', 96 Response.ID: '0'
99 Response.ERROR: null
100 })); 97 }));
101 } 98 }
102 99
103 static void setPrioritySources_nonEmpty() { 100 static void setPrioritySources_nonEmpty() {
104 AnalysisServer server = new AnalysisServer(new MockServerChannel()); 101 AnalysisServer server = new AnalysisServer(new MockServerChannel());
105 String contextId = _createContext(server); 102 String contextId = _createContext(server);
106 List<String> sources = new List<String>(); 103 List<String> sources = new List<String>();
107 sources.add("foo.dart"); 104 sources.add("foo.dart");
108 ContextDomainHandler handler = new ContextDomainHandler(server); 105 ContextDomainHandler handler = new ContextDomainHandler(server);
109 106
110 Request request = new Request('0', ContextDomainHandler.SET_PRIORITY_SOURCES _NAME); 107 Request request = new Request('0', ContextDomainHandler.SET_PRIORITY_SOURCES _NAME);
111 request.setParameter(ContextDomainHandler.CONTEXT_ID_PARAM, contextId); 108 request.setParameter(ContextDomainHandler.CONTEXT_ID_PARAM, contextId);
112 request.setParameter(ContextDomainHandler.SOURCES_PARAM, sources); 109 request.setParameter(ContextDomainHandler.SOURCES_PARAM, sources);
113 Response response = handler.handleRequest(request); 110 Response response = handler.handleRequest(request);
114 expect(response.toJson(), equals({ 111 expect(response.toJson(), equals({
115 Response.ID: '0', 112 Response.ID: '0'
116 Response.ERROR: null
117 })); 113 }));
118 } 114 }
119 115
120 static String _createContext(AnalysisServer server) { 116 static String _createContext(AnalysisServer server) {
121 String contextId = "context${contextIdCounter++}"; 117 String contextId = "context${contextIdCounter++}";
122 ServerDomainHandler handler = new ServerDomainHandler(server); 118 ServerDomainHandler handler = new ServerDomainHandler(server);
123 Request request = new Request('0', ServerDomainHandler.CREATE_CONTEXT_METHOD ); 119 Request request = new Request('0', ServerDomainHandler.CREATE_CONTEXT_METHOD );
124 request.setParameter(ServerDomainHandler.SDK_DIRECTORY_PARAM, sdkPath); 120 request.setParameter(ServerDomainHandler.SDK_DIRECTORY_PARAM, sdkPath);
125 request.setParameter(ServerDomainHandler.CONTEXT_ID_PARAM, contextId); 121 request.setParameter(ServerDomainHandler.CONTEXT_ID_PARAM, contextId);
126 Response response = handler.handleRequest(request); 122 Response response = handler.handleRequest(request);
127 if (response.error != null) { 123 if (response.error != null) {
128 fail('Unexpected error: ${response.error.toJson()}'); 124 fail('Unexpected error: ${response.error.toJson()}');
129 } 125 }
130 return contextId; 126 return contextId;
131 } 127 }
132 } 128 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/protocol.dart ('k') | pkg/analysis_server/test/domain_server_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698