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

Side by Side Diff: pkg/analyzer_experimental/test/services/test_utils.dart

Issue 24481002: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_utils; 5 library test_utils;
6 6
7 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 8
9 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo ntext, AnalysisContextImpl; 9 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo ntext, AnalysisContextImpl;
10 import 'package:analyzer_experimental/src/generated/source.dart'; 10 import 'package:analyzer_experimental/src/generated/source.dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 50
51 /// Asserts that the number of errors that have been gathered matches the 51 /// Asserts that the number of errors that have been gathered matches the
52 /// number of errors that are given and that they have the expected error 52 /// number of errors that are given and that they have the expected error
53 /// codes. The order in which the errors were gathered is ignored. 53 /// codes. The order in which the errors were gathered is ignored.
54 void expectErrors(List<ErrorCode> expectedErrorCodes) { 54 void expectErrors(List<ErrorCode> expectedErrorCodes) {
55 var builder = new StringBuffer(); 55 var builder = new StringBuffer();
56 var expectedCounts = new Map<ErrorCode, int>(); 56 var expectedCounts = new Map<ErrorCode, int>();
57 57
58 for (code in expectedErrorCodes) { 58 for (var code in expectedErrorCodes) {
59 var count = expectedCounts[code]; 59 var count = expectedCounts[code];
60 if (count == null) { 60 if (count == null) {
61 count = 1; 61 count = 1;
62 } else { 62 } else {
63 count = count + 1; 63 count = count + 1;
64 } 64 }
65 expectedCounts[code] = count; 65 expectedCounts[code] = count;
66 } 66 }
67 67
68 var errorsByCode = new Map<ErrorCode, List<AnalysisError>>(); 68 var errorsByCode = new Map<ErrorCode, List<AnalysisError>>();
69 for (error in _errors) { 69 for (var error in _errors) {
70 var code = error.errorCode; 70 var code = error.errorCode;
71 var list = errorsByCode[code]; 71 var list = errorsByCode[code];
72 if (list == null) { 72 if (list == null) {
73 list = new List<AnalysisError>(); 73 list = new List<AnalysisError>();
74 errorsByCode[code] = list; 74 errorsByCode[code] = list;
75 } 75 }
76 list.add(error); 76 list.add(error);
77 } 77 }
78 78
79 for (entry in _getMapEntrySet(expectedCounts)) { 79 for (var entry in _getMapEntrySet(expectedCounts)) {
80 var code = entry.getKey(); 80 var code = entry.getKey();
81 var expectedCount = entry.getValue(); 81 var expectedCount = entry.getValue();
82 var actualCount; 82 var actualCount;
83 83
84 var list = errorsByCode.remove(code); 84 var list = errorsByCode.remove(code);
85 if (list == null) { 85 if (list == null) {
86 actualCount = 0; 86 actualCount = 0;
87 } else { 87 } else {
88 actualCount = list.length; 88 actualCount = list.length;
89 } 89 }
90 90
91 if (actualCount != expectedCount) { 91 if (actualCount != expectedCount) {
92 if (builder.length == 0) { 92 if (builder.length == 0) {
93 builder.write('Expected '); 93 builder.write('Expected ');
94 } else { 94 } else {
95 builder.write('; '); 95 builder.write('; ');
96 } 96 }
97 builder.write(expectedCount); 97 builder.write(expectedCount);
98 builder.write(' errors of type '); 98 builder.write(' errors of type ');
99 builder.write(code); 99 builder.write(code);
100 builder.write(', found '); 100 builder.write(', found ');
101 builder.write(actualCount); 101 builder.write(actualCount);
102 } 102 }
103 } 103 }
104 104
105 for (entry in _getMapEntrySet(errorsByCode)) { 105 for (var entry in _getMapEntrySet(errorsByCode)) {
106 var code = entry.getKey(); 106 var code = entry.getKey();
107 var actualErrors = entry.getValue(); 107 var actualErrors = entry.getValue();
108 var actualCount = actualErrors.length; 108 var actualCount = actualErrors.length;
109 109
110 if (builder.length == 0) { 110 if (builder.length == 0) {
111 builder.write('Expected '); 111 builder.write('Expected ');
112 } else { 112 } else {
113 builder.write('; '); 113 builder.write('; ');
114 } 114 }
115 115
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 var parser = new Parser(null, listener); 204 var parser = new Parser(null, listener);
205 var statement = parser.parseStatement(token); 205 var statement = parser.parseStatement(token);
206 expect(statement, isNotNull); 206 expect(statement, isNotNull);
207 207
208 if (expectedErrorCodes != null) { 208 if (expectedErrorCodes != null) {
209 listener.expectErrors(expectedErrorCodes); 209 listener.expectErrors(expectedErrorCodes);
210 } 210 }
211 211
212 return statement; 212 return statement;
213 } 213 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/test/generated/test_support.dart ('k') | tests/co19/co19-analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698