| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.integration.analysis.occurrences; |
| 6 |
| 7 import 'package:analysis_testing/reflective_tests.dart'; |
| 8 import 'package:unittest/unittest.dart'; |
| 9 |
| 10 import '../integration_tests.dart'; |
| 11 |
| 12 @ReflectiveTestCase() |
| 13 class Test extends AbstractAnalysisServerIntegrationTest { |
| 14 test_occurrences() { |
| 15 String pathname = sourcePath('test.dart'); |
| 16 String text = |
| 17 r''' |
| 18 main() { |
| 19 int sum = 0; |
| 20 for (int i = 0; i < 10; i++) { |
| 21 for (int j = 0; j < i; j++) { |
| 22 sum += j; |
| 23 } |
| 24 } |
| 25 print(sum); |
| 26 } |
| 27 '''; |
| 28 writeFile(pathname, text); |
| 29 standardAnalysisSetup(); |
| 30 sendAnalysisSetSubscriptions({ |
| 31 'OCCURRENCES': [pathname] |
| 32 }); |
| 33 List occurrences; |
| 34 onAnalysisOccurrences.listen((params) { |
| 35 expect(params['file'], equals(pathname)); |
| 36 occurrences = params['occurrences']; |
| 37 }); |
| 38 return analysisFinished.then((_) { |
| 39 expect(currentAnalysisErrors[pathname], isEmpty); |
| 40 Set<int> findOffsets(String elementName) { |
| 41 for (Map occurrence in occurrences) { |
| 42 if (occurrence['element']['name'] == elementName) { |
| 43 return occurrence['offsets'].toSet(); |
| 44 } |
| 45 } |
| 46 fail('No element found matching $elementName'); |
| 47 return null; |
| 48 } |
| 49 void check(String elementName, Iterable<String> expectedOccurrences) { |
| 50 Set<int> expectedOffsets = expectedOccurrences.map((String substring) => |
| 51 text.indexOf(substring)).toSet(); |
| 52 Set<int> foundOffsets = findOffsets(elementName); |
| 53 expect(foundOffsets, equals(expectedOffsets)); |
| 54 } |
| 55 check('i', ['i = 0', 'i < 10', 'i++', 'i;']); |
| 56 check('j', ['j = 0', 'j < i', 'j++', 'j;']); |
| 57 check('sum', ['sum = 0', 'sum +=', 'sum)']); |
| 58 }); |
| 59 } |
| 60 } |
| 61 |
| 62 main() { |
| 63 runReflectiveTests(Test); |
| 64 } |
| OLD | NEW |