コード例 #1
0
 public void IsArrayName(string baseTypeId, string expected1DId, string expected2DId)
 {
     Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(baseTypeId));
     foreach (var arrId in new[] { expected1DId, expected2DId })
     {
         if (TypeParameterName.IsTypeParameterNameIdentifier(baseTypeId))
         {
             Assert.IsTrue(TypeParameterName.IsTypeParameterNameIdentifier(arrId));
             Assert.IsFalse(TypeName.IsTypeNameIdentifier(arrId));
             Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(arrId));
             Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(arrId));
             Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(arrId));
             Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(arrId));
         }
         else if (PredefinedTypeName.IsPredefinedTypeNameIdentifier(baseTypeId))
         {
             Assert.IsTrue(PredefinedTypeName.IsPredefinedTypeNameIdentifier(arrId));
             Assert.IsFalse(TypeName.IsTypeNameIdentifier(arrId));
             Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(arrId));
             Assert.IsFalse(TypeParameterName.IsTypeParameterNameIdentifier(arrId));
             Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(arrId));
             Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(arrId));
         }
         else
         {
             Assert.IsTrue(ArrayTypeName.IsArrayTypeNameIdentifier(arrId));
             Assert.IsFalse(TypeName.IsTypeNameIdentifier(arrId));
             Assert.IsFalse(TypeParameterName.IsTypeParameterNameIdentifier(arrId));
             Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(arrId));
             Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(arrId));
             Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(arrId));
         }
     }
 }
コード例 #2
0
        public void ShouldRejectUnknownIds()
        {
            const string invalidId = "p:...";

            Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(invalidId));
            new PredefinedTypeName(invalidId);
        }
コード例 #3
0
 public void ShouldIdentifyValidTypeParameterNames(string typeParameter, string shortName, string boundType)
 {
     Assert.IsTrue(TypeParameterName.IsTypeParameterNameIdentifier(typeParameter));
     Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(typeParameter));
     Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(typeParameter));
     Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(typeParameter));
     Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(typeParameter));
     Assert.IsFalse(TypeName.IsTypeNameIdentifier(typeParameter));
 }
コード例 #4
0
 public void ShouldNotCrashForInvalidNames(string invalidId)
 {
     Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(invalidId));
     Assert.IsFalse(TypeParameterName.IsTypeParameterNameIdentifier(invalidId));
     Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(invalidId));
     Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(invalidId));
     Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(invalidId));
     Assert.IsFalse(TypeName.IsTypeNameIdentifier(invalidId));
 }
コード例 #5
0
 public void ShouldRecognizeDelegateNames(string delegateId, string delegateTypeId)
 {
     Assert.IsTrue(DelegateTypeName.IsDelegateTypeNameIdentifier(delegateId));
     Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(delegateId));
     Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(delegateId));
     Assert.IsFalse(TypeParameterName.IsTypeParameterNameIdentifier(delegateId));
     Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(delegateId));
     Assert.IsFalse(TypeName.IsTypeNameIdentifier(delegateId));
 }
コード例 #6
0
 public void ShouldRecognizeIdentifier(string shortName, string fullName, string id)
 {
     Assert.IsTrue(PredefinedTypeName.IsPredefinedTypeNameIdentifier(id));
     Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(id));
     Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(id));
     Assert.IsFalse(TypeParameterName.IsTypeParameterNameIdentifier(id));
     Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(id));
     Assert.IsFalse(TypeName.IsTypeNameIdentifier(id));
 }
コード例 #7
0
 public void ShouldRecognizeUnknownType()
 {
     foreach (var id in new[] { null, "", "?" })
     {
         Assert.IsTrue(TypeUtils.IsUnknownTypeIdentifier(id));
         Assert.IsFalse(TypeName.IsTypeNameIdentifier(id));
         Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(id));
         Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(id));
         Assert.IsFalse(TypeParameterName.IsTypeParameterNameIdentifier(id));
         Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(id));
     }
 }
コード例 #8
0
 public void ShouldRecognizeRegularTypes(string typeId,
                                         string assemblyId,
                                         string namespaceId,
                                         string fullName,
                                         string name)
 {
     Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(typeId));
     Assert.IsFalse(ArrayTypeName.IsArrayTypeNameIdentifier(typeId));
     Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(typeId));
     Assert.IsFalse(TypeParameterName.IsTypeParameterNameIdentifier(typeId));
     Assert.IsFalse(PredefinedTypeName.IsPredefinedTypeNameIdentifier(typeId));
     Assert.IsTrue(TypeName.IsTypeNameIdentifier(typeId));
 }
コード例 #9
0
        public void ArraysAreNothingElse(string baseTypeId, string expected1DId, string expected2DId)
        {
            foreach (var id in new[] { expected1DId, expected2DId })
            {
                var sut = TypeUtils.CreateTypeName(id);

                Assert.IsFalse(sut.IsClassType);
                Assert.IsFalse(sut.IsDelegateType);
                Assert.IsFalse(sut.IsEnumType);
                Assert.IsFalse(sut.IsInterfaceType);
                Assert.IsFalse(sut.IsNestedType);
                Assert.IsFalse(sut.IsNullableType);
                Assert.IsTrue(sut.IsReferenceType);
                Assert.IsTrue(sut.IsArray);
                Assert.IsFalse(sut.IsSimpleType);
                Assert.IsFalse(sut.IsStructType);
                Assert.IsFalse(sut.IsValueType);
                Assert.IsFalse(sut.IsVoidType);

                Assert.IsFalse(sut.IsTypeParameter);
                Assert.IsFalse(sut.IsDelegateType);
                Assert.IsFalse(sut.IsPredefined);

                Assert.IsFalse(TypeName.IsTypeNameIdentifier(id));
                Assert.IsFalse(TypeUtils.IsUnknownTypeIdentifier(id));
                Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(id));
                if (TypeParameterName.IsTypeParameterNameIdentifier(baseTypeId))
                {
                    Assert.IsTrue(TypeParameterName.IsTypeParameterNameIdentifier(id));
                }
                if (PredefinedTypeName.IsPredefinedTypeNameIdentifier(baseTypeId))
                {
                    Assert.IsTrue(PredefinedTypeName.IsPredefinedTypeNameIdentifier(id));
                }
                if (DelegateTypeName.IsDelegateTypeNameIdentifier(baseTypeId))
                {
                    Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(id));
                }
            }
        }
コード例 #10
0
        private void AppendAssertsForTypeName(ITypeName t)
        {
            _sb.AppendLine("String id = \"{0}\";".FormatEx(t.Identifier));

            _sb.Append("assertEquals(")
            .AppendBool(TypeUtils.IsUnknownTypeIdentifier(t.Identifier))
            .AppendLine(", TypeUtils.isUnknownTypeIdentifier(id));");
            _sb.Append("assertEquals(")
            .AppendBool(TypeName.IsTypeNameIdentifier(t.Identifier))
            .AppendLine(", TypeName.isTypeNameIdentifier(id));");
            _sb.Append("assertEquals(")
            .AppendBool(ArrayTypeName.IsArrayTypeNameIdentifier(t.Identifier))
            .AppendLine(", ArrayTypeName.isArrayTypeNameIdentifier(id));");
            _sb.Append("assertEquals(")
            .AppendBool(TypeParameterName.IsTypeParameterNameIdentifier(t.Identifier))
            .AppendLine(", TypeParameterName.isTypeParameterNameIdentifier(id));");
            _sb.Append("assertEquals(")
            .AppendBool(DelegateTypeName.IsDelegateTypeNameIdentifier(t.Identifier))
            .AppendLine(", DelegateTypeName.isDelegateTypeNameIdentifier(id));");
            _sb.Append("assertEquals(")
            .AppendBool(PredefinedTypeName.IsPredefinedTypeNameIdentifier(t.Identifier))
            .AppendLine(", PredefinedTypeName.isPredefinedTypeNameIdentifier(id));");


            _sb.AppendLine("ITypeName sut = TypeUtils.createTypeName(id);");
            _sb.AppendLine("assertTrue(sut instanceof {0});".FormatEx(t.GetType().Name));

            _sb.AppendAreEqual(t.IsHashed, "sut.isHashed()");
            _sb.AppendAreEqual(t.IsUnknown, "sut.isUnknown()");

            _sb.AppendAreEqual(t.Namespace, "sut.getNamespace()");
            _sb.AppendAreEqual(t.Assembly, "sut.getAssembly()");
            _sb.AppendAreEqual(t.FullName, "sut.getFullName()");
            _sb.AppendAreEqual(t.Name, "sut.getName()");

            _sb.AppendAreEqual(t.IsClassType, "sut.isClassType()");
            _sb.AppendAreEqual(t.IsEnumType, "sut.isEnumType()");
            _sb.AppendAreEqual(t.IsInterfaceType, "sut.isInterfaceType()");
            _sb.AppendAreEqual(t.IsNullableType, "sut.isNullableType()");
            _sb.AppendAreEqual(t.IsPredefined, "sut.isPredefined()");
            _sb.AppendAreEqual(t.IsReferenceType, "sut.isReferenceType()");
            _sb.AppendAreEqual(t.IsSimpleType, "sut.isSimpleType()");
            _sb.AppendAreEqual(t.IsStructType, "sut.isStructType()");
            _sb.AppendAreEqual(t.IsTypeParameter, "sut.isTypeParameter()");
            _sb.AppendAreEqual(t.IsValueType, "sut.isValueType()");
            _sb.AppendAreEqual(t.IsVoidType, "sut.isVoidType()");

            _sb.AppendAreEqual(t.IsNestedType, "sut.isNestedType()");
            _sb.AppendAreEqual(t.DeclaringType, "sut.getDeclaringType()");

            _sb.AppendAreEqual(t.HasTypeParameters, "sut.hasTypeParameters()");
            _sb.AppendAreEqual(t.TypeParameters, "sut.getTypeParameters()");

            // used for several checks;
            _sb.AppendLine("boolean hasThrown;");

            // array
            _sb.Comment("array");
            _sb.AppendAreEqual(t.IsArray, "sut.isArray()");
            if (t.IsArray)
            {
                var tArr = t.AsArrayTypeName;
                _sb.AppendLine("IArrayTypeName sutArr = sut.asArrayTypeName();");
                _sb.AppendAreEqual(tArr.Rank, "sutArr.getRank()");
                _sb.AppendAreEqual(tArr.ArrayBaseType, "sutArr.getArrayBaseType()");
            }
            else
            {
                _sb.AppendThrowValidation("sut.asArrayTypeName();", "AssertionException");
            }

            // delegates
            _sb.Comment("delegates");
            _sb.AppendAreEqual(t.IsDelegateType, "sut.isDelegateType()");
            if (t.IsDelegateType)
            {
                var tD = t.AsDelegateTypeName;
                _sb.AppendLine("IDelegateTypeName sutD = sut.asDelegateTypeName();");
                _sb.AppendAreEqual(tD.DelegateType, "sutD.getDelegateType()");
                _sb.AppendAreEqual(tD.HasParameters, "sutD.hasParameters()");
                _sb.AppendAreEqual(tD.IsRecursive, "sutD.isRecursive()");
                _sb.AppendAreEqual(tD.Parameters, "sutD.getParameters()");
                _sb.AppendAreEqual(tD.ReturnType, "sutD.getReturnType()");
            }
            else
            {
                _sb.AppendThrowValidation("sut.asDelegateTypeName();", "AssertionException");
            }

            // predefined
            _sb.Comment("predefined");
            _sb.AppendAreEqual(t.IsPredefined, "sut.isPredefined()");
            if (t.IsPredefined)
            {
                var sutP = t.AsPredefinedTypeName;
                _sb.AppendLine("IPredefinedTypeName sutP = sut.asPredefinedTypeName();");
                _sb.AppendAreEqual(sutP.FullType, "sutP.getFullType()");
            }
            else
            {
                _sb.AppendThrowValidation("sut.asPredefinedTypeName();", "AssertionException");
            }

            // type parameters
            _sb.Comment("type parameters");
            _sb.AppendAreEqual(t.IsTypeParameter, "sut.isTypeParameter()");
            if (t.IsTypeParameter)
            {
                var sutT = t.AsTypeParameterName;
                _sb.AppendLine("ITypeParameterName sutT = sut.asTypeParameterName();");
                _sb.AppendAreEqual(sutT.IsBound, "sutT.isBound()");
                _sb.AppendAreEqual(sutT.TypeParameterShortName, "sutT.getTypeParameterShortName()");
                _sb.AppendAreEqual(sutT.TypeParameterType, "sutT.getTypeParameterType()");
            }
            else
            {
                _sb.AppendThrowValidation("sut.asTypeParameterName();", "AssertionException");
            }
        }