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

Side by Side Diff: pkg/analyzer/test/generated/ast_test.dart

Issue 1490933002: New NodeLocator which uses positions of characters, not between them. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/analyzer/lib/src/task/dart.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 engine.ast_test; 5 library engine.ast_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/java_core.dart'; 8 import 'package:analyzer/src/generated/java_core.dart';
9 import 'package:analyzer/src/generated/java_engine.dart' show Predicate; 9 import 'package:analyzer/src/generated/java_engine.dart' show Predicate;
10 import 'package:analyzer/src/generated/java_engine.dart'; 10 import 'package:analyzer/src/generated/java_engine.dart';
(...skipping 11 matching lines...) Expand all
22 initializeTestEnvironment(); 22 initializeTestEnvironment();
23 runReflectiveTests(BreadthFirstVisitorTest); 23 runReflectiveTests(BreadthFirstVisitorTest);
24 runReflectiveTests(ClassDeclarationTest); 24 runReflectiveTests(ClassDeclarationTest);
25 runReflectiveTests(ClassTypeAliasTest); 25 runReflectiveTests(ClassTypeAliasTest);
26 runReflectiveTests(ConstantEvaluatorTest); 26 runReflectiveTests(ConstantEvaluatorTest);
27 runReflectiveTests(ConstructorDeclarationTest); 27 runReflectiveTests(ConstructorDeclarationTest);
28 runReflectiveTests(FieldFormalParameterTest); 28 runReflectiveTests(FieldFormalParameterTest);
29 runReflectiveTests(IndexExpressionTest); 29 runReflectiveTests(IndexExpressionTest);
30 runReflectiveTests(NodeListTest); 30 runReflectiveTests(NodeListTest);
31 runReflectiveTests(NodeLocatorTest); 31 runReflectiveTests(NodeLocatorTest);
32 runReflectiveTests(NodeLocator2Test);
32 runReflectiveTests(SimpleIdentifierTest); 33 runReflectiveTests(SimpleIdentifierTest);
33 runReflectiveTests(SimpleStringLiteralTest); 34 runReflectiveTests(SimpleStringLiteralTest);
34 runReflectiveTests(StringInterpolationTest); 35 runReflectiveTests(StringInterpolationTest);
35 runReflectiveTests(ToSourceVisitorTest); 36 runReflectiveTests(ToSourceVisitorTest);
36 runReflectiveTests(VariableDeclarationTest); 37 runReflectiveTests(VariableDeclarationTest);
37 } 38 }
38 39
39 class AssignmentKind extends Enum<AssignmentKind> { 40 class AssignmentKind extends Enum<AssignmentKind> {
40 static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0); 41 static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0);
41 42
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 try { 939 try {
939 javaListSet(list, 1, node); 940 javaListSet(list, 1, node);
940 fail("Expected IndexOutOfBoundsException"); 941 fail("Expected IndexOutOfBoundsException");
941 } on RangeError { 942 } on RangeError {
942 // Expected 943 // Expected
943 } 944 }
944 } 945 }
945 } 946 }
946 947
947 @reflectiveTest 948 @reflectiveTest
949 class NodeLocator2Test extends ParserTestCase {
950 void test_onlyStartOffset() {
951 CompilationUnit unit = ParserTestCase.parseCompilationUnit(' int vv;');
952 TopLevelVariableDeclaration declaration = unit.declarations[0];
953 VariableDeclarationList variableList = declaration.variables;
954 Identifier typeName = variableList.type.name;
955 expect(new NodeLocator2(0).searchWithin(unit), same(unit));
956 expect(new NodeLocator2(1).searchWithin(unit), same(typeName));
957 expect(new NodeLocator2(2).searchWithin(unit), same(typeName));
958 expect(new NodeLocator2(3).searchWithin(unit), same(typeName));
959 expect(new NodeLocator2(4).searchWithin(unit), same(variableList));
960 }
961
962 void test_startEndOffset() {
963 CompilationUnit unit = ParserTestCase.parseCompilationUnit(' int vv; ');
964 TopLevelVariableDeclaration declaration = unit.declarations[0];
965 VariableDeclarationList variableList = declaration.variables;
966 Identifier typeName = variableList.type.name;
967 SimpleIdentifier varName = variableList.variables[0].name;
968 expect(new NodeLocator2(0, 2).searchWithin(unit), same(unit));
969 expect(new NodeLocator2(1, 2).searchWithin(unit), same(typeName));
970 expect(new NodeLocator2(1, 3).searchWithin(unit), same(typeName));
971 expect(new NodeLocator2(1, 4).searchWithin(unit), same(variableList));
972 expect(new NodeLocator2(5, 6).searchWithin(unit), same(varName));
973 expect(new NodeLocator2(5, 7).searchWithin(unit), same(declaration));
974 }
975 }
976
977 @reflectiveTest
948 class NodeLocatorTest extends ParserTestCase { 978 class NodeLocatorTest extends ParserTestCase {
949 void test_range() { 979 void test_range() {
950 CompilationUnit unit = 980 CompilationUnit unit =
951 ParserTestCase.parseCompilationUnit("library myLib;"); 981 ParserTestCase.parseCompilationUnit("library myLib;");
952 _assertLocate( 982 _assertLocate(
953 unit, 4, 10, (node) => node is LibraryDirective, LibraryDirective); 983 unit, 4, 10, (node) => node is LibraryDirective, LibraryDirective);
954 } 984 }
955 985
956 void test_searchWithin_null() { 986 void test_searchWithin_null() {
957 NodeLocator locator = new NodeLocator(0, 0); 987 NodeLocator locator = new NodeLocator(0, 0);
(...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after
3920 static const List<WrapperKind> values = const [ 3950 static const List<WrapperKind> values = const [
3921 PREFIXED_LEFT, 3951 PREFIXED_LEFT,
3922 PREFIXED_RIGHT, 3952 PREFIXED_RIGHT,
3923 PROPERTY_LEFT, 3953 PROPERTY_LEFT,
3924 PROPERTY_RIGHT, 3954 PROPERTY_RIGHT,
3925 NONE 3955 NONE
3926 ]; 3956 ];
3927 3957
3928 const WrapperKind(String name, int ordinal) : super(name, ordinal); 3958 const WrapperKind(String name, int ordinal) : super(name, ordinal);
3929 } 3959 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698