1
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
// software and associated documentation files (the "Software"), to deal in the Software
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
// to whom the Software is furnished to do so, subject to the following conditions:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
// DEALINGS IN THE SOFTWARE.
22
using ICSharpCode.NRefactory.Documentation;
23
using ICSharpCode.NRefactory.TypeSystem;
24
using ICSharpCode.NRefactory.TypeSystem.Implementation;
25
using ICSharpCode.NRefactory.TypeSystem.TestCase;
26
using ICSharpCode.NRefactory.Utils;
27
using NUnit.Framework;
29
namespace ICSharpCode.NRefactory.CSharp.Parser
32
public class TypeSystemConvertVisitorTests : TypeSystemTests
35
public void FixtureSetUp()
37
compilation = ParseTestCase().CreateCompilation();
40
static IProjectContent CreateContent (IUnresolvedFile unresolvedFile)
42
return new CSharpProjectContent()
43
.AddOrUpdateFiles(unresolvedFile)
44
.AddAssemblyReferences(new[] {
45
CecilLoaderTests.Mscorlib
47
.SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name);
50
internal static IProjectContent ParseTestCase()
52
const string fileName = "TypeSystemTests.TestCase.cs";
54
CSharpParser parser = new CSharpParser();
55
SyntaxTree syntaxTree;
56
using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
57
syntaxTree = parser.Parse(s, fileName);
60
return CreateContent(syntaxTree.ToTypeSystem());
64
public void ConvertStandaloneTypeReference()
66
var typeRef = new MemberType(new SimpleType("System"), "Array").ToTypeReference();
67
Assert.AreEqual(compilation.FindType(KnownTypeCode.Array), typeRef.Resolve(compilation.TypeResolveContext));
71
public void PartialMethodWithImplementation()
73
var t = compilation.FindType(typeof(PartialClass));
74
var methods = t.GetMethods(m => m.Name == "PartialMethodWithImplementation").ToList();
75
Assert.AreEqual(2, methods.Count);
76
var method1 = methods.Single(m => m.Parameters[0].Type.FullName == "System.Int32");
77
var method2 = methods.Single(m => m.Parameters[0].Type.FullName == "System.String");
78
Assert.AreEqual(2, method1.Parts.Count);
79
Assert.AreEqual(2, method2.Parts.Count);
83
public void PartialMethodWithoutImplementation()
85
var t = compilation.FindType(typeof(PartialClass));
86
var method = t.GetMethods(m => m.Name == "PartialMethodWithoutImplementation").Single();
87
Assert.AreEqual(1, method.Parts.Count);
91
public void CyclicConstants()
93
var syntaxTree = SyntaxTree.Parse ("class Test { const int foo = foo; }");
94
syntaxTree.FileName = "a.cs";
95
var content = CreateContent (syntaxTree.ToTypeSystem());
96
var testType = content.CreateCompilation ().MainAssembly.GetTypeDefinition ("", "Test");
97
Assert.NotNull (testType);
98
var field = testType.Fields.First ();
99
Assert.IsTrue (field.IsConst);
100
Assert.IsNull (field.ConstantValue);
105
public class SerializedTypeSystemConvertVisitorTests : TypeSystemTests
108
public void FixtureSetUp()
110
FastSerializer serializer = new FastSerializer();
111
using (MemoryStream ms = new MemoryStream()) {
112
serializer.Serialize(ms, TypeSystemConvertVisitorTests.ParseTestCase());
114
var pc = (IProjectContent)serializer.Deserialize(ms);
115
compilation = pc.CreateCompilation();