| 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.integration.analysis.occurrences; | 5 library test.integration.analysis.occurrences; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 print(sum); | 26 print(sum); |
| 27 } | 27 } |
| 28 '''; | 28 '''; |
| 29 writeFile(pathname, text); | 29 writeFile(pathname, text); |
| 30 standardAnalysisSetup(); | 30 standardAnalysisSetup(); |
| 31 sendAnalysisSetSubscriptions({ | 31 sendAnalysisSetSubscriptions({ |
| 32 AnalysisService.OCCURRENCES: [pathname] | 32 AnalysisService.OCCURRENCES: [pathname] |
| 33 }); | 33 }); |
| 34 List occurrences; | 34 List<Occurrences> occurrences; |
| 35 onAnalysisOccurrences.listen((params) { | 35 onAnalysisOccurrences.listen((AnalysisOccurrencesParams params) { |
| 36 expect(params['file'], equals(pathname)); | 36 expect(params.file, equals(pathname)); |
| 37 occurrences = params['occurrences']; | 37 occurrences = params.occurrences; |
| 38 }); | 38 }); |
| 39 return analysisFinished.then((_) { | 39 return analysisFinished.then((_) { |
| 40 expect(currentAnalysisErrors[pathname], isEmpty); | 40 expect(currentAnalysisErrors[pathname], isEmpty); |
| 41 Set<int> findOffsets(String elementName) { | 41 Set<int> findOffsets(String elementName) { |
| 42 for (Map occurrence in occurrences) { | 42 for (Occurrences occurrence in occurrences) { |
| 43 if (occurrence['element']['name'] == elementName) { | 43 if (occurrence.element.name == elementName) { |
| 44 return occurrence['offsets'].toSet(); | 44 return occurrence.offsets.toSet(); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 fail('No element found matching $elementName'); | 47 fail('No element found matching $elementName'); |
| 48 return null; | 48 return null; |
| 49 } | 49 } |
| 50 void check(String elementName, Iterable<String> expectedOccurrences) { | 50 void check(String elementName, Iterable<String> expectedOccurrences) { |
| 51 Set<int> expectedOffsets = expectedOccurrences.map((String substring) => | 51 Set<int> expectedOffsets = expectedOccurrences.map((String substring) => |
| 52 text.indexOf(substring)).toSet(); | 52 text.indexOf(substring)).toSet(); |
| 53 Set<int> foundOffsets = findOffsets(elementName); | 53 Set<int> foundOffsets = findOffsets(elementName); |
| 54 expect(foundOffsets, equals(expectedOffsets)); | 54 expect(foundOffsets, equals(expectedOffsets)); |
| 55 } | 55 } |
| 56 check('i', ['i = 0', 'i < 10', 'i++', 'i;']); | 56 check('i', ['i = 0', 'i < 10', 'i++', 'i;']); |
| 57 check('j', ['j = 0', 'j < i', 'j++', 'j;']); | 57 check('j', ['j = 0', 'j < i', 'j++', 'j;']); |
| 58 check('sum', ['sum = 0', 'sum +=', 'sum)']); | 58 check('sum', ['sum = 0', 'sum +=', 'sum)']); |
| 59 }); | 59 }); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 main() { | 63 main() { |
| 64 runReflectiveTests(Test); | 64 runReflectiveTests(Test); |
| 65 } | 65 } |
| OLD | NEW |