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

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

Issue 1081103004: (belated) Tests for CompilationUnitElement.getElementAt(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element_test; 8 library engine.element_test;
9 9
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 ClassTypeAlias nodeA = elementA.node; 909 ClassTypeAlias nodeA = elementA.node;
910 expect(nodeA, isNotNull); 910 expect(nodeA, isNotNull);
911 expect(nodeA.name.name, "A"); 911 expect(nodeA.name.name, "A");
912 expect(nodeA.element, same(elementA)); 912 expect(nodeA.element, same(elementA));
913 } 913 }
914 } 914 }
915 } 915 }
916 916
917 @reflectiveTest 917 @reflectiveTest
918 class CompilationUnitElementImplTest extends EngineTestCase { 918 class CompilationUnitElementImplTest extends EngineTestCase {
919 void test_getElementAt() {
920 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
921 AnalysisContext context = contextHelper.context;
922 String code = r'''
923 class A {
924 int field;
925 }
926 main() {
927 int localVar = 42;
928 }
929 ''';
930 Source libSource = contextHelper.addSource("/my_lib.dart", code);
931 // prepare library/unit elements
932 LibraryElement libraryElement = context.computeLibraryElement(libSource);
933 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
934 // A
935 ClassElement elementA;
936 {
937 int offset = code.indexOf('A {');
938 elementA = unitElement.getElementAt(offset);
939 expect(elementA, isNotNull);
940 expect(elementA.enclosingElement, unitElement);
941 expect(elementA.name, 'A');
942 }
943 // A.field
944 {
945 int offset = code.indexOf('field;');
946 FieldElement element = unitElement.getElementAt(offset);
947 expect(element, isNotNull);
948 expect(element.enclosingElement, elementA);
949 expect(element.name, 'field');
950 }
951 // main
952 FunctionElement mainElement;
953 {
954 int offset = code.indexOf('main() {');
955 mainElement = unitElement.getElementAt(offset);
956 expect(mainElement, isNotNull);
957 expect(mainElement.enclosingElement, unitElement);
958 expect(mainElement.name, 'main');
959 }
960 // main.localVar
961 {
962 int offset = code.indexOf('localVar');
963 LocalVariableElement element = unitElement.getElementAt(offset);
964 expect(element, isNotNull);
965 expect(element.enclosingElement, mainElement);
966 expect(element.name, 'localVar');
967 }
968 // null
969 expect(unitElement.getElementAt(1000), isNull);
970 }
971
972 void test_getElementAt_multipleUnitsInLibrary() {
973 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
974 AnalysisContext context = contextHelper.context;
975 Source libSource = contextHelper.addSource("/my_lib.dart", r'''
976 library my_lib;
977 part 'unit_a.dart';
978 part 'unit_b.dart';
979 ''');
980 Source unitSourceA =
981 contextHelper.addSource("/unit_a.dart", 'part of my_lib;class A {}');
982 Source unitSourceB =
983 contextHelper.addSource("/unit_b.dart", 'part of my_lib;class B {}');
984 int offset = 'part of my_lib;class A {}'.indexOf('A {}');
985 // prepare library/unit elements
986 context.computeLibraryElement(libSource);
987 CompilationUnitElement unitElementA =
988 context.getCompilationUnitElement(unitSourceA, libSource);
989 CompilationUnitElement unitElementB =
990 context.getCompilationUnitElement(unitSourceB, libSource);
991 // A
992 {
993 ClassElement element = unitElementA.getElementAt(offset);
994 expect(element, isNotNull);
995 expect(element.enclosingElement, unitElementA);
996 expect(element.name, 'A');
997 }
998 // B
999 {
1000 ClassElement element = unitElementB.getElementAt(offset);
1001 expect(element, isNotNull);
1002 expect(element.enclosingElement, unitElementB);
1003 expect(element.name, 'B');
1004 }
1005 }
1006
919 void test_getEnum_declared() { 1007 void test_getEnum_declared() {
920 TestTypeProvider typeProvider = new TestTypeProvider(); 1008 TestTypeProvider typeProvider = new TestTypeProvider();
921 CompilationUnitElementImpl unit = 1009 CompilationUnitElementImpl unit =
922 ElementFactory.compilationUnit("/lib.dart"); 1010 ElementFactory.compilationUnit("/lib.dart");
923 String enumName = "E"; 1011 String enumName = "E";
924 ClassElement enumElement = 1012 ClassElement enumElement =
925 ElementFactory.enumElement(typeProvider, enumName); 1013 ElementFactory.enumElement(typeProvider, enumName);
926 unit.enums = <ClassElement>[enumElement]; 1014 unit.enums = <ClassElement>[enumElement];
927 expect(unit.getEnum(enumName), same(enumElement)); 1015 expect(unit.getEnum(enumName), same(enumElement));
928 } 1016 }
(...skipping 2943 matching lines...) Expand 10 before | Expand all | Expand 10 after
3872 } 3960 }
3873 3961
3874 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction 3962 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
3875 extends InterfaceTypeImpl { 3963 extends InterfaceTypeImpl {
3876 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) 3964 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0)
3877 : super.con1(arg0); 3965 : super.con1(arg0);
3878 3966
3879 @override 3967 @override
3880 bool get isDartCoreFunction => true; 3968 bool get isDartCoreFunction => true;
3881 } 3969 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698