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

Unified Diff: pkg/analyzer/test/generated/declaration_resolver_test.dart

Issue 1492373002: Fix for DeclarationResolver and invalid getters/setters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/test_all.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/declaration_resolver_test.dart
diff --git a/pkg/analyzer/test/generated/declaration_resolver_test.dart b/pkg/analyzer/test/generated/declaration_resolver_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a3d0b6628946eba19c20a68d4128920feb234ce2
--- /dev/null
+++ b/pkg/analyzer/test/generated/declaration_resolver_test.dart
@@ -0,0 +1,98 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library engine.declaration_resolver_test;
+
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/element.dart';
+import 'package:analyzer/src/generated/resolver.dart';
+import 'package:unittest/unittest.dart';
+
+import '../reflective_tests.dart';
+import '../utils.dart';
+import 'resolver_test.dart';
+import 'test_support.dart';
+
+main() {
+ initializeTestEnvironment();
+ runReflectiveTests(DeclarationResolverTest);
+}
+
+@reflectiveTest
+class DeclarationResolverTest extends ResolverTestCase {
+ @override
+ void setUp() {
+ super.setUp();
+ }
+
+ void test_functionDeclaration_getter() {
+ String code = r'''
+int get zzz => 42;
+''';
+ CompilationUnit unit = resolveSource(code);
+ PropertyAccessorElement getterElement =
+ findSimpleIdentifier(unit, code, 'zzz =>').staticElement;
+ expect(getterElement.isGetter, isTrue);
+ // re-resolve
+ CompilationUnit unit2 = _cloneResolveUnit(unit);
+ SimpleIdentifier getterName = findSimpleIdentifier(unit2, code, 'zzz =>');
+ expect(getterName.staticElement, same(getterElement));
+ }
+
+ void test_functionDeclaration_setter() {
+ String code = r'''
+void set zzz(_) {}
+''';
+ CompilationUnit unit = resolveSource(code);
+ PropertyAccessorElement setterElement =
+ findSimpleIdentifier(unit, code, 'zzz(_)').staticElement;
+ expect(setterElement.isSetter, isTrue);
+ // re-resolve
+ CompilationUnit unit2 = _cloneResolveUnit(unit);
+ SimpleIdentifier getterName = findSimpleIdentifier(unit2, code, 'zzz(_)');
+ expect(getterName.staticElement, same(setterElement));
+ }
+
+ void test_invalid_functionDeclaration_getter_inFunction() {
+ String code = r'''
+main() {
+ int get zzz => 42;
+}
+''';
+ CompilationUnit unit = resolveSource(code);
+ FunctionElement getterElement =
+ findSimpleIdentifier(unit, code, 'zzz =>').staticElement;
+ // re-resolve
+ CompilationUnit unit2 = _cloneResolveUnit(unit);
+ SimpleIdentifier getterName = findSimpleIdentifier(unit2, code, 'zzz =>');
+ expect(getterName.staticElement, same(getterElement));
+ }
+
+ void test_invalid_functionDeclaration_setter_inFunction() {
+ String code = r'''
+main() {
+ set zzz(x) {}
+}
+''';
+ CompilationUnit unit = resolveSource(code);
+ FunctionElement setterElement =
+ findSimpleIdentifier(unit, code, 'zzz(x)').staticElement;
+ // re-resolve
+ CompilationUnit unit2 = _cloneResolveUnit(unit);
+ SimpleIdentifier setterName = findSimpleIdentifier(unit2, code, 'zzz(x)');
+ expect(setterName.staticElement, same(setterElement));
+ }
+
+ static SimpleIdentifier findSimpleIdentifier(
+ AstNode root, String code, String search) {
+ return EngineTestCase.findNode(
+ root, code, search, (n) => n is SimpleIdentifier);
+ }
+
+ static CompilationUnit _cloneResolveUnit(CompilationUnit unit) {
+ CompilationUnit clonedUnit = AstCloner.clone(unit);
+ new DeclarationResolver().resolve(clonedUnit, unit.element);
+ return clonedUnit;
+ }
+}
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698