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

Side by Side Diff: pkg/analyzer/test/src/dart/element/element_test.dart

Issue 1686893002: Consolidate the code that replaces a TypeParameter with its bound. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add unit tests. Created 4 years, 10 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/analyzer/test/generated/resolver_test.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 analyzer.test.src.dart.element.element_test; 5 library analyzer.test.src.dart.element.element_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 ElementFactory.functionTypeAliasElement('f'); 1850 ElementFactory.functionTypeAliasElement('f');
1851 FunctionTypeAliasElementImpl g = 1851 FunctionTypeAliasElementImpl g =
1852 ElementFactory.functionTypeAliasElement('g'); 1852 ElementFactory.functionTypeAliasElement('g');
1853 f.typeParameters = [ElementFactory.typeParameterElement('T')]; 1853 f.typeParameters = [ElementFactory.typeParameterElement('T')];
1854 f.parameters = [ElementFactory.positionalParameter2('x', g.type)]; 1854 f.parameters = [ElementFactory.positionalParameter2('x', g.type)];
1855 FunctionTypeImpl paramType = f.type.optionalParameterTypes[0]; 1855 FunctionTypeImpl paramType = f.type.optionalParameterTypes[0];
1856 expect(paramType.prunedTypedefs, hasLength(1)); 1856 expect(paramType.prunedTypedefs, hasLength(1));
1857 expect(paramType.prunedTypedefs[0], same(f)); 1857 expect(paramType.prunedTypedefs[0], same(f));
1858 } 1858 }
1859 1859
1860 void test_resolveToBound() {
1861 FunctionElementImpl f = ElementFactory.functionElement('f');
1862 FunctionTypeImpl type = f.type;
1863
1864 // Returns this.
1865 expect(type.resolveToBound(null), same(type));
1866 }
1867
1860 void test_returnType_pruned_no_type_arguments() { 1868 void test_returnType_pruned_no_type_arguments() {
1861 FunctionTypeAliasElementImpl f = 1869 FunctionTypeAliasElementImpl f =
1862 ElementFactory.functionTypeAliasElement('f'); 1870 ElementFactory.functionTypeAliasElement('f');
1863 FunctionTypeAliasElementImpl g = 1871 FunctionTypeAliasElementImpl g =
1864 ElementFactory.functionTypeAliasElement('g'); 1872 ElementFactory.functionTypeAliasElement('g');
1865 f.returnType = g.type; 1873 f.returnType = g.type;
1866 FunctionTypeImpl paramType = f.type.returnType; 1874 FunctionTypeImpl paramType = f.type.returnType;
1867 expect(paramType.prunedTypedefs, hasLength(1)); 1875 expect(paramType.prunedTypedefs, hasLength(1));
1868 expect(paramType.prunedTypedefs[0], same(f)); 1876 expect(paramType.prunedTypedefs[0], same(f));
1869 } 1877 }
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 // 3393 //
3386 ClassElementImpl classA = ElementFactory.classElement2("A"); 3394 ClassElementImpl classA = ElementFactory.classElement2("A");
3387 InterfaceType typeA = classA.type; 3395 InterfaceType typeA = classA.type;
3388 LibraryElementImpl library = 3396 LibraryElementImpl library =
3389 ElementFactory.library(createAnalysisContext(), "lib"); 3397 ElementFactory.library(createAnalysisContext(), "lib");
3390 CompilationUnitElement unit = library.definingCompilationUnit; 3398 CompilationUnitElement unit = library.definingCompilationUnit;
3391 (unit as CompilationUnitElementImpl).types = <ClassElement>[classA]; 3399 (unit as CompilationUnitElementImpl).types = <ClassElement>[classA];
3392 expect(typeA.lookUpSetter("s", library), isNull); 3400 expect(typeA.lookUpSetter("s", library), isNull);
3393 } 3401 }
3394 3402
3403 void test_resolveToBound() {
3404 InterfaceTypeImpl type =
3405 ElementFactory.classElement2("A").type as InterfaceTypeImpl;
3406
3407 // Returns this.
3408 expect(type.resolveToBound(null), same(type));
3409 }
3410
3395 void test_setTypeArguments() { 3411 void test_setTypeArguments() {
3396 InterfaceTypeImpl type = 3412 InterfaceTypeImpl type =
3397 ElementFactory.classElement2("A").type as InterfaceTypeImpl; 3413 ElementFactory.classElement2("A").type as InterfaceTypeImpl;
3398 List<DartType> typeArguments = <DartType>[ 3414 List<DartType> typeArguments = <DartType>[
3399 ElementFactory.classElement2("B").type, 3415 ElementFactory.classElement2("B").type,
3400 ElementFactory.classElement2("C").type 3416 ElementFactory.classElement2("C").type
3401 ]; 3417 ];
3402 type.typeArguments = typeArguments; 3418 type.typeArguments = typeArguments;
3403 expect(type.typeArguments, typeArguments); 3419 expect(type.typeArguments, typeArguments);
3404 } 3420 }
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
3929 TypeParameterElementImpl typeParameterT = 3945 TypeParameterElementImpl typeParameterT =
3930 new TypeParameterElementImpl.forNode(AstFactory.identifier3("T")); 3946 new TypeParameterElementImpl.forNode(AstFactory.identifier3("T"));
3931 typeParameterT.bound = classS.type; 3947 typeParameterT.bound = classS.type;
3932 TypeParameterTypeImpl typeParameterTypeT = 3948 TypeParameterTypeImpl typeParameterTypeT =
3933 new TypeParameterTypeImpl(typeParameterT); 3949 new TypeParameterTypeImpl(typeParameterT);
3934 // <T extends S> 3950 // <T extends S>
3935 // T << S 3951 // T << S
3936 expect(typeParameterTypeT.isMoreSpecificThan(classS.type), isTrue); 3952 expect(typeParameterTypeT.isMoreSpecificThan(classS.type), isTrue);
3937 } 3953 }
3938 3954
3955 void test_resolveToBound_unbound() {
3956 TypeParameterTypeImpl type = new TypeParameterTypeImpl(
3957 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")));
3958 // Returns whatever type is passed to resolveToBound().
3959 expect(type.resolveToBound(VoidTypeImpl.instance),
3960 same(VoidTypeImpl.instance));
3961 }
3962
3963 void test_resolveToBound_bound() {
3964 ClassElementImpl classS = ElementFactory.classElement2("A");
3965 TypeParameterElementImpl element =
3966 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"));
3967 element.bound = classS.type;
3968 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
3969 expect(type.resolveToBound(null), same(classS.type));
3970 }
3971
3972 void test_resolveToBound_nestedBound() {
3973 ClassElementImpl classS = ElementFactory.classElement2("A");
3974 TypeParameterElementImpl elementE =
3975 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"));
3976 elementE.bound = classS.type;
3977 TypeParameterTypeImpl typeE = new TypeParameterTypeImpl(elementE);
3978 TypeParameterElementImpl elementF =
3979 new TypeParameterElementImpl.forNode(AstFactory.identifier3("F"));
3980 elementF.bound = typeE;
3981 TypeParameterTypeImpl typeF = new TypeParameterTypeImpl(elementE);
3982 expect(typeF.resolveToBound(null), same(classS.type));
3983 }
3984
3939 void test_substitute_equal() { 3985 void test_substitute_equal() {
3940 TypeParameterElementImpl element = 3986 TypeParameterElementImpl element =
3941 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")); 3987 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"));
3942 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 3988 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
3943 InterfaceTypeImpl argument = new InterfaceTypeImpl( 3989 InterfaceTypeImpl argument = new InterfaceTypeImpl(
3944 new ClassElementImpl.forNode(AstFactory.identifier3("A"))); 3990 new ClassElementImpl.forNode(AstFactory.identifier3("A")));
3945 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(element); 3991 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(element);
3946 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]), 3992 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]),
3947 same(argument)); 3993 same(argument));
3948 } 3994 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3988 expect(_voidType.isSubtypeOf(DynamicTypeImpl.instance), isTrue); 4034 expect(_voidType.isSubtypeOf(DynamicTypeImpl.instance), isTrue);
3989 } 4035 }
3990 4036
3991 void test_isSubtypeOf_void_void() { 4037 void test_isSubtypeOf_void_void() {
3992 expect(_voidType.isSubtypeOf(_voidType), isTrue); 4038 expect(_voidType.isSubtypeOf(_voidType), isTrue);
3993 } 4039 }
3994 4040
3995 void test_isVoid() { 4041 void test_isVoid() {
3996 expect(_voidType.isVoid, isTrue); 4042 expect(_voidType.isVoid, isTrue);
3997 } 4043 }
4044
4045 void test_resolveToBound() {
4046 // Returns this.
4047 expect(_voidType.resolveToBound(null), same(_voidType));
4048 }
3998 } 4049 }
3999 4050
4000 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction 4051 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
4001 extends InterfaceTypeImpl { 4052 extends InterfaceTypeImpl {
4002 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) 4053 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0)
4003 : super(arg0); 4054 : super(arg0);
4004 4055
4005 @override 4056 @override
4006 bool get isDartCoreFunction => true; 4057 bool get isDartCoreFunction => true;
4007 } 4058 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698