Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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.computer.element; | 5 library test.computer.element; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | |
| 8 | |
| 7 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 8 import 'package:analysis_server/src/protocol_server.dart'; | 10 import 'package:analysis_server/src/protocol_server.dart'; |
| 11 import 'package:analysis_server/src/services/search/search_engine.dart'; | |
| 9 import 'package:analyzer/src/generated/ast.dart' as engine; | 12 import 'package:analyzer/src/generated/ast.dart' as engine; |
| 10 import 'package:analyzer/src/generated/element.dart' as engine; | 13 import 'package:analyzer/src/generated/element.dart' as engine; |
| 11 import 'package:analyzer/src/generated/error.dart' as engine; | 14 import 'package:analyzer/src/generated/error.dart' as engine; |
| 12 import 'package:analyzer/src/generated/source.dart' as engine; | 15 import 'package:analyzer/src/generated/source.dart' as engine; |
| 13 import 'package:typed_mock/typed_mock.dart'; | 16 import 'package:typed_mock/typed_mock.dart'; |
| 14 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 15 | 18 |
| 16 import 'abstract_context.dart'; | 19 import 'abstract_context.dart'; |
| 17 import 'mocks.dart'; | 20 import 'mocks.dart'; |
| 18 import 'reflective_tests.dart'; | 21 import 'reflective_tests.dart'; |
| 19 | 22 |
| 20 | 23 |
| 21 | 24 |
| 22 main() { | 25 main() { |
| 23 groupSep = ' | '; | 26 groupSep = ' | '; |
| 24 runReflectiveTests(AnalysisErrorTest); | 27 runReflectiveTests(AnalysisErrorTest); |
| 25 runReflectiveTests(ElementTest); | 28 runReflectiveTests(ElementTest); |
| 26 runReflectiveTests(ElementKindTest); | 29 runReflectiveTests(ElementKindTest); |
| 30 runReflectiveTests(EnumTest); | |
| 27 } | 31 } |
| 28 | 32 |
| 29 | 33 |
| 30 class AnalysisErrorMock extends TypedMock implements engine.AnalysisError { | 34 class AnalysisErrorMock extends TypedMock implements engine.AnalysisError { |
| 31 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 35 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 32 } | 36 } |
| 33 | 37 |
| 34 | 38 |
| 35 @ReflectiveTestCase() | 39 @ReflectiveTestCase() |
| 36 class AnalysisErrorTest { | 40 class AnalysisErrorTest { |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 // create notification Element | 406 // create notification Element |
| 403 Element element = newElement_fromEngine(engineElement); | 407 Element element = newElement_fromEngine(engineElement); |
| 404 expect(element.kind, ElementKind.UNKNOWN); | 408 expect(element.kind, ElementKind.UNKNOWN); |
| 405 expect(element.name, 'dynamic'); | 409 expect(element.name, 'dynamic'); |
| 406 expect(element.location, isNull); | 410 expect(element.location, isNull); |
| 407 expect(element.parameters, isNull); | 411 expect(element.parameters, isNull); |
| 408 expect(element.returnType, isNull); | 412 expect(element.returnType, isNull); |
| 409 expect(element.flags, 0); | 413 expect(element.flags, 0); |
| 410 } | 414 } |
| 411 } | 415 } |
| 416 | |
| 417 /** | |
| 418 * Helper class for testing the correspondence between an analysis engine enum | |
| 419 * and an analysis server API enum. | |
| 420 */ | |
| 421 class EnumTester<EngineEnum, ApiEnum extends Enum> { | |
| 422 /** | |
| 423 * Test that the function [convert] properly converts all possible values of | |
| 424 * [EngineEnum] to an [ApiEnum] with the same name, with the exceptions noted | |
| 425 * in [exceptions]. For each key in [exceptions], if the corresponding value | |
| 426 * is null, then we check that converting the given key results in an error. | |
| 427 * If the corresponding value is an [ApiEnum], then we check that converting | |
| 428 * the given key results in the given value. | |
| 429 */ | |
| 430 void run(ApiEnum convert(EngineEnum value), {Map<EngineEnum, | |
| 431 ApiEnum> exceptions: const {}}) { | |
| 432 ClassMirror engineClass = reflectClass(EngineEnum); | |
| 433 engineClass.staticMembers.forEach((Symbol symbol, MethodMirror method) { | |
| 434 if (symbol == #values) { | |
| 435 return; | |
| 436 } | |
| 437 if (!method.isGetter) { | |
| 438 return; | |
| 439 } | |
| 440 String enumName = MirrorSystem.getName(symbol); | |
| 441 EngineEnum engineValue = engineClass.getField(symbol).reflectee; | |
| 442 expect(engineValue, new isInstanceOf<EngineEnum>()); | |
| 443 if (exceptions.containsKey(engineValue)) { | |
| 444 ApiEnum expectedResult = exceptions[engineValue]; | |
| 445 if (expectedResult == null) { | |
| 446 expect(() { | |
| 447 convert(engineValue); | |
| 448 }, throws); | |
| 449 } else { | |
| 450 ApiEnum apiValue = convert(engineValue); | |
| 451 expect(apiValue, equals(expectedResult)); | |
| 452 } | |
| 453 } else { | |
| 454 ApiEnum apiValue = convert(engineValue); | |
| 455 expect(apiValue.name, equals(enumName)); | |
| 456 } | |
| 457 }); | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 | |
| 462 @ReflectiveTestCase() | |
| 463 class EnumTest { | |
| 464 void test_AnalysisErrorSeverity() { | |
| 465 new EnumTester<engine.ErrorSeverity, AnalysisErrorSeverity>().run( | |
| 466 (engine.ErrorSeverity engineErrorSeverity) => | |
| 467 new AnalysisErrorSeverity(engineErrorSeverity.name), | |
| 468 exceptions: { | |
| 469 engine.ErrorSeverity.NONE: null | |
| 470 }); | |
| 471 } | |
| 472 | |
| 473 void test_AnalysisErrorType() { | |
| 474 new EnumTester<engine.ErrorType, AnalysisErrorType>().run( | |
| 475 (engine.ErrorType engineErrorType) => | |
| 476 new AnalysisErrorType(engineErrorType.name)); | |
| 477 } | |
| 478 | |
| 479 void test_ElementKind() { | |
| 480 new EnumTester<engine.ElementKind, ElementKind>().run( | |
| 481 newElementKind_fromEngine, | |
| 482 exceptions: { | |
| 483 // TODO(paulberry): do any of the exceptions below constitute bugs? | |
|
Brian Wilkerson
2014/10/09 21:41:22
Yes. Some of these can almost certainly get passed
scheglov
2014/10/09 21:44:16
All these ElementKind values represent features th
| |
| 484 engine.ElementKind.ANGULAR_FORMATTER: ElementKind.UNKNOWN, | |
| 485 engine.ElementKind.ANGULAR_COMPONENT: ElementKind.UNKNOWN, | |
| 486 engine.ElementKind.ANGULAR_CONTROLLER: ElementKind.UNKNOWN, | |
| 487 engine.ElementKind.ANGULAR_DIRECTIVE: ElementKind.UNKNOWN, | |
| 488 engine.ElementKind.ANGULAR_PROPERTY: ElementKind.UNKNOWN, | |
| 489 engine.ElementKind.ANGULAR_SCOPE_PROPERTY: ElementKind.UNKNOWN, | |
| 490 engine.ElementKind.ANGULAR_SELECTOR: ElementKind.UNKNOWN, | |
| 491 engine.ElementKind.ANGULAR_VIEW: ElementKind.UNKNOWN, | |
| 492 engine.ElementKind.DYNAMIC: ElementKind.UNKNOWN, | |
| 493 engine.ElementKind.EMBEDDED_HTML_SCRIPT: ElementKind.UNKNOWN, | |
| 494 engine.ElementKind.ERROR: ElementKind.UNKNOWN, | |
| 495 engine.ElementKind.EXPORT: ElementKind.UNKNOWN, | |
| 496 engine.ElementKind.EXTERNAL_HTML_SCRIPT: ElementKind.UNKNOWN, | |
| 497 engine.ElementKind.HTML: ElementKind.UNKNOWN, | |
| 498 engine.ElementKind.IMPORT: ElementKind.UNKNOWN, | |
| 499 engine.ElementKind.NAME: ElementKind.UNKNOWN, | |
| 500 engine.ElementKind.POLYMER_ATTRIBUTE: ElementKind.UNKNOWN, | |
| 501 engine.ElementKind.POLYMER_TAG_DART: ElementKind.UNKNOWN, | |
| 502 engine.ElementKind.POLYMER_TAG_HTML: ElementKind.UNKNOWN, | |
| 503 engine.ElementKind.UNIVERSE: ElementKind.UNKNOWN | |
| 504 }); | |
| 505 } | |
| 506 | |
| 507 void test_SearchResultKind() { | |
| 508 // TODO(paulberry): why does the MatchKind class exist at all? Can't we | |
| 509 // use SearchResultKind inside the analysis server? | |
|
scheglov
2014/10/09 21:44:16
We could, but it is kind of mixing layers here.
Se
| |
| 510 new EnumTester<MatchKind, SearchResultKind>().run( | |
| 511 newSearchResultKind_fromEngine, | |
| 512 exceptions: { | |
| 513 // TODO(paulberry): do any of the exceptions below constitute bugs? | |
|
Brian Wilkerson
2014/10/09 21:41:22
I think these also fall into the "they should be d
| |
| 514 MatchKind.ANGULAR_REFERENCE: SearchResultKind.UNKNOWN, | |
| 515 MatchKind.ANGULAR_CLOSING_TAG_REFERENCE: SearchResultKind.UNKNOWN | |
| 516 }); | |
| 517 } | |
| 518 } | |
| OLD | NEW |