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 'package:analysis_server/src/computer/element.dart'; | 7 import 'package:analysis_server/src/protocol2.dart'; |
8 import 'package:analysis_server/src/constants.dart'; | |
9 import 'package:analysis_server/src/protocol2.dart' show ElementKind; | |
10 import 'package:analysis_testing/abstract_context.dart'; | 8 import 'package:analysis_testing/abstract_context.dart'; |
11 import 'package:analysis_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
12 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
13 import 'package:analyzer/src/generated/element.dart' as engine; | 11 import 'package:analyzer/src/generated/element.dart' as engine; |
14 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
15 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; | 13 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; |
16 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
17 | 15 |
18 | 16 |
19 | 17 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 expect(location.file, '/test.dart'); | 247 expect(location.file, '/test.dart'); |
250 expect(location.offset, 32); | 248 expect(location.offset, 32); |
251 expect(location.length, 'myGetter'.length); | 249 expect(location.length, 'myGetter'.length); |
252 expect(location.startLine, 2); | 250 expect(location.startLine, 2); |
253 expect(location.startColumn, 23); | 251 expect(location.startColumn, 23); |
254 } | 252 } |
255 expect(element.parameters, '(int a, {String b})'); | 253 expect(element.parameters, '(int a, {String b})'); |
256 expect(element.returnType, 'List<String>'); | 254 expect(element.returnType, 'List<String>'); |
257 expect(element.flags, Element.FLAG_STATIC); | 255 expect(element.flags, Element.FLAG_STATIC); |
258 } | 256 } |
259 | |
260 void test_fromJson() { | |
261 var flags = | |
262 Element.FLAG_DEPRECATED | | |
263 Element.FLAG_PRIVATE | | |
264 Element.FLAG_STATIC; | |
265 var json = { | |
266 KIND: 'METHOD', | |
267 NAME: 'my name', | |
268 LOCATION: { | |
269 FILE: '/project/file.dart', | |
270 OFFSET: 1, | |
271 LENGTH: 2, | |
272 START_LINE: 3, | |
273 START_COLUMN: 4, | |
274 }, | |
275 FLAGS: flags, | |
276 PARAMETERS: '(int a, String b)', | |
277 RETURN_TYPE: 'List<String>' | |
278 }; | |
279 Element element = new Element.fromJson(json); | |
280 expect(element.kind, ElementKind.METHOD); | |
281 expect(element.name, 'my name'); | |
282 { | |
283 Location location = element.location; | |
284 expect(location.file, '/project/file.dart'); | |
285 expect(location.offset, 1); | |
286 expect(location.length, 2); | |
287 expect(location.startLine, 3); | |
288 expect(location.startColumn, 4); | |
289 } | |
290 expect(element.flags, flags); | |
291 expect(element.isAbstract, isFalse); | |
292 expect(element.isConst, isFalse); | |
293 expect(element.isDeprecated, isTrue); | |
294 expect(element.isFinal, isFalse); | |
295 expect(element.isPrivate, isTrue); | |
296 expect(element.isStatic, isTrue); | |
297 } | |
298 | |
299 void test_toJson() { | |
300 var json = { | |
301 KIND: 'METHOD', | |
302 NAME: 'my name', | |
303 LOCATION: { | |
304 FILE: '/project/file.dart', | |
305 OFFSET: 1, | |
306 LENGTH: 2, | |
307 START_LINE: 3, | |
308 START_COLUMN: 4, | |
309 }, | |
310 FLAGS: Element.FLAG_DEPRECATED | | |
311 Element.FLAG_PRIVATE | | |
312 Element.FLAG_STATIC, | |
313 PARAMETERS: '(int a, String b)', | |
314 RETURN_TYPE: 'List<String>' | |
315 }; | |
316 Element element = new Element.fromJson(json); | |
317 expect(element.toJson(), equals(json)); | |
318 } | |
319 } | 257 } |
OLD | NEW |