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

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

Issue 1061043002: Remove union type support from analyzer. (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
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 11 matching lines...) Expand all
22 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper; 22 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper;
23 import 'test_support.dart'; 23 import 'test_support.dart';
24 24
25 main() { 25 main() {
26 groupSep = ' | '; 26 groupSep = ' | ';
27 runReflectiveTests(ElementKindTest); 27 runReflectiveTests(ElementKindTest);
28 runReflectiveTests(FieldElementImplTest); 28 runReflectiveTests(FieldElementImplTest);
29 runReflectiveTests(FunctionTypeImplTest); 29 runReflectiveTests(FunctionTypeImplTest);
30 runReflectiveTests(InterfaceTypeImplTest); 30 runReflectiveTests(InterfaceTypeImplTest);
31 runReflectiveTests(TypeParameterTypeImplTest); 31 runReflectiveTests(TypeParameterTypeImplTest);
32 runReflectiveTests(UnionTypeImplTest);
33 runReflectiveTests(VoidTypeImplTest); 32 runReflectiveTests(VoidTypeImplTest);
34 runReflectiveTests(ClassElementImplTest); 33 runReflectiveTests(ClassElementImplTest);
35 runReflectiveTests(CompilationUnitElementImplTest); 34 runReflectiveTests(CompilationUnitElementImplTest);
36 runReflectiveTests(ElementLocationImplTest); 35 runReflectiveTests(ElementLocationImplTest);
37 runReflectiveTests(ElementImplTest); 36 runReflectiveTests(ElementImplTest);
38 runReflectiveTests(HtmlElementImplTest); 37 runReflectiveTests(HtmlElementImplTest);
39 runReflectiveTests(LibraryElementImplTest); 38 runReflectiveTests(LibraryElementImplTest);
40 runReflectiveTests(MultiplyDefinedElementImplTest); 39 runReflectiveTests(MultiplyDefinedElementImplTest);
41 } 40 }
42 41
(...skipping 3700 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1( 3742 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1(
3744 new ClassElementImpl.forNode(AstFactory.identifier3("A"))); 3743 new ClassElementImpl.forNode(AstFactory.identifier3("A")));
3745 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl( 3744 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(
3746 new TypeParameterElementImpl.forNode(AstFactory.identifier3("F"))); 3745 new TypeParameterElementImpl.forNode(AstFactory.identifier3("F")));
3747 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]), 3746 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]),
3748 same(type)); 3747 same(type));
3749 } 3748 }
3750 } 3749 }
3751 3750
3752 @reflectiveTest 3751 @reflectiveTest
3753 class UnionTypeImplTest extends EngineTestCase {
3754 ClassElement _classA;
3755
3756 InterfaceType _typeA;
3757
3758 ClassElement _classB;
3759
3760 InterfaceType _typeB;
3761
3762 DartType _uA;
3763
3764 DartType _uB;
3765
3766 DartType _uAB;
3767
3768 DartType _uBA;
3769
3770 List<DartType> _us;
3771
3772 @override
3773 void setUp() {
3774 super.setUp();
3775 _classA = ElementFactory.classElement2("A");
3776 _typeA = _classA.type;
3777 _classB = ElementFactory.classElement("B", _typeA);
3778 _typeB = _classB.type;
3779 _uA = UnionTypeImpl.union([_typeA]);
3780 _uB = UnionTypeImpl.union([_typeB]);
3781 _uAB = UnionTypeImpl.union([_typeA, _typeB]);
3782 _uBA = UnionTypeImpl.union([_typeB, _typeA]);
3783 _us = <DartType>[_uA, _uB, _uAB, _uBA];
3784 }
3785
3786 void test_emptyUnionsNotAllowed() {
3787 try {
3788 UnionTypeImpl.union([]);
3789 } on IllegalArgumentException {
3790 return;
3791 }
3792 fail("Expected illegal argument exception.");
3793 }
3794
3795 void test_equality_beingASubtypeOfAnElementIsNotSufficient() {
3796 // Non-equal if some elements are different
3797 expect(_uAB == _uA, isFalse);
3798 }
3799
3800 void test_equality_insertionOrderDoesntMatter() {
3801 // Insertion order doesn't matter, only sets of elements
3802 expect(_uAB == _uBA, isTrue);
3803 expect(_uBA == _uAB, isTrue);
3804 }
3805
3806 void test_equality_reflexivity() {
3807 for (DartType u in _us) {
3808 expect(u == u, isTrue);
3809 }
3810 }
3811
3812 void test_equality_singletonsCollapse() {
3813 expect(_typeA == _uA, isTrue);
3814 expect(_uA == _typeA, isTrue);
3815 }
3816
3817 void test_isMoreSpecificThan_allElementsOnLHSAreSubtypesOfSomeElementOnRHS() {
3818 // Unions are subtypes when all elements are subtypes
3819 expect(_uAB.isMoreSpecificThan(_uA), isTrue);
3820 expect(_uAB.isMoreSpecificThan(_typeA), isTrue);
3821 }
3822
3823 void test_isMoreSpecificThan_element() {
3824 // Elements of union are sub types
3825 expect(_typeA.isMoreSpecificThan(_uAB), isTrue);
3826 expect(_typeB.isMoreSpecificThan(_uAB), isTrue);
3827 }
3828
3829 void test_isMoreSpecificThan_notSubtypeOfAnyElement() {
3830 // Types that are not subtypes of elements are not subtypes
3831 expect(_typeA.isMoreSpecificThan(_uB), isFalse);
3832 }
3833
3834 void test_isMoreSpecificThan_reflexivity() {
3835 for (DartType u in _us) {
3836 expect(u.isMoreSpecificThan(u), isTrue);
3837 }
3838 }
3839
3840 void test_isMoreSpecificThan_someElementOnLHSIsNotASubtypeOfAnyElementOnRHS() {
3841 // Unions are subtypes when some element is a subtype
3842 expect(_uAB.isMoreSpecificThan(_uB), isTrue);
3843 expect(_uAB.isMoreSpecificThan(_typeB), isTrue);
3844 }
3845
3846 void test_isMoreSpecificThan_subtypeOfSomeElement() {
3847 // Subtypes of elements are sub types
3848 expect(_typeB.isMoreSpecificThan(_uA), isTrue);
3849 }
3850
3851 void test_isSubtypeOf_allElementsOnLHSAreSubtypesOfSomeElementOnRHS() {
3852 // Unions are subtypes when all elements are subtypes
3853 expect(_uAB.isSubtypeOf(_uA), isTrue);
3854 expect(_uAB.isSubtypeOf(_typeA), isTrue);
3855 }
3856
3857 void test_isSubtypeOf_element() {
3858 // Elements of union are sub types
3859 expect(_typeA.isSubtypeOf(_uAB), isTrue);
3860 expect(_typeB.isSubtypeOf(_uAB), isTrue);
3861 }
3862
3863 void test_isSubtypeOf_notSubtypeOfAnyElement() {
3864 // Types that are not subtypes of elements are not subtypes
3865 expect(_typeA.isSubtypeOf(_uB), isFalse);
3866 }
3867
3868 void test_isSubtypeOf_reflexivity() {
3869 for (DartType u in _us) {
3870 expect(u.isSubtypeOf(u), isTrue);
3871 }
3872 }
3873
3874 void test_isSubtypeOf_someElementOnLHSIsNotASubtypeOfAnyElementOnRHS() {
3875 // Unions are subtypes when some element is a subtype
3876 expect(_uAB.isSubtypeOf(_uB), isTrue);
3877 expect(_uAB.isSubtypeOf(_typeB), isTrue);
3878 }
3879
3880 void test_isSubtypeOf_subtypeOfSomeElement() {
3881 // Subtypes of elements are sub types
3882 expect(_typeB.isSubtypeOf(_uA), isTrue);
3883 }
3884
3885 void test_nestedUnionsCollapse() {
3886 UnionType u = UnionTypeImpl.union([_uAB, _typeA]) as UnionType;
3887 for (DartType t in u.elements) {
3888 if (t is UnionType) {
3889 fail("Expected only non-union types but found $t!");
3890 }
3891 }
3892 }
3893
3894 void test_noLossage() {
3895 UnionType u = UnionTypeImpl
3896 .union([_typeA, _typeB, _typeB, _typeA, _typeB, _typeB]) as UnionType;
3897 Set<DartType> elements = u.elements;
3898 expect(elements.contains(_typeA), isTrue);
3899 expect(elements.contains(_typeB), isTrue);
3900 expect(elements.length == 2, isTrue);
3901 }
3902
3903 void test_substitute() {
3904 // Based on [InterfaceTypeImplTest.test_substitute_equal].
3905 ClassElement classAE = ElementFactory.classElement2("A", ["E"]);
3906 InterfaceType typeAE = classAE.type;
3907 List<DartType> args = [_typeB];
3908 List<DartType> params = [classAE.typeParameters[0].type];
3909 DartType typeAESubbed = typeAE.substitute2(args, params);
3910 expect(typeAE == typeAESubbed, isFalse);
3911 expect(UnionTypeImpl.union([_typeA, typeAESubbed]),
3912 UnionTypeImpl.union([_typeA, typeAE]).substitute2(args, params));
3913 }
3914
3915 void test_toString_pair() {
3916 String s = _uAB.toString();
3917 expect(s == "{A,B}" || s == "{B,A}", isTrue);
3918 expect(_uAB.displayName, s);
3919 }
3920
3921 void test_toString_singleton() {
3922 // Singleton unions collapse to the the single type.
3923 expect(_uA.toString(), "A");
3924 }
3925
3926 void test_unionTypeIsLessSpecificThan_function() {
3927 // Based on
3928 // [FunctionTypeImplTest.test_isAssignableTo_normalAndPositionalArgs].
3929 ClassElement a = ElementFactory.classElement2("A");
3930 FunctionType t =
3931 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type;
3932 DartType uAT = UnionTypeImpl.union([_uA, t]);
3933 expect(t.isMoreSpecificThan(uAT), isTrue);
3934 expect(t.isMoreSpecificThan(_uAB), isFalse);
3935 }
3936
3937 void test_unionTypeIsSuperTypeOf_function() {
3938 // Based on
3939 // [FunctionTypeImplTest.test_isAssignableTo_normalAndPositionalArgs].
3940 ClassElement a = ElementFactory.classElement2("A");
3941 FunctionType t =
3942 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type;
3943 DartType uAT = UnionTypeImpl.union([_uA, t]);
3944 expect(t.isSubtypeOf(uAT), isTrue);
3945 expect(t.isSubtypeOf(_uAB), isFalse);
3946 }
3947 }
3948
3949 @reflectiveTest
3950 class VoidTypeImplTest extends EngineTestCase { 3752 class VoidTypeImplTest extends EngineTestCase {
3951 /** 3753 /**
3952 * Reference {code VoidTypeImpl.getInstance()}. 3754 * Reference {code VoidTypeImpl.getInstance()}.
3953 */ 3755 */
3954 DartType _voidType = VoidTypeImpl.instance; 3756 DartType _voidType = VoidTypeImpl.instance;
3955 3757
3956 void test_isMoreSpecificThan_void_A() { 3758 void test_isMoreSpecificThan_void_A() {
3957 ClassElement classA = ElementFactory.classElement2("A"); 3759 ClassElement classA = ElementFactory.classElement2("A");
3958 expect(_voidType.isMoreSpecificThan(classA.type), isFalse); 3760 expect(_voidType.isMoreSpecificThan(classA.type), isFalse);
3959 } 3761 }
(...skipping 25 matching lines...) Expand all
3985 } 3787 }
3986 3788
3987 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction 3789 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
3988 extends InterfaceTypeImpl { 3790 extends InterfaceTypeImpl {
3989 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) 3791 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0)
3990 : super.con1(arg0); 3792 : super.con1(arg0);
3991 3793
3992 @override 3794 @override
3993 bool get isDartCoreFunction => true; 3795 bool get isDartCoreFunction => true;
3994 } 3796 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698