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

Side by Side Diff: pkg/analysis_server/test/services/correction/name_suggestion_test.dart

Issue 2969343002: Stop depending of visiting LocalVariableElement(s) in Executableelement.visitChildren(). (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « pkg/analysis_server/test/abstract_single_unit.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'package:analysis_server/src/services/correction/name_suggestion.dart'; 5 import 'package:analysis_server/src/services/correction/name_suggestion.dart';
6 import 'package:analyzer/dart/ast/ast.dart'; 6 import 'package:analyzer/dart/ast/ast.dart';
7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 7 import 'package:analyzer/dart/element/type.dart';
9 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; 9 import 'package:test_reflective_loader/test_reflective_loader.dart';
11 10
12 import '../../abstract_single_unit.dart'; 11 import '../../abstract_single_unit.dart';
13 12
14 main() { 13 main() {
15 defineReflectiveSuite(() { 14 defineReflectiveSuite(() {
16 defineReflectiveTests(VariableNameSuggestionTest); 15 defineReflectiveTests(VariableNameSuggestionTest);
17 }); 16 });
(...skipping 15 matching lines...) Expand all
33 } 32 }
34 33
35 test_forExpression_expectedType() async { 34 test_forExpression_expectedType() async {
36 await resolveTestUnit(''' 35 await resolveTestUnit('''
37 class TreeNode {} 36 class TreeNode {}
38 main() { 37 main() {
39 TreeNode node = null; 38 TreeNode node = null;
40 } 39 }
41 '''); 40 ''');
42 Set<String> excluded = new Set<String>.from([]); 41 Set<String> excluded = new Set<String>.from([]);
43 DartType expectedType = (findElement('node') as LocalVariableElement).type; 42 DartType expectedType = findLocalVariable('node').type;
44 Expression assignedExpression = 43 Expression assignedExpression =
45 findNodeAtString('null;', (node) => node is NullLiteral); 44 findNodeAtString('null;', (node) => node is NullLiteral);
46 List<String> suggestions = getVariableNameSuggestionsForExpression( 45 List<String> suggestions = getVariableNameSuggestionsForExpression(
47 expectedType, assignedExpression, excluded); 46 expectedType, assignedExpression, excluded);
48 expect(suggestions, unorderedEquals(['treeNode', 'node'])); 47 expect(suggestions, unorderedEquals(['treeNode', 'node']));
49 } 48 }
50 49
51 test_forExpression_expectedType_double() async { 50 test_forExpression_expectedType_double() async {
52 await resolveTestUnit(''' 51 await resolveTestUnit('''
53 main() { 52 main() {
54 double res = 0.0; 53 double res = 0.0;
55 } 54 }
56 '''); 55 ''');
57 DartType expectedType = (findElement('res') as LocalVariableElement).type; 56 DartType expectedType = findLocalVariable('res').type;
58 Expression assignedExpression = findNodeAtString('0.0;'); 57 Expression assignedExpression = findNodeAtString('0.0;');
59 // first choice for "double" is "d" 58 // first choice for "double" is "d"
60 expect( 59 expect(
61 getVariableNameSuggestionsForExpression( 60 getVariableNameSuggestionsForExpression(
62 expectedType, assignedExpression, new Set.from([])), 61 expectedType, assignedExpression, new Set.from([])),
63 unorderedEquals(['d'])); 62 unorderedEquals(['d']));
64 // if "d" is used, try "e", "f", etc 63 // if "d" is used, try "e", "f", etc
65 expect( 64 expect(
66 getVariableNameSuggestionsForExpression( 65 getVariableNameSuggestionsForExpression(
67 expectedType, assignedExpression, new Set.from(['d', 'e'])), 66 expectedType, assignedExpression, new Set.from(['d', 'e'])),
68 unorderedEquals(['f'])); 67 unorderedEquals(['f']));
69 } 68 }
70 69
71 test_forExpression_expectedType_int() async { 70 test_forExpression_expectedType_int() async {
72 await resolveTestUnit(''' 71 await resolveTestUnit('''
73 main() { 72 main() {
74 int res = 0; 73 int res = 0;
75 } 74 }
76 '''); 75 ''');
77 DartType expectedType = (findElement('res') as LocalVariableElement).type; 76 DartType expectedType = findLocalVariable('res').type;
78 Expression assignedExpression = findNodeAtString('0;'); 77 Expression assignedExpression = findNodeAtString('0;');
79 // first choice for "int" is "i" 78 // first choice for "int" is "i"
80 expect( 79 expect(
81 getVariableNameSuggestionsForExpression( 80 getVariableNameSuggestionsForExpression(
82 expectedType, assignedExpression, new Set.from([])), 81 expectedType, assignedExpression, new Set.from([])),
83 unorderedEquals(['i'])); 82 unorderedEquals(['i']));
84 // if "i" is used, try "j", "k", etc 83 // if "i" is used, try "j", "k", etc
85 expect( 84 expect(
86 getVariableNameSuggestionsForExpression( 85 getVariableNameSuggestionsForExpression(
87 expectedType, assignedExpression, new Set.from(['i', 'j'])), 86 expectedType, assignedExpression, new Set.from(['i', 'j'])),
88 unorderedEquals(['k'])); 87 unorderedEquals(['k']));
89 } 88 }
90 89
91 test_forExpression_expectedType_String() async { 90 test_forExpression_expectedType_String() async {
92 await resolveTestUnit(''' 91 await resolveTestUnit('''
93 main() { 92 main() {
94 String res = 'abc'; 93 String res = 'abc';
95 } 94 }
96 '''); 95 ''');
97 DartType expectedType = (findElement('res') as LocalVariableElement).type; 96 DartType expectedType = findLocalVariable('res').type;
98 Expression assignedExpression = findNodeAtString("'abc';"); 97 Expression assignedExpression = findNodeAtString("'abc';");
99 // first choice for "String" is "s" 98 // first choice for "String" is "s"
100 expect( 99 expect(
101 getVariableNameSuggestionsForExpression( 100 getVariableNameSuggestionsForExpression(
102 expectedType, assignedExpression, new Set.from([])), 101 expectedType, assignedExpression, new Set.from([])),
103 unorderedEquals(['s'])); 102 unorderedEquals(['s']));
104 } 103 }
105 104
106 test_forExpression_instanceCreation() async { 105 test_forExpression_instanceCreation() async {
107 verifyNoTestUnitErrors = false; 106 verifyNoTestUnitErrors = false;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 327 }
329 { 328 {
330 Set<String> excluded = new Set<String>.from(['world']); 329 Set<String> excluded = new Set<String>.from(['world']);
331 List<String> suggestions = 330 List<String> suggestions =
332 getVariableNameSuggestionsForText('Goodbye, cruel world!', excluded); 331 getVariableNameSuggestionsForText('Goodbye, cruel world!', excluded);
333 expect(suggestions, 332 expect(suggestions,
334 unorderedEquals(['goodbyeCruelWorld', 'cruelWorld', 'world2'])); 333 unorderedEquals(['goodbyeCruelWorld', 'cruelWorld', 'world2']));
335 } 334 }
336 } 335 }
337 } 336 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/abstract_single_unit.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698