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

Side by Side Diff: pkg/analysis_server/test/analysis/notification_outline_test.dart

Issue 3009713002: Add test structure to the outline from server
Patch Set: complete implementation Created 3 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
« no previous file with comments | « pkg/analysis_server/lib/src/computer/computer_outline.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 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analysis_server/protocol/protocol.dart'; 7 import 'package:analysis_server/protocol/protocol.dart';
8 import 'package:analysis_server/protocol/protocol_constants.dart'; 8 import 'package:analysis_server/protocol/protocol_constants.dart';
9 import 'package:analysis_server/protocol/protocol_generated.dart'; 9 import 'package:analysis_server/protocol/protocol_generated.dart';
10 import 'package:analyzer_plugin/protocol/protocol_common.dart'; 10 import 'package:analyzer_plugin/protocol/protocol_common.dart';
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 expect(element_MyEnum.returnType, null); 295 expect(element_MyEnum.returnType, null);
296 // MyEnum children 296 // MyEnum children
297 List<Outline> outlines_MyEnum = outline_MyEnum.children; 297 List<Outline> outlines_MyEnum = outline_MyEnum.children;
298 expect(outlines_MyEnum, hasLength(3)); 298 expect(outlines_MyEnum, hasLength(3));
299 _isEnumConstant(outlines_MyEnum[0], 'A'); 299 _isEnumConstant(outlines_MyEnum[0], 'A');
300 _isEnumConstant(outlines_MyEnum[1], 'B'); 300 _isEnumConstant(outlines_MyEnum[1], 'B');
301 _isEnumConstant(outlines_MyEnum[2], 'C'); 301 _isEnumConstant(outlines_MyEnum[2], 'C');
302 } 302 }
303 } 303 }
304 304
305 test_groupAndTest() async {
306 addTestFile('''
307 void group(name, closure) {}
308 void test(name) {}
309 void main() {
310 group('group1', () {
311 group('group1_1', () {
312 test('test1_1_1');
313 test('test1_1_2');
314 });
315 group('group1_2', () {
316 test('test1_2_1');
317 });
318 });
319 group('group2', () {
320 test('test2_1');
321 test('test2_2');
322 });
323 }
324 ''');
325 await prepareOutline();
326 // unit
327 List<Outline> unit_children = outline.children;
328 expect(unit_children, hasLength(3));
329 // main
330 Outline main_outline = unit_children[2];
331 _expect(main_outline,
332 kind: ElementKind.FUNCTION,
333 name: 'main',
334 offset: testCode.indexOf("main() {"),
335 parameters: '()',
336 returnType: 'void');
337 List<Outline> main_children = main_outline.children;
338 expect(main_children, hasLength(2));
339 // group1
340 Outline group1_outline = main_children[0];
341 _expect(group1_outline,
342 kind: ElementKind.UNKNOWN,
343 length: 5,
344 name: 'group group1',
345 offset: testCode.indexOf("group('group1'"));
346 List<Outline> group1_children = group1_outline.children;
347 expect(group1_children, hasLength(2));
348 // group1_1
349 Outline group1_1_outline = group1_children[0];
350 _expect(group1_1_outline,
351 kind: ElementKind.UNKNOWN,
352 length: 5,
353 name: 'group group1_1',
354 offset: testCode.indexOf("group('group1_1'"));
355 List<Outline> group1_1_children = group1_1_outline.children;
356 expect(group1_1_children, hasLength(2));
357 // test1_1_1
358 Outline test1_1_1_outline = group1_1_children[0];
359 _expect(test1_1_1_outline,
360 kind: ElementKind.UNKNOWN,
361 leaf: true,
362 length: 4,
363 name: 'test test1_1_1',
364 offset: testCode.indexOf("test('test1_1_1'"));
365 // test1_1_1
366 Outline test1_1_2_outline = group1_1_children[1];
367 _expect(test1_1_2_outline,
368 kind: ElementKind.UNKNOWN,
369 leaf: true,
370 length: 4,
371 name: 'test test1_1_2',
372 offset: testCode.indexOf("test('test1_1_2'"));
373 // group1_2
374 Outline group1_2_outline = group1_children[1];
375 _expect(group1_2_outline,
376 kind: ElementKind.UNKNOWN,
377 length: 5,
378 name: 'group group1_2',
379 offset: testCode.indexOf("group('group1_2'"));
380 List<Outline> group1_2_children = group1_2_outline.children;
381 expect(group1_2_children, hasLength(1));
382 // test2_1
383 Outline test1_2_1_outline = group1_2_children[0];
384 _expect(test1_2_1_outline,
385 kind: ElementKind.UNKNOWN,
386 leaf: true,
387 length: 4,
388 name: 'test test1_2_1',
389 offset: testCode.indexOf("test('test1_2_1'"));
390 // group2
391 Outline group2_outline = main_children[1];
392 _expect(group2_outline,
393 kind: ElementKind.UNKNOWN,
394 length: 5,
395 name: 'group group2',
396 offset: testCode.indexOf("group('group2'"));
397 List<Outline> group2_children = group2_outline.children;
398 expect(group2_children, hasLength(2));
399 // test2_1
400 Outline test2_1_outline = group2_children[0];
401 _expect(test2_1_outline,
402 kind: ElementKind.UNKNOWN,
403 leaf: true,
404 length: 4,
405 name: 'test test2_1',
406 offset: testCode.indexOf("test('test2_1'"));
407 // test2_2
408 Outline test2_2_outline = group2_children[1];
409 _expect(test2_2_outline,
410 kind: ElementKind.UNKNOWN,
411 leaf: true,
412 length: 4,
413 name: 'test test2_2',
414 offset: testCode.indexOf("test('test2_2'"));
415 }
416
305 /** 417 /**
306 * Code like this caused NPE in the past. 418 * Code like this caused NPE in the past.
307 * 419 *
308 * https://code.google.com/p/dart/issues/detail?id=21373 420 * https://code.google.com/p/dart/issues/detail?id=21373
309 */ 421 */
310 test_invalidGetterInConstructor() async { 422 test_invalidGetterInConstructor() async {
311 addTestFile(''' 423 addTestFile('''
312 class A { 424 class A {
313 A() { 425 A() {
314 get badGetter { 426 get badGetter {
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 { 980 {
869 Location location = element.location; 981 Location location = element.location;
870 expect(location.offset, testCode.indexOf("propB(int v) {}")); 982 expect(location.offset, testCode.indexOf("propB(int v) {}"));
871 expect(location.length, "propB".length); 983 expect(location.length, "propB".length);
872 } 984 }
873 expect(element.parameters, "(int v)"); 985 expect(element.parameters, "(int v)");
874 expect(element.returnType, ""); 986 expect(element.returnType, "");
875 } 987 }
876 } 988 }
877 989
990 void _expect(Outline outline,
991 {ElementKind kind,
992 bool leaf: false,
993 int length,
994 String name,
995 int offset,
996 String parameters,
997 String returnType}) {
998 Element element = outline.element;
999 Location location = element.location;
1000
1001 if (kind != null) {
1002 expect(element.kind, kind);
1003 }
1004 if (leaf) {
1005 expect(outline.children, isNull);
1006 }
1007 length ??= name?.length;
1008 if (length != null) {
1009 expect(location.length, length);
1010 }
1011 if (name != null) {
1012 expect(element.name, name);
1013 }
1014 if (offset != null) {
1015 expect(location.offset, offset);
1016 }
1017 if (parameters != null) {
1018 expect(element.parameters, parameters);
1019 }
1020 if (returnType != null) {
1021 expect(element.returnType, returnType);
1022 }
1023 }
1024
878 void _isEnumConstant(Outline outline, String name) { 1025 void _isEnumConstant(Outline outline, String name) {
879 Element element = outline.element; 1026 Element element = outline.element;
880 expect(element.kind, ElementKind.ENUM_CONSTANT); 1027 expect(element.kind, ElementKind.ENUM_CONSTANT);
881 expect(element.name, name); 1028 expect(element.name, name);
882 expect(element.parameters, isNull); 1029 expect(element.parameters, isNull);
883 expect(element.returnType, isNull); 1030 expect(element.returnType, isNull);
884 } 1031 }
885 } 1032 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/computer/computer_outline.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698