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

Side by Side Diff: packages/analyzer/test/dart/ast/visitor_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer.test.dart.ast.visitor_test;
6
7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:test_reflective_loader/test_reflective_loader.dart';
10 import 'package:unittest/unittest.dart';
11
12 import '../../generated/parser_test.dart' show ParserTestCase;
13 import '../../generated/test_support.dart';
14 import '../../utils.dart';
15
16 main() {
17 initializeTestEnvironment();
18 defineReflectiveTests(BreadthFirstVisitorTest);
19 }
20
21 @reflectiveTest
22 class BreadthFirstVisitorTest extends ParserTestCase {
23 void test_it() {
24 String source = r'''
25 class A {
26 bool get g => true;
27 }
28 class B {
29 int f() {
30 num q() {
31 return 3;
32 }
33 return q() + 4;
34 }
35 }
36 A f(var p) {
37 if ((p as A).g) {
38 return p;
39 } else {
40 return null;
41 }
42 }''';
43 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source);
44 List<AstNode> nodes = new List<AstNode>();
45 BreadthFirstVisitor<Object> visitor =
46 new _BreadthFirstVisitorTestHelper(nodes);
47 visitor.visitAllNodes(unit);
48 expect(nodes, hasLength(59));
49 EngineTestCase.assertInstanceOf(
50 (obj) => obj is CompilationUnit, CompilationUnit, nodes[0]);
51 EngineTestCase.assertInstanceOf(
52 (obj) => obj is ClassDeclaration, ClassDeclaration, nodes[2]);
53 EngineTestCase.assertInstanceOf(
54 (obj) => obj is FunctionDeclaration, FunctionDeclaration, nodes[3]);
55 EngineTestCase.assertInstanceOf(
56 (obj) => obj is FunctionDeclarationStatement,
57 FunctionDeclarationStatement,
58 nodes[27]);
59 EngineTestCase.assertInstanceOf(
60 (obj) => obj is IntegerLiteral, IntegerLiteral, nodes[58]);
61 //3
62 }
63 }
64
65 /**
66 * A helper class used to collect the nodes that were visited and to preserve
67 * the order in which they were visited.
68 */
69 class _BreadthFirstVisitorTestHelper extends BreadthFirstVisitor<Object> {
70 List<AstNode> nodes;
71
72 _BreadthFirstVisitorTestHelper(this.nodes) : super();
73
74 @override
75 Object visitNode(AstNode node) {
76 nodes.add(node);
77 return super.visitNode(node);
78 }
79 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/dart/ast/test_all.dart ('k') | packages/analyzer/test/dart/element/element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698