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

Side by Side Diff: pkg/analysis_server/test/computer/element_test.dart

Issue 529313002: Fix for NPE in the server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/protocol.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 library test.computer.element; 5 library test.computer.element;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_testing/abstract_context.dart'; 8 import 'package:analysis_testing/abstract_context.dart';
9 import 'package:analysis_testing/reflective_tests.dart'; 9 import 'package:analysis_testing/reflective_tests.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart' as engine; 11 import 'package:analyzer/src/generated/element.dart' as engine;
12 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; 13 import 'package:analyzer/src/generated/utilities_dart.dart' as engine;
14 import 'package:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
15 15
16 16
17 17
18 main() { 18 main() {
19 groupSep = ' | '; 19 groupSep = ' | ';
20 runReflectiveTests(ElementTest); 20 runReflectiveTests(ElementTest);
21 runReflectiveTests(ElementKindTest); 21 runReflectiveTests(ElementKindTest);
22 } 22 }
23 23
24 24
25 class ElementKindTest { 25 class ElementKindTest {
26 void test_toString() { 26 void test_fromEngine() {
27 expect(ElementKind.CLASS.toString(), 'ElementKind.CLASS'); 27 expect(
28 expect(ElementKind.COMPILATION_UNIT.toString(), 28 new ElementKind.fromEngine(engine.ElementKind.CLASS),
29 'ElementKind.COMPILATION_UNIT'); 29 ElementKind.CLASS);
30 expect(
31 new ElementKind.fromEngine(engine.ElementKind.COMPILATION_UNIT),
32 ElementKind.COMPILATION_UNIT);
33 expect(
34 new ElementKind.fromEngine(engine.ElementKind.CONSTRUCTOR),
35 ElementKind.CONSTRUCTOR);
36 expect(
37 new ElementKind.fromEngine(engine.ElementKind.FIELD),
38 ElementKind.FIELD);
39 expect(
40 new ElementKind.fromEngine(engine.ElementKind.FUNCTION),
41 ElementKind.FUNCTION);
42 expect(
43 new ElementKind.fromEngine(engine.ElementKind.FUNCTION_TYPE_ALIAS),
44 ElementKind.FUNCTION_TYPE_ALIAS);
45 expect(
46 new ElementKind.fromEngine(engine.ElementKind.GETTER),
47 ElementKind.GETTER);
48 expect(
49 new ElementKind.fromEngine(engine.ElementKind.LIBRARY),
50 ElementKind.LIBRARY);
51 expect(
52 new ElementKind.fromEngine(engine.ElementKind.LOCAL_VARIABLE),
53 ElementKind.LOCAL_VARIABLE);
54 expect(
55 new ElementKind.fromEngine(engine.ElementKind.METHOD),
56 ElementKind.METHOD);
57 expect(
58 new ElementKind.fromEngine(engine.ElementKind.PARAMETER),
59 ElementKind.PARAMETER);
60 expect(
61 new ElementKind.fromEngine(engine.ElementKind.SETTER),
62 ElementKind.SETTER);
63 expect(
64 new ElementKind.fromEngine(engine.ElementKind.TOP_LEVEL_VARIABLE),
65 ElementKind.TOP_LEVEL_VARIABLE);
66 expect(
67 new ElementKind.fromEngine(engine.ElementKind.TYPE_PARAMETER),
68 ElementKind.TYPE_PARAMETER);
69 expect(
70 new ElementKind.fromEngine(engine.ElementKind.ANGULAR_COMPONENT),
71 ElementKind.UNKNOWN);
30 } 72 }
31 73
32 void test_string_constructor() { 74 void test_string_constructor() {
33 expect(new ElementKind(ElementKind.CLASS.name), ElementKind.CLASS); 75 expect(new ElementKind(ElementKind.CLASS.name), ElementKind.CLASS);
34 expect( 76 expect(
35 new ElementKind(ElementKind.CLASS_TYPE_ALIAS.name), 77 new ElementKind(ElementKind.CLASS_TYPE_ALIAS.name),
36 ElementKind.CLASS_TYPE_ALIAS); 78 ElementKind.CLASS_TYPE_ALIAS);
37 expect( 79 expect(
38 new ElementKind(ElementKind.COMPILATION_UNIT.name), 80 new ElementKind(ElementKind.COMPILATION_UNIT.name),
39 ElementKind.COMPILATION_UNIT); 81 ElementKind.COMPILATION_UNIT);
(...skipping 28 matching lines...) Expand all
68 ElementKind.UNIT_TEST_TEST); 110 ElementKind.UNIT_TEST_TEST);
69 expect( 111 expect(
70 new ElementKind(ElementKind.UNIT_TEST_GROUP.name), 112 new ElementKind(ElementKind.UNIT_TEST_GROUP.name),
71 ElementKind.UNIT_TEST_GROUP); 113 ElementKind.UNIT_TEST_GROUP);
72 expect(new ElementKind(ElementKind.UNKNOWN.name), ElementKind.UNKNOWN); 114 expect(new ElementKind(ElementKind.UNKNOWN.name), ElementKind.UNKNOWN);
73 expect(() { 115 expect(() {
74 new ElementKind('no-such-kind'); 116 new ElementKind('no-such-kind');
75 }, throws); 117 }, throws);
76 } 118 }
77 119
78 void test_fromEngine() { 120 void test_toString() {
79 expect( 121 expect(ElementKind.CLASS.toString(), 'ElementKind.CLASS');
80 new ElementKind.fromEngine(engine.ElementKind.CLASS), 122 expect(ElementKind.COMPILATION_UNIT.toString(),
81 ElementKind.CLASS); 123 'ElementKind.COMPILATION_UNIT');
82 expect(
83 new ElementKind.fromEngine(engine.ElementKind.COMPILATION_UNIT),
84 ElementKind.COMPILATION_UNIT);
85 expect(
86 new ElementKind.fromEngine(engine.ElementKind.CONSTRUCTOR),
87 ElementKind.CONSTRUCTOR);
88 expect(
89 new ElementKind.fromEngine(engine.ElementKind.FIELD),
90 ElementKind.FIELD);
91 expect(
92 new ElementKind.fromEngine(engine.ElementKind.FUNCTION),
93 ElementKind.FUNCTION);
94 expect(
95 new ElementKind.fromEngine(engine.ElementKind.FUNCTION_TYPE_ALIAS),
96 ElementKind.FUNCTION_TYPE_ALIAS);
97 expect(
98 new ElementKind.fromEngine(engine.ElementKind.GETTER),
99 ElementKind.GETTER);
100 expect(
101 new ElementKind.fromEngine(engine.ElementKind.LIBRARY),
102 ElementKind.LIBRARY);
103 expect(
104 new ElementKind.fromEngine(engine.ElementKind.LOCAL_VARIABLE),
105 ElementKind.LOCAL_VARIABLE);
106 expect(
107 new ElementKind.fromEngine(engine.ElementKind.METHOD),
108 ElementKind.METHOD);
109 expect(
110 new ElementKind.fromEngine(engine.ElementKind.PARAMETER),
111 ElementKind.PARAMETER);
112 expect(
113 new ElementKind.fromEngine(engine.ElementKind.SETTER),
114 ElementKind.SETTER);
115 expect(
116 new ElementKind.fromEngine(engine.ElementKind.TOP_LEVEL_VARIABLE),
117 ElementKind.TOP_LEVEL_VARIABLE);
118 expect(
119 new ElementKind.fromEngine(engine.ElementKind.TYPE_PARAMETER),
120 ElementKind.TYPE_PARAMETER);
121 expect(
122 new ElementKind.fromEngine(engine.ElementKind.ANGULAR_COMPONENT),
123 ElementKind.UNKNOWN);
124 } 124 }
125 } 125 }
126 126
127 127
128 @ReflectiveTestCase() 128 @ReflectiveTestCase()
129 class ElementTest extends AbstractContextTest { 129 class ElementTest extends AbstractContextTest {
130 engine.Element findElementInUnit(CompilationUnit unit, String name, 130 engine.Element findElementInUnit(CompilationUnit unit, String name,
131 [engine.ElementKind kind]) { 131 [engine.ElementKind kind]) {
132 return findChildElement(unit.element, name, kind); 132 return findChildElement(unit.element, name, kind);
133 } 133 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 expect(location.file, '/test.dart'); 247 expect(location.file, '/test.dart');
248 expect(location.offset, 32); 248 expect(location.offset, 32);
249 expect(location.length, 'myGetter'.length); 249 expect(location.length, 'myGetter'.length);
250 expect(location.startLine, 2); 250 expect(location.startLine, 2);
251 expect(location.startColumn, 23); 251 expect(location.startColumn, 23);
252 } 252 }
253 expect(element.parameters, '(int a, {String b})'); 253 expect(element.parameters, '(int a, {String b})');
254 expect(element.returnType, 'List<String>'); 254 expect(element.returnType, 'List<String>');
255 expect(element.flags, Element.FLAG_STATIC); 255 expect(element.flags, Element.FLAG_STATIC);
256 } 256 }
257
258 void test_fromElement_dynamic() {
259 var engineElement = engine.DynamicElementImpl.instance;
260 // create notification Element
261 Element element = new Element.fromEngine(engineElement);
262 expect(element.kind, ElementKind.UNKNOWN);
263 expect(element.name, 'dynamic');
264 expect(element.location, isNull);
265 expect(element.parameters, isNull);
266 expect(element.returnType, isNull);
267 expect(element.flags, 0);
268 }
257 } 269 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/protocol.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698