Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dev_compiler.src.testing; | 5 library dev_compiler.src.testing; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 | 234 |
| 235 visitNode(AstNode node) { | 235 visitNode(AstNode node) { |
| 236 var token = node.beginToken; | 236 var token = node.beginToken; |
| 237 var comment = token.precedingComments; | 237 var comment = token.precedingComments; |
| 238 // Use error marker found in an immediately preceding comment, | 238 // Use error marker found in an immediately preceding comment, |
| 239 // and attach it to the outermost expression that starts at that token. | 239 // and attach it to the outermost expression that starts at that token. |
| 240 if (comment != null) { | 240 if (comment != null) { |
| 241 while (comment.next != null) { | 241 while (comment.next != null) { |
| 242 comment = comment.next; | 242 comment = comment.next; |
| 243 } | 243 } |
| 244 if (comment.end == token.offset && | 244 if (comment.end == token.offset && node.parent.beginToken != token) { |
| 245 _realParent(node).beginToken != token) { | |
| 246 var commentText = '$comment'; | 245 var commentText = '$comment'; |
| 247 var start = commentText.lastIndexOf('/*'); | 246 var start = commentText.lastIndexOf('/*'); |
| 248 var end = commentText.lastIndexOf('*/'); | 247 var end = commentText.lastIndexOf('*/'); |
| 249 if (start != -1 && end != -1) { | 248 if (start != -1 && end != -1) { |
| 250 expect(start, lessThan(end)); | 249 expect(start, lessThan(end)); |
| 251 var errors = commentText.substring(start + 2, end).split(','); | 250 var errors = commentText.substring(start + 2, end).split(','); |
| 252 var expectations = errors.map(_ErrorExpectation.parse); | 251 var expectations = errors.map(_ErrorExpectation.parse); |
| 253 expectedErrors[node] = expectations.where((x) => x != null).toList(); | 252 expectedErrors[node] = expectations.where((x) => x != null).toList(); |
| 254 } | 253 } |
| 255 } | 254 } |
| 256 } | 255 } |
| 257 return super.visitNode(node); | 256 return super.visitNode(node); |
| 258 } | 257 } |
| 259 | |
| 260 /// Get the node's parent, ignoring fake conversion nodes. | |
| 261 AstNode _realParent(AstNode node) { | |
| 262 var p = node.parent; | |
| 263 while (p is Conversion) p = p.parent; | |
|
Jennifer Messerly
2015/06/08 23:51:37
after renamed Conversion -> CoercionInfo, I notice
| |
| 264 return p; | |
| 265 } | |
| 266 } | 258 } |
| 267 | 259 |
| 268 /// Describes an expected message that should be produced by the checker. | 260 /// Describes an expected message that should be produced by the checker. |
| 269 class _ErrorExpectation { | 261 class _ErrorExpectation { |
| 270 final Level level; | 262 final Level level; |
| 271 final Type type; | 263 final Type type; |
| 272 _ErrorExpectation(this.level, this.type); | 264 _ErrorExpectation(this.level, this.type); |
| 273 | 265 |
| 274 static _ErrorExpectation _parse(String descriptor) { | 266 static _ErrorExpectation _parse(String descriptor) { |
| 275 var tokens = descriptor.split(':'); | 267 var tokens = descriptor.split(':'); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 296 expect(tokens[1], "should", reason: 'invalid error descriptor'); | 288 expect(tokens[1], "should", reason: 'invalid error descriptor'); |
| 297 expect(tokens[2], "be", reason: 'invalid error descriptor'); | 289 expect(tokens[2], "be", reason: 'invalid error descriptor'); |
| 298 if (tokens[0] == "pass") return null; | 290 if (tokens[0] == "pass") return null; |
| 299 // TODO(leafp) For now, we just use whatever the current expectation is, | 291 // TODO(leafp) For now, we just use whatever the current expectation is, |
| 300 // eventually we could do more automated reporting here. | 292 // eventually we could do more automated reporting here. |
| 301 return _parse(tokens[0]); | 293 return _parse(tokens[0]); |
| 302 } | 294 } |
| 303 | 295 |
| 304 String toString() => '$level $type'; | 296 String toString() => '$level $type'; |
| 305 } | 297 } |
| OLD | NEW |