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

Side by Side Diff: pkg/analysis_server/test/src/plugin/result_collector_test.dart

Issue 2676593006: Initial support for managing partial results from plugins (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 import 'package:analysis_server/src/plugin/result_collector.dart';
6 import 'package:test/test.dart';
7 import 'package:test_reflective_loader/test_reflective_loader.dart';
8
9 main() {
10 defineReflectiveSuite(() {
11 defineReflectiveTests(ResultCollectorTest);
12 });
13 }
14
15 @reflectiveTest
16 class ResultCollectorTest {
17 static const String serverId = 'server';
18
19 ResultCollector<String> collector = new ResultCollector<String>(serverId);
20
21 void test_clearResultsForFile() {
22 String filePath1 = 'test1.dart';
23 String filePath2 = 'test2.dart';
24 String value1 = 'r1';
25 String value2 = 'r2';
26 collector.startCollectingFor(filePath1);
27 collector.startCollectingFor(filePath2);
28 collector.putResults(filePath1, 'p', value1);
29 collector.putResults(filePath2, 'p', value2);
30 expect(collector.getResults(filePath1), contains(value1));
31 expect(collector.getResults(filePath2), contains(value2));
32
33 collector.clearResultsForFile(filePath2);
34 expect(collector.getResults(filePath1), contains(value1));
35 expect(collector.getResults(filePath2), isEmpty);
36 }
37
38 void test_clearResultsFromPlugin() {
39 String filePath = 'test.dart';
40 String p1Name = 'p1';
41 String p2Name = 'p2';
42 String p1Value = 'r1';
43 String p2Value = 'r2';
44
45 collector.startCollectingFor(filePath);
46 collector.putResults(filePath, p1Name, p1Value);
47 collector.putResults(filePath, p2Name, p2Value);
48 expect(collector.getResults(filePath), contains(p1Value));
49 expect(collector.getResults(filePath), contains(p2Value));
50
51 collector.clearResultsFromPlugin(p1Name);
52 expect(collector.getResults(filePath), isNot(contains(p1Value)));
53 expect(collector.getResults(filePath), contains(p2Value));
54 }
55
56 void test_getResults_emptyCollector() {
57 expect(collector.getResults('test.dart'), isEmpty);
58 }
59
60 void test_getResults_serverFirst() {
61 // This is a flaky test in that it is possible for the test to pass even
62 // when the code is broken.
63 String filePath = 'test.dart';
64 String value1 = 'r1';
65 String value2 = 'r2';
66 collector.startCollectingFor(filePath);
67 collector.putResults(filePath, 'p', value1);
68 collector.putResults(filePath, serverId, value2);
69 expect(collector.getResults(filePath), <String>[value2, value1]);
70 }
71
72 void test_putResults_collecting() {
73 String filePath1 = 'test1.dart';
74 String filePath2 = 'test2.dart';
75 String value1 = 'r1';
76 String value2 = 'r2';
77 expect(collector.getResults(filePath1), isEmpty);
78 expect(collector.getResults(filePath2), isEmpty);
79
80 collector.startCollectingFor(filePath1);
81 collector.startCollectingFor(filePath2);
82 collector.putResults(filePath1, 'p', value1);
83 collector.putResults(filePath2, 'p', value2);
84 expect(collector.getResults(filePath1), contains(value1));
85 expect(collector.getResults(filePath1), isNot(contains(value2)));
86 expect(collector.getResults(filePath2), contains(value2));
87 expect(collector.getResults(filePath2), isNot(contains(value1)));
88 }
89
90 void test_putResults_notCollecting() {
91 String filePath = 'test.dart';
92 expect(collector.getResults(filePath), isEmpty);
93
94 collector.putResults(filePath, 'p', 'r');
95 expect(collector.getResults(filePath), isEmpty);
96 }
97
98 void test_stopCollectingFor() {
99 String filePath = 'test.dart';
100 String value = 'r';
101 collector.startCollectingFor(filePath);
102 collector.putResults(filePath, 'p', value);
103 expect(collector.getResults(filePath), contains(value));
104
105 collector.stopCollectingFor(filePath);
106 expect(collector.getResults(filePath), isEmpty);
107 collector.putResults(filePath, 'p', value);
108 expect(collector.getResults(filePath), isEmpty);
109 }
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698