| 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.analysis_server; | 5 library test.analysis_server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/source_io.dart'; | 10 import 'package:analyzer/src/generated/source_io.dart'; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 static Future addContextToWorkQueue_whenRunning() { | 65 static Future addContextToWorkQueue_whenRunning() { |
| 66 MockAnalysisContext context = new MockAnalysisContext(); | 66 MockAnalysisContext context = new MockAnalysisContext(); |
| 67 server.addContextToWorkQueue(context); | 67 server.addContextToWorkQueue(context); |
| 68 MockSource source = new MockSource(); | 68 MockSource source = new MockSource(); |
| 69 source.when(callsTo('get encoding')).alwaysReturn('foo.dart'); | 69 source.when(callsTo('get encoding')).alwaysReturn('foo.dart'); |
| 70 ChangeNoticeImpl changeNoticeImpl = new ChangeNoticeImpl(source); | 70 ChangeNoticeImpl changeNoticeImpl = new ChangeNoticeImpl(source); |
| 71 LineInfo lineInfo = new LineInfo([0]); | 71 LineInfo lineInfo = new LineInfo([0]); |
| 72 AnalysisError analysisError = new AnalysisError.con1(source, | 72 AnalysisError analysisError = new AnalysisError.con1(source, |
| 73 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, []); | 73 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, ['Foo']); |
| 74 changeNoticeImpl.setErrors([analysisError], lineInfo); | 74 changeNoticeImpl.setErrors([analysisError], lineInfo); |
| 75 context.when(callsTo('performAnalysisTask')).thenReturn( | 75 context.when(callsTo('performAnalysisTask')).thenReturn( |
| 76 new AnalysisResult([changeNoticeImpl], 0, 'myClass', 0)); | 76 new AnalysisResult([changeNoticeImpl], 0, 'myClass', 0)); |
| 77 context.when(callsTo('performAnalysisTask')).thenReturn( | 77 context.when(callsTo('performAnalysisTask')).thenReturn( |
| 78 new AnalysisResult(null, 0, null, 0)); | 78 new AnalysisResult(null, 0, null, 0)); |
| 79 return pumpEventQueue().then((_) { | 79 return pumpEventQueue().then((_) { |
| 80 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(2))
; | 80 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(2))
; |
| 81 expect(channel.notificationsReceived, hasLength(2)); | 81 expect(channel.notificationsReceived, hasLength(2)); |
| 82 expect(channel.notificationsReceived[0].event, equals('server.connected') | 82 expect(channel.notificationsReceived[0].event, equals('server.connected') |
| 83 ); | 83 ); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 expect(json['message'], | 135 expect(json['message'], |
| 136 equals("The element 'foo' is defined in the libraries 'bar' and 'baz'"))
; | 136 equals("The element 'foo' is defined in the libraries 'bar' and 'baz'"))
; |
| 137 } | 137 } |
| 138 | 138 |
| 139 static void errorToJson_noCorrection() { | 139 static void errorToJson_noCorrection() { |
| 140 MockSource source = new MockSource(); | 140 MockSource source = new MockSource(); |
| 141 source.when(callsTo('get encoding')).alwaysReturn('foo.dart'); | 141 source.when(callsTo('get encoding')).alwaysReturn('foo.dart'); |
| 142 CompileTimeErrorCode errorCode = | 142 CompileTimeErrorCode errorCode = |
| 143 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER; | 143 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER; |
| 144 AnalysisError analysisError = | 144 AnalysisError analysisError = |
| 145 new AnalysisError.con2(source, 10, 5, errorCode, []); | 145 new AnalysisError.con2(source, 10, 5, errorCode, ['Foo']); |
| 146 Map<String, Object> json = AnalysisServer.errorToJson(analysisError); | 146 Map<String, Object> json = AnalysisServer.errorToJson(analysisError); |
| 147 expect(json, hasLength(5)); | 147 expect(json, hasLength(5)); |
| 148 expect(json['source'], equals('foo.dart')); | 148 expect(json['source'], equals('foo.dart')); |
| 149 expect(json['errorCode'], equals(errorCode.ordinal)); | 149 expect(json['errorCode'], equals(errorCode.ordinal)); |
| 150 expect(json['offset'], equals(analysisError.offset)); | 150 expect(json['offset'], equals(analysisError.offset)); |
| 151 expect(json['length'], equals(analysisError.length)); | 151 expect(json['length'], equals(analysisError.length)); |
| 152 expect(json['message'], equals(errorCode.message)); | 152 expect(json['message'], equals(errorCode.message.replaceAll('%s', 'Foo'))); |
| 153 } | 153 } |
| 154 | 154 |
| 155 static void errorToJson_withCorrection() { | 155 static void errorToJson_withCorrection() { |
| 156 MockSource source = new MockSource(); | 156 MockSource source = new MockSource(); |
| 157 source.when(callsTo('get encoding')).alwaysReturn('foo.dart'); | 157 source.when(callsTo('get encoding')).alwaysReturn('foo.dart'); |
| 158 | 158 |
| 159 // TODO(paulberry): in principle we should test an error or hint that uses | 159 // TODO(paulberry): in principle we should test an error or hint that uses |
| 160 // %s formatting in its correction string. But no such errors or hints | 160 // %s formatting in its correction string. But no such errors or hints |
| 161 // currently exist! | 161 // currently exist! |
| 162 HintCode errorCode = HintCode.MISSING_RETURN; | 162 HintCode errorCode = HintCode.MISSING_RETURN; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 @override | 206 @override |
| 207 Response handleRequest(Request request) { | 207 Response handleRequest(Request request) { |
| 208 if (request.method == 'echo') { | 208 if (request.method == 'echo') { |
| 209 var response = new Response(request.id); | 209 var response = new Response(request.id); |
| 210 response.setResult('echo', true); | 210 response.setResult('echo', true); |
| 211 return response; | 211 return response; |
| 212 } | 212 } |
| 213 return null; | 213 return null; |
| 214 } | 214 } |
| 215 } | 215 } |
| OLD | NEW |