Exemplo n.º 1
0
        public void UnifyStructuralEquivalence_Pass()
        {
            var rt1 = RuntimeCompiler.CreateRecordType(
                new Dictionary <string, Type>
            {
                { "Foo", typeof(int) },
                { "Bar", typeof(string) }
            },
                true);

            var rt2 = RuntimeCompiler.CreateRecordType(
                new Dictionary <string, Type>
            {
                { "Foo", typeof(int) },
                { "Bar", typeof(string) }
            },
                true);

            var typeToSlim = new TypeToTypeSlimConverter();
            var slim       = typeToSlim.Visit(rt1);
            var unifier    = new TypeUnifier();

            Assert.IsTrue(unifier.Unify(rt1, slim));
            Assert.IsTrue(unifier.Unify(rt2, slim));
            Assert.AreEqual(1, unifier.Entries.Count);
            Assert.AreSame(rt1, unifier.Entries[slim]);
        }
Exemplo n.º 2
0
        public void Unify_NullArguments()
        {
            var unifier = new TypeUnifier();

            AssertEx.ThrowsException <ArgumentNullException>(() => unifier.Unify(typeRich: null, typeSlim: null), ex => Assert.AreEqual("typeRich", ex.ParamName));
            AssertEx.ThrowsException <ArgumentNullException>(() => unifier.Unify(typeof(int), typeSlim: null), ex => Assert.AreEqual("typeSlim", ex.ParamName));
        }
Exemplo n.º 3
0
        public void Unify_AlreadyMapped()
        {
            var unifier    = new TypeUnifier();
            var typeToSlim = new TypeToTypeSlimConverter();
            var intSlim    = typeToSlim.Visit(typeof(int));

            unifier.Unify(typeof(int), intSlim);
            unifier.Unify(typeof(double), intSlim);
        }
Exemplo n.º 4
0
        public void TryUnify_AlreadyMapped_Pass()
        {
            var unifier    = new TypeUnifier();
            var typeToSlim = new TypeToTypeSlimConverter();
            var intSlim    = typeToSlim.Visit(typeof(int));

            unifier.Unify(typeof(int), intSlim);
            Assert.IsTrue(unifier.Unify(typeof(int), intSlim));
        }
Exemplo n.º 5
0
        public void TryUnify_AlreadyMapped()
        {
            var unifier    = new TypeUnifier(safe: true);
            var typeToSlim = new TypeToTypeSlimConverter();
            var intSlim    = typeToSlim.Visit(typeof(int));

            unifier.Unify(typeof(int), intSlim);
            Assert.IsFalse(unifier.Unify(typeof(double), intSlim));
        }
Exemplo n.º 6
0
        public void UnifyStructural_MissingProperty_Fail()
        {
            var unifier    = new TypeUnifier();
            var typeToSlim = new TypeToTypeSlimConverter();

            var rtc          = new RuntimeCompiler();
            var typeBuilder1 = rtc.GetNewRecordTypeBuilder();
            var typeBuilder2 = rtc.GetNewRecordTypeBuilder();

            rtc.DefineRecordType(
                typeBuilder1,
                (new Dictionary <string, Type> {
                { "foo", typeof(int) }
            }).AsEnumerable(),
                true
                );

            rtc.DefineRecordType(
                typeBuilder2,
                (new Dictionary <string, Type> {
                { "bar", typeof(double) }
            }).AsEnumerable(),
                true
                );

            var structuralType1    = typeBuilder1.CreateType();
            var structuralType2    = typeBuilder2.CreateType();
            var slimStructuralType = typeToSlim.Visit(structuralType2);

            unifier.Unify(structuralType1, slimStructuralType);
        }
Exemplo n.º 7
0
        public void UnifyStructural_DifferentPropertyTypes_Pass()
        {
            var unifier    = new TypeUnifier();
            var typeToSlim = new TypeToTypeSlimConverter();

            var rtc         = new RuntimeCompiler();
            var typeBuilder = rtc.GetNewRecordTypeBuilder();

            rtc.DefineRecordType(
                typeBuilder,
                (new Dictionary <string, Type> {
                { "foo", typeof(int) }
            }).AsEnumerable(),
                true
                );

            var structuralType     = typeBuilder.CreateType();
            var slimStructuralType = typeToSlim.Visit(structuralType);

            Assert.IsTrue(unifier.Unify(structuralType, slimStructuralType));

            Assert.AreEqual(1, unifier.Entries.Count);

            Assert.IsTrue(unifier.Entries.ContainsKey(slimStructuralType));
            Assert.AreEqual(unifier.Entries[slimStructuralType], structuralType);

            Assert.IsTrue(slimStructuralType is StructuralTypeSlim);
        }
Exemplo n.º 8
0
        public void Unify_UnknownType()
        {
            var unifier = new TypeUnifier();
            var ts      = new FakeType();

            Assert.ThrowsException <NotSupportedException>(() => unifier.Unify(typeof(int), ts));
        }
Exemplo n.º 9
0
        public void UnifyArray_WithNonArrayClrType_Fail()
        {
            var unifier      = new TypeUnifier();
            var typeToSlim   = new TypeToTypeSlimConverter();
            var intArraySlim = typeToSlim.Visit(typeof(int[]));

            unifier.Unify(typeof(int), intArraySlim);
        }
Exemplo n.º 10
0
        public void UnifyArray_DifferentRankMultidimensionalSlim_Fail()
        {
            var unifier      = new TypeUnifier();
            var typeToSlim   = new TypeToTypeSlimConverter();
            var intArraySlim = typeToSlim.Visit(typeof(int[, ]));

            unifier.Unify(typeof(int[]), intArraySlim);
        }
Exemplo n.º 11
0
        public void TryUnifyArray_DifferentElementType_Fail()
        {
            var unifier         = new TypeUnifier(safe: true);
            var typeToSlim      = new TypeToTypeSlimConverter();
            var doubleArraySlim = typeToSlim.Visit(typeof(double[]));

            Assert.IsFalse(unifier.Unify(typeof(int[]), doubleArraySlim));
        }
Exemplo n.º 12
0
        public void UnifyArray_DifferentElementType_Fail()
        {
            var unifier         = new TypeUnifier();
            var typeToSlim      = new TypeToTypeSlimConverter();
            var doubleArraySlim = typeToSlim.Visit(typeof(double[]));

            unifier.Unify(typeof(int[]), doubleArraySlim);
        }
Exemplo n.º 13
0
        public void UnifySimple_DifferentTypeName_Fail()
        {
            var unifier    = new TypeUnifier();
            var typeToSlim = new TypeToTypeSlimConverter();
            var doubleSlim = typeToSlim.Visit(typeof(double));

            unifier.Unify(typeof(int), doubleSlim);
        }
Exemplo n.º 14
0
        public void UnifyGenericParameter_Fail()
        {
            var unifier = new TypeUnifier();
            var openGenericParameterType = typeof(List <>).GetGenericArguments()[0];
            var genericParameterTypeSlim = TypeSlim.GenericParameter("T");

            unifier.Unify(openGenericParameterType, genericParameterTypeSlim);
        }
Exemplo n.º 15
0
        public void Unify_Wildcard_Fail()
        {
            var unifier    = new TypeUnifier(safe: true);
            var typeToSlim = new TypeToTypeSlimConverter();
            var slim       = typeToSlim.Visit(typeof(Func <int, bool>));

            Assert.IsFalse(unifier.Unify(typeof(Func <T, T>), slim));
            Assert.AreEqual(0, unifier.Entries.Count);
        }
Exemplo n.º 16
0
        public void UnifyArray_Vector_Pass()
        {
            var unifier      = new TypeUnifier();
            var typeToSlim   = new TypeToTypeSlimConverter();
            var intArraySlim = typeToSlim.Visit(typeof(int[]));

            Assert.IsTrue(unifier.Unify(typeof(int[]), intArraySlim));
            Assert.AreEqual(0, unifier.Entries.Count);
        }
Exemplo n.º 17
0
        public void UnifyGenericDefinition_WithNonGenericDefClrType_Fail()
        {
            var unifier        = new TypeUnifier();
            var typeToSlim     = new TypeToTypeSlimConverter();
            var definition     = typeof(List <>);
            var slimDefinition = typeToSlim.Visit(definition);

            unifier.Unify(typeof(int), slimDefinition);
        }
Exemplo n.º 18
0
        public void UnifyGeneric_DifferentArguments_Fail()
        {
            var unifier     = new TypeUnifier();
            var typeToSlim  = new TypeToTypeSlimConverter();
            var generic     = typeof(List <int>);
            var slimGeneric = typeToSlim.Visit(generic);

            unifier.Unify(typeof(List <double>), slimGeneric);
        }
Exemplo n.º 19
0
        public void TryUnifyGeneric_DifferentDefinition_Fail()
        {
            var unifier     = new TypeUnifier(safe: true);
            var typeToSlim  = new TypeToTypeSlimConverter();
            var generic     = typeof(List <int>);
            var slimGeneric = typeToSlim.Visit(generic);

            Assert.IsFalse(unifier.Unify(typeof(Nullable <int>), slimGeneric));
        }
Exemplo n.º 20
0
        public void UnifyGeneric_DifferentDefinition_Fail()
        {
            var unifier     = new TypeUnifier();
            var typeToSlim  = new TypeToTypeSlimConverter();
            var generic     = typeof(List <int>);
            var slimGeneric = typeToSlim.Visit(generic);

            unifier.Unify(typeof(Nullable <int>), slimGeneric);
        }
Exemplo n.º 21
0
        public void UnifyGeneric_WithGenericDefClrType_Fail()
        {
            var unifier     = new TypeUnifier();
            var typeToSlim  = new TypeToTypeSlimConverter();
            var generic     = typeof(List <int>);
            var slimGeneric = typeToSlim.Visit(generic);

            unifier.Unify(typeof(List <>), slimGeneric);
        }
Exemplo n.º 22
0
        public void UnifyGeneric_Pass()
        {
            var unifier     = new TypeUnifier();
            var typeToSlim  = new TypeToTypeSlimConverter();
            var generic     = typeof(List <int>);
            var slimGeneric = typeToSlim.Visit(generic);

            Assert.IsTrue(unifier.Unify(generic, slimGeneric));
            Assert.AreEqual(0, unifier.Entries.Count);
        }
Exemplo n.º 23
0
        public void UnifyGenericDefinition_Pass()
        {
            var unifier        = new TypeUnifier();
            var typeToSlim     = new TypeToTypeSlimConverter();
            var definition     = typeof(List <>);
            var slimDefinition = typeToSlim.Visit(definition);

            Assert.IsTrue(unifier.Unify(definition, slimDefinition));
            Assert.AreEqual(0, unifier.Entries.Count);
        }
Exemplo n.º 24
0
        public void UnifyManOrBoy_Pass()
        {
            var record1 = RuntimeCompiler.CreateRecordType(
                new Dictionary <string, Type> {
                { "foo", typeof(int) }
            },
                true);
            var record2 = RuntimeCompiler.CreateRecordType(
                new Dictionary <string, Type> {
                { "bar", record1 },
                { "qux", typeof(string) }
            },
                true);
            var list       = typeof(List <>).MakeGenericType(new[] { record2 });
            var unifier    = new TypeUnifier();
            var typeToSlim = new TypeToTypeSlimConverter();
            var slimList   = typeToSlim.Visit(list);

            Assert.IsTrue(unifier.Unify(list, slimList));
            Assert.AreEqual(2, unifier.Entries.Count);
        }
Exemplo n.º 25
0
        public void UnifySimple_DifferentAssemblyName_Fail()
        {
            var unifier = new TypeUnifier();

            unifier.Unify(typeof(int), TypeSlim.Simple(new AssemblySlim("Foo"), "System.Int32"));
        }