public void ShouldParseAssembly(string delegateId, string delegateTypeId)
        {
            var actual   = new DelegateTypeName(delegateId).Assembly;
            var expected = TypeUtils.CreateTypeName(delegateTypeId).Assembly;

            Assert.AreEqual(expected, actual);
        }
        public void ShouldParseReturnType(string delegateId, string returnTypeId)
        {
            var actual   = new DelegateTypeName(delegateId).ReturnType;
            var expected = TypeUtils.CreateTypeName(returnTypeId);

            Assert.AreEqual(expected, actual);
        }
        public void TypeClassification(string delegateId, string delegateTypeId)
        {
            var delegateType = new DelegateTypeName(delegateId);

            Assert.IsTrue(delegateType.IsDelegateType);
            Assert.IsTrue(delegateType.IsReferenceType);

            if (!delegateType.Identifier.StartsWith("d:[?]"))
            {
                Assert.IsFalse(delegateType.IsUnknown);
            }
            Assert.IsFalse(delegateType.IsHashed);

            var dt = delegateType.DelegateType;

            Assert.AreEqual(dt.HasTypeParameters, delegateType.HasTypeParameters);

            Assert.IsFalse(delegateType.IsArray);
            Assert.IsFalse(delegateType.IsTypeParameter);
            Assert.IsFalse(delegateType.IsPredefined);

            Assert.IsFalse(delegateType.IsClassType);
            Assert.IsFalse(delegateType.IsEnumType);
            Assert.IsFalse(delegateType.IsInterfaceType);
            Assert.IsFalse(delegateType.IsNullableType);
            Assert.IsFalse(delegateType.IsSimpleType);
            Assert.IsFalse(delegateType.IsStructType);
            Assert.IsFalse(delegateType.IsTypeParameter);
            Assert.IsFalse(delegateType.IsValueType);
            Assert.IsFalse(delegateType.IsVoidType);
        }
        public void ShouldApplyV0NameFixes()
        {
            var actual   = "0T:d:T,P".Deserialize <IDelegateTypeName>();
            var expected = new DelegateTypeName("d:[?] [T,P].()");

            Assert.AreEqual(expected, actual);
        }
예제 #5
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));
         }
     }
 }
        public void TypeParameterParsingIsCached()
        {
            var sut = new DelegateTypeName("d:[?] [n.C+D`1[[T]], P].()");
            var a   = sut.TypeParameters;
            var b   = sut.TypeParameters;

            Assert.AreSame(a, b);
        }
        public void RecursiveDelegates1_param()
        {
            const string id = "d:[?] [n.C+D, P].([n.C+D, P] p)";
            var          ps = new DelegateTypeName(id).Parameters;

            Assert.AreEqual(1, ps.Count);
            Assert.AreEqual(id, ps.First().ValueType.Identifier);
        }
        public void RecursiveDelegates1_return()
        {
            const string id = "d:[n.C+D, P] [n.C+D, P].()";
            var          a  = new DelegateTypeName(id);
            var          b  = a.ReturnType;

            Assert.AreEqual(a, b);
        }
        public void RecursiveDelegates2_return()
        {
            const string id       = "d:[T`1[[T -> n.C+D, P]], P] [n.C+D, P].()";
            const string returnId = "T`1[[T -> d:[T`1[[T -> n.C+D, P]], P] [n.C+D, P].()]], P";
            var          a        = new DelegateTypeName(id).ReturnType;
            var          b        = TypeUtils.CreateTypeName(returnId);

            Assert.AreEqual(a, b);
        }
예제 #10
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));
 }
 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));
 }
예제 #12
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));
 }
예제 #13
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));
 }
        public void RecursiveDelegates2_param()
        {
            const string id      = "d:[?] [n.C+D, P].([T`1[[T -> n.C+D, P]], P] p)";
            var          paramId = "T`1[[T -> {0}]], P".FormatEx(id);

            var ps = new DelegateTypeName(id).Parameters;

            Assert.AreEqual(1, ps.Count);
            Assert.AreEqual(paramId, ps.First().ValueType.Identifier);
        }
 public void ShouldRecognizeNonDelegateNames(string delegateId, string delegateTypeId)
 {
     if (DelegateTypeName.IsDelegateTypeNameIdentifier(delegateTypeId))
     {
         Assert.Ignore();
     }
     else
     {
         Assert.IsFalse(DelegateTypeName.IsDelegateTypeNameIdentifier(delegateTypeId));
     }
 }
 public void ShouldParseParameters(string delegateId, string delegateTypeId)
 {
     if (!delegateId.EndsWith("()"))
     {
         var sut = new DelegateTypeName(delegateId);
         Assert.IsTrue(sut.HasParameters);
     }
     else
     {
         Assert.Ignore();
     }
 }
예제 #17
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));
     }
 }
예제 #18
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));
 }
        public void RecursiveDelegates_unknown()
        {
            const string id  = "d:[?] [?].([?] p)";
            var          sut = new DelegateTypeName(id);

            Assert.IsFalse(sut.IsRecursive);

            var rt = sut.ReturnType;

            Assert.AreEqual("?", rt.Identifier);

            var ps = sut.Parameters;

            Assert.AreEqual(1, ps.Count);
            Assert.AreEqual("[?] p", ps[0].Identifier);
        }
예제 #20
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));
                }
            }
        }
예제 #21
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");
            }
        }