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

Unified Diff: pkg/analyzer/test/dart/ast/visitor_test.dart

Issue 1612933006: Moved the AST related tests to their new locations (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/test/dart/ast/test_all.dart ('k') | pkg/analyzer/test/dart/element/test_all.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/dart/ast/visitor_test.dart
diff --git a/pkg/analyzer/test/dart/ast/visitor_test.dart b/pkg/analyzer/test/dart/ast/visitor_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1645daaa53adaa299617ff2e8cd5d6df7523e21e
--- /dev/null
+++ b/pkg/analyzer/test/dart/ast/visitor_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library analyzer.test.dart.ast.visitor_test;
+
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/visitor.dart';
+import 'package:unittest/unittest.dart';
+
+import '../../generated/parser_test.dart' show ParserTestCase;
+import '../../generated/test_support.dart';
+import '../../reflective_tests.dart';
+import '../../utils.dart';
+
+main() {
+ initializeTestEnvironment();
+ runReflectiveTests(BreadthFirstVisitorTest);
+}
+
+@reflectiveTest
+class BreadthFirstVisitorTest extends ParserTestCase {
+ void test_it() {
+ String source = r'''
+class A {
+ bool get g => true;
+}
+class B {
+ int f() {
+ num q() {
+ return 3;
+ }
+ return q() + 4;
+ }
+}
+A f(var p) {
+ if ((p as A).g) {
+ return p;
+ } else {
+ return null;
+ }
+}''';
+ CompilationUnit unit = ParserTestCase.parseCompilationUnit(source);
+ List<AstNode> nodes = new List<AstNode>();
+ BreadthFirstVisitor<Object> visitor =
+ new _BreadthFirstVisitorTestHelper(nodes);
+ visitor.visitAllNodes(unit);
+ expect(nodes, hasLength(59));
+ EngineTestCase.assertInstanceOf(
+ (obj) => obj is CompilationUnit, CompilationUnit, nodes[0]);
+ EngineTestCase.assertInstanceOf(
+ (obj) => obj is ClassDeclaration, ClassDeclaration, nodes[2]);
+ EngineTestCase.assertInstanceOf(
+ (obj) => obj is FunctionDeclaration, FunctionDeclaration, nodes[3]);
+ EngineTestCase.assertInstanceOf(
+ (obj) => obj is FunctionDeclarationStatement,
+ FunctionDeclarationStatement,
+ nodes[27]);
+ EngineTestCase.assertInstanceOf(
+ (obj) => obj is IntegerLiteral, IntegerLiteral, nodes[58]);
+ //3
+ }
+}
+
+/**
+ * A helper class used to collect the nodes that were visited and to preserve
+ * the order in which they were visited.
+ */
+class _BreadthFirstVisitorTestHelper extends BreadthFirstVisitor<Object> {
+ List<AstNode> nodes;
+
+ _BreadthFirstVisitorTestHelper(this.nodes) : super();
+
+ @override
+ Object visitNode(AstNode node) {
+ nodes.add(node);
+ return super.visitNode(node);
+ }
+}
« no previous file with comments | « pkg/analyzer/test/dart/ast/test_all.dart ('k') | pkg/analyzer/test/dart/element/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698