| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.updateContent; | 5 library test.analysis.updateContent; |
| 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.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| 11 import '../analysis_abstract.dart'; | 11 import '../analysis_abstract.dart'; |
| 12 import '../reflective_tests.dart'; | 12 import '../reflective_tests.dart'; |
| 13 | 13 |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 groupSep = ' | '; | 16 groupSep = ' | '; |
| 17 runReflectiveTests(UpdateContentTest); | 17 runReflectiveTests(UpdateContentTest); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 @reflectiveTest | 21 @reflectiveTest |
| 22 class UpdateContentTest extends AbstractAnalysisTest { | 22 class UpdateContentTest extends AbstractAnalysisTest { |
| 23 Map<String, List<AnalysisError>> filesErrors = {}; | 23 Map<String, List<AnalysisError>> filesErrors = {}; |
| 24 int serverErrorCount = 0; |
| 25 int navigationCount = 0; |
| 24 | 26 |
| 25 @override | 27 @override |
| 26 void processNotification(Notification notification) { | 28 void processNotification(Notification notification) { |
| 27 if (notification.event == ANALYSIS_ERRORS) { | 29 if (notification.event == ANALYSIS_ERRORS) { |
| 28 var decoded = new AnalysisErrorsParams.fromNotification(notification); | 30 var decoded = new AnalysisErrorsParams.fromNotification(notification); |
| 29 filesErrors[decoded.file] = decoded.errors; | 31 filesErrors[decoded.file] = decoded.errors; |
| 30 } | 32 } |
| 33 if (notification.event == ANALYSIS_NAVIGATION) { |
| 34 navigationCount++; |
| 35 } |
| 36 if (notification.event == SERVER_ERROR) { |
| 37 serverErrorCount++; |
| 38 } |
| 39 } |
| 40 |
| 41 test_discardNotifications_onSourceChange() async { |
| 42 createProject(); |
| 43 addTestFile(''); |
| 44 await server.onAnalysisComplete; |
| 45 server.setAnalysisSubscriptions({ |
| 46 AnalysisService.NAVIGATION: [testFile].toSet() |
| 47 }); |
| 48 // update file, analyze, but don't sent notifications |
| 49 navigationCount = 0; |
| 50 server.updateContent('1', { |
| 51 testFile: new AddContentOverlay('foo() {}') |
| 52 }); |
| 53 server.test_performAllAnalysisOperations(); |
| 54 expect(serverErrorCount, 0); |
| 55 expect(navigationCount, 0); |
| 56 // replace the file contents, |
| 57 // should discard any pending notification operations |
| 58 server.updateContent('2', { |
| 59 testFile: new AddContentOverlay('bar() {}') |
| 60 }); |
| 61 await server.onAnalysisComplete; |
| 62 expect(serverErrorCount, 0); |
| 63 expect(navigationCount, 1); |
| 31 } | 64 } |
| 32 | 65 |
| 33 test_illegal_ChangeContentOverlay() { | 66 test_illegal_ChangeContentOverlay() { |
| 34 // It should be illegal to send a ChangeContentOverlay for a file that | 67 // It should be illegal to send a ChangeContentOverlay for a file that |
| 35 // doesn't have an overlay yet. | 68 // doesn't have an overlay yet. |
| 36 createProject(); | 69 createProject(); |
| 37 addTestFile('library foo;'); | 70 addTestFile('library foo;'); |
| 38 String id = 'myId'; | 71 String id = 'myId'; |
| 39 try { | 72 try { |
| 40 server.updateContent(id, { | 73 server.updateContent(id, { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 filesErrors.clear(); | 153 filesErrors.clear(); |
| 121 server.test_flushResolvedUnit(testFile); | 154 server.test_flushResolvedUnit(testFile); |
| 122 server.updateContent('2', { | 155 server.updateContent('2', { |
| 123 testFile: new ChangeContentOverlay([new SourceEdit(0, 4, 'main')]) | 156 testFile: new ChangeContentOverlay([new SourceEdit(0, 4, 'main')]) |
| 124 }); | 157 }); |
| 125 await server.onAnalysisComplete; | 158 await server.onAnalysisComplete; |
| 126 // errors should have been resent | 159 // errors should have been resent |
| 127 expect(filesErrors, isNotEmpty); | 160 expect(filesErrors, isNotEmpty); |
| 128 } | 161 } |
| 129 } | 162 } |
| OLD | NEW |