Browse Source

Use directly specific corlib implementation for GetAllBaseTypesTest so that the tests don't fail if interfaces are added to .NET BCL types.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
3d74abb409
  1. 71
      ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs

71
ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs

@ -21,6 +21,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.TypeSystem.Implementation;
using NUnit.Framework; using NUnit.Framework;
@ -31,12 +32,43 @@ namespace ICSharpCode.NRefactory.TypeSystem
[TestFixture] [TestFixture]
public class GetAllBaseTypesTest public class GetAllBaseTypesTest
{ {
const string corlib = @"
namespace System {
class Object {}
class ValueType {}
class String : System.Collections.Generic.IEnumerable<char>, IComparable<string> {}
class Array : System.Collections.IList, ICloneable {}
interface ICloneable {}
interface IComparable<in T> {}
struct Int32 {}
struct Char {}
}
namespace System.Collections {
interface IEnumerable {}
interface ICollection : IEnumerable {}
interface IList : ICollection {}
interface IDictionary : ICollection {}
}
namespace System.Collections.Generic {
interface IEnumerable<out T> : IEnumerable {}
interface ICollection<T> : IEnumerable<T> {}
interface IList<T> : ICollection<T> {}
interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>> {}
class List<T> : IList, IList<T> {}
class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary {}
struct KeyValuePair<TKey, TValue> {}
}
";
ICompilation compilation; ICompilation compilation;
[SetUp] [SetUp]
public void SetUp() public void SetUp()
{ {
compilation = new SimpleCompilation(CecilLoaderTests.Mscorlib); var parsedFile = new CSharpParser().Parse(corlib, "corlib.cs").ToTypeSystem();
compilation = new CSharpProjectContent().SetAssemblyName("mscorlib").UpdateProjectContent(null, parsedFile).CreateCompilation();
} }
IType[] GetAllBaseTypes(Type type) IType[] GetAllBaseTypes(Type type)
@ -46,7 +78,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IType[] GetTypes(params Type[] types) IType[] GetTypes(params Type[] types)
{ {
return types.Select(t => compilation.FindType(t)).OrderBy(t => t.ReflectionName).ToArray();; return types.Select(t => compilation.FindType(t)).OrderBy(t => t.ReflectionName).ToArray();
} }
ITypeDefinition Resolve(IUnresolvedTypeDefinition typeDef) ITypeDefinition Resolve(IUnresolvedTypeDefinition typeDef)
@ -58,24 +90,26 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void ObjectBaseTypes() public void ObjectBaseTypes()
{ {
Assert.AreEqual(GetTypes(typeof(object)), GetAllBaseTypes(typeof(object))); Assert.AreEqual(GetTypes(typeof(object)), GetAllBaseTypes(typeof(object)));
Assert.That(compilation.FindType(KnownTypeCode.Object).DirectBaseTypes, Is.Empty);
} }
[Test] [Test]
public void StringBaseTypes() public void StringBaseTypes()
{ {
Assert.AreEqual(GetTypes(typeof(string), typeof(object), typeof(IComparable), typeof(ICloneable), typeof(IConvertible), Assert.AreEqual(GetTypes(typeof(string), typeof(object),
typeof(IComparable<string>), typeof(IEquatable<string>), typeof(IEnumerable<char>), typeof(IEnumerable)), typeof(IComparable<string>), typeof(IEnumerable<char>), typeof(IEnumerable)),
GetAllBaseTypes(typeof(string))); GetAllBaseTypes(typeof(string)));
} }
[Test] [Test]
[Ignore("Produces different results in .NET 4.5 due to new read-only interfaces")]
public void ArrayOfString() public void ArrayOfString()
{ {
Assert.AreEqual(GetTypes(typeof(string[]), typeof(Array), typeof(object), var expectedTypes = GetTypes(
typeof(IList), typeof(ICollection), typeof(IEnumerable), typeof(string[]), typeof(Array), typeof(object),
typeof(IList<string>), typeof(ICollection<string>), typeof(IEnumerable<string>), typeof(IList), typeof(ICollection), typeof(IEnumerable), typeof(ICloneable),
typeof(IStructuralEquatable), typeof(IStructuralComparable), typeof(ICloneable)), typeof(IList<string>), typeof(ICollection<string>), typeof(IEnumerable<string>));
Assert.AreEqual(expectedTypes,
GetAllBaseTypes(typeof(string[]))); GetAllBaseTypes(typeof(string[])));
} }
@ -83,8 +117,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
public unsafe void ArrayOfPointers() public unsafe void ArrayOfPointers()
{ {
Assert.AreEqual(GetTypes(typeof(int*[]), typeof(Array), typeof(object), Assert.AreEqual(GetTypes(typeof(int*[]), typeof(Array), typeof(object),
typeof(IList), typeof(ICollection), typeof(IEnumerable), typeof(IList), typeof(ICollection), typeof(IEnumerable), typeof(ICloneable)),
typeof(IStructuralEquatable), typeof(IStructuralComparable), typeof(ICloneable)),
GetAllBaseTypes(typeof(int*[]))); GetAllBaseTypes(typeof(int*[])));
} }
@ -92,8 +125,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void MultidimensionalArrayOfString() public void MultidimensionalArrayOfString()
{ {
Assert.AreEqual(GetTypes(typeof(string[,]), typeof(Array), typeof(object), Assert.AreEqual(GetTypes(typeof(string[,]), typeof(Array), typeof(object),
typeof(IList), typeof(ICollection), typeof(IEnumerable), typeof(IList), typeof(ICollection), typeof(IEnumerable), typeof(ICloneable)),
typeof(IStructuralEquatable), typeof(IStructuralComparable), typeof(ICloneable)),
GetAllBaseTypes(typeof(string[,]))); GetAllBaseTypes(typeof(string[,])));
} }
@ -175,7 +207,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
[Test] [Test]
[Ignore("Produces different results in .NET 4.5 due to new read-only interfaces")]
public void BaseTypesOfListOfString() public void BaseTypesOfListOfString()
{ {
Assert.AreEqual( Assert.AreEqual(
@ -186,7 +217,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
[Test] [Test]
[Ignore("Produces different results in .NET 4.5 due to new read-only interfaces")]
public void BaseTypesOfUnboundDictionary() public void BaseTypesOfUnboundDictionary()
{ {
Assert.AreEqual( Assert.AreEqual(
@ -198,15 +228,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
typeof(ICollection).FullName, typeof(ICollection).FullName,
typeof(IDictionary).FullName, typeof(IDictionary).FullName,
typeof(IEnumerable).FullName, typeof(IEnumerable).FullName,
typeof(object).FullName, typeof(object).FullName
typeof(IDeserializationCallback).FullName,
typeof(ISerializable).FullName,
}, },
GetAllBaseTypes(typeof(Dictionary<,>)).Select(t => t.ReflectionName).ToArray()); GetAllBaseTypes(typeof(Dictionary<,>)).Select(t => t.ReflectionName).OrderBy(n => n).ToArray());
} }
[Test] [Test]
[Ignore("Produces different results in .NET 4.5 due to new read-only interfaces")]
public void BaseTypeDefinitionsOfListOfString() public void BaseTypeDefinitionsOfListOfString()
{ {
Assert.AreEqual( Assert.AreEqual(
@ -217,12 +244,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
[Test] [Test]
[Ignore("Produces different results in .NET 4.5 due to new read-only interfaces")]
public void BaseTypeDefinitionsOfStringArray() public void BaseTypeDefinitionsOfStringArray()
{ {
Assert.AreEqual( Assert.AreEqual(
GetTypes(typeof(Array), typeof(object), GetTypes(typeof(Array), typeof(object), typeof(ICloneable),
typeof(ICloneable), typeof(IStructuralComparable), typeof(IStructuralEquatable),
typeof(IList), typeof(ICollection), typeof(IEnumerable), typeof(IList), typeof(ICollection), typeof(IEnumerable),
typeof(IEnumerable<>), typeof(ICollection<>), typeof(IList<>)), typeof(IEnumerable<>), typeof(ICollection<>), typeof(IList<>)),
compilation.FindType(typeof(string[])).GetAllBaseTypeDefinitions().OrderBy(t => t.ReflectionName).ToArray()); compilation.FindType(typeof(string[])).GetAllBaseTypeDefinitions().OrderBy(t => t.ReflectionName).ToArray());

Loading…
Cancel
Save