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

Side by Side Diff: pkg/analysis_server/test/integration/analysis/occurrences_test.dart

Issue 475903002: Add an integration test for analysis.occurrences. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/integration/analysis/test_all.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/integration/analysis/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698