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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library engine.declaration_resolver_test;
6
7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/resolver.dart';
10 import 'package:unittest/unittest.dart';
11
12 import '../reflective_tests.dart';
13 import '../utils.dart';
14 import 'resolver_test.dart';
15 import 'test_support.dart';
16
17 main() {
18 initializeTestEnvironment();
19 runReflectiveTests(DeclarationResolverTest);
20 }
21
22 @reflectiveTest
23 class DeclarationResolverTest extends ResolverTestCase {
24 @override
25 void setUp() {
26 super.setUp();
27 }
28
29 void test_functionDeclaration_getter() {
30 String code = r'''
31 int get zzz => 42;
32 ''';
33 CompilationUnit unit = resolveSource(code);
34 PropertyAccessorElement getterElement =
35 findSimpleIdentifier(unit, code, 'zzz =>').staticElement;
36 expect(getterElement.isGetter, isTrue);
37 // re-resolve
38 CompilationUnit unit2 = _cloneResolveUnit(unit);
39 SimpleIdentifier getterName = findSimpleIdentifier(unit2, code, 'zzz =>');
40 expect(getterName.staticElement, same(getterElement));
41 }
42
43 void test_functionDeclaration_setter() {
44 String code = r'''
45 void set zzz(_) {}
46 ''';
47 CompilationUnit unit = resolveSource(code);
48 PropertyAccessorElement setterElement =
49 findSimpleIdentifier(unit, code, 'zzz(_)').staticElement;
50 expect(setterElement.isSetter, isTrue);
51 // re-resolve
52 CompilationUnit unit2 = _cloneResolveUnit(unit);
53 SimpleIdentifier getterName = findSimpleIdentifier(unit2, code, 'zzz(_)');
54 expect(getterName.staticElement, same(setterElement));
55 }
56
57 void test_invalid_functionDeclaration_getter_inFunction() {
58 String code = r'''
59 main() {
60 int get zzz => 42;
61 }
62 ''';
63 CompilationUnit unit = resolveSource(code);
64 FunctionElement getterElement =
65 findSimpleIdentifier(unit, code, 'zzz =>').staticElement;
66 // re-resolve
67 CompilationUnit unit2 = _cloneResolveUnit(unit);
68 SimpleIdentifier getterName = findSimpleIdentifier(unit2, code, 'zzz =>');
69 expect(getterName.staticElement, same(getterElement));
70 }
71
72 void test_invalid_functionDeclaration_setter_inFunction() {
73 String code = r'''
74 main() {
75 set zzz(x) {}
76 }
77 ''';
78 CompilationUnit unit = resolveSource(code);
79 FunctionElement setterElement =
80 findSimpleIdentifier(unit, code, 'zzz(x)').staticElement;
81 // re-resolve
82 CompilationUnit unit2 = _cloneResolveUnit(unit);
83 SimpleIdentifier setterName = findSimpleIdentifier(unit2, code, 'zzz(x)');
84 expect(setterName.staticElement, same(setterElement));
85 }
86
87 static SimpleIdentifier findSimpleIdentifier(
88 AstNode root, String code, String search) {
89 return EngineTestCase.findNode(
90 root, code, search, (n) => n is SimpleIdentifier);
91 }
92
93 static CompilationUnit _cloneResolveUnit(CompilationUnit unit) {
94 CompilationUnit clonedUnit = AstCloner.clone(unit);
95 new DeclarationResolver().resolve(clonedUnit, unit.element);
96 return clonedUnit;
97 }
98 }
OLDNEW
« 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