public void TypeToTypeSlimConverter_Resolve_ThrowsInvalidOperation() { var visitor = new TypeToTypeSlimConverter(); var intTypeSlim = visitor.Visit(typeof(int)); var longTypeSlim = visitor.Visit(typeof(long)); Assert.ThrowsException <InvalidOperationException>(() => visitor.MapType(typeof(int), longTypeSlim)); }
public void TypeToTypeSlimConverter_Resolve_Success() { var visitor = new TypeToTypeSlimConverter(); var longTypeSlim = visitor.Visit(typeof(long)); visitor.MapType(typeof(int), longTypeSlim); var intTypeSlim = visitor.Visit(typeof(int)); Assert.AreEqual(intTypeSlim, longTypeSlim); visitor.MapType(typeof(int), longTypeSlim); }
public void TypeToTypeSlimConverter_ThrowsNotSupported() { var refType = typeof(Foo).GetConstructors().Single().GetParameters()[0].ParameterType; Assert.IsTrue(refType.IsByRef); var pointerType = typeof(int *); Assert.IsTrue(pointerType.IsPointer); var converter = new TypeToTypeSlimConverter(); Assert.ThrowsException <NotSupportedException>(() => converter.Visit(refType)); Assert.ThrowsException <NotSupportedException>(() => converter.Visit(pointerType)); }
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); }
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]); }
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); }
public void UnifyArray_WithNonArrayClrType_Fail() { var unifier = new TypeUnifier(); var typeToSlim = new TypeToTypeSlimConverter(); var intArraySlim = typeToSlim.Visit(typeof(int[])); unifier.Unify(typeof(int), intArraySlim); }
public void UnifyArray_DifferentRankMultidimensionalSlim_Fail() { var unifier = new TypeUnifier(); var typeToSlim = new TypeToTypeSlimConverter(); var intArraySlim = typeToSlim.Visit(typeof(int[, ])); unifier.Unify(typeof(int[]), intArraySlim); }
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)); }
public void UnifyArray_DifferentElementType_Fail() { var unifier = new TypeUnifier(); var typeToSlim = new TypeToTypeSlimConverter(); var doubleArraySlim = typeToSlim.Visit(typeof(double[])); unifier.Unify(typeof(int[]), doubleArraySlim); }
public void UnifySimple_DifferentTypeName_Fail() { var unifier = new TypeUnifier(); var typeToSlim = new TypeToTypeSlimConverter(); var doubleSlim = typeToSlim.Visit(typeof(double)); unifier.Unify(typeof(int), doubleSlim); }
public void TypeToTypeSlimConverter_GenericParameter() { var genericParameterType = typeof(List <>).GetGenericArguments()[0]; var visitor = new TypeToTypeSlimConverter(); Assert.ThrowsException <InvalidOperationException>(() => visitor.Visit(genericParameterType)); }
public void TypeToTypeSlimConverter_ArgumentChecks() { var converter = new TypeToTypeSlimConverter(); AssertEx.ThrowsException <ArgumentNullException>(() => converter.Visit(type: null), ex => Assert.AreEqual(ex.ParamName, "type")); AssertEx.ThrowsException <ArgumentNullException>(() => converter.MapType(type: null, typeSlim: null), ex => Assert.AreEqual(ex.ParamName, "type")); AssertEx.ThrowsException <ArgumentNullException>(() => converter.MapType(typeof(int), typeSlim: null), ex => Assert.AreEqual(ex.ParamName, "typeSlim")); }
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)); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
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)); }
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); }
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); }
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); }