/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

http://github.com/icsharpcode/ILSpy · C# · 100 lines · 74 code · 9 blank · 17 comment · 4 complexity · ec83a4967407984725563724a166de8b MD5 · raw file

  1. // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
  2. //
  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:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  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.
  18. using System;
  19. using System.IO;
  20. using System.Linq;
  21. using ICSharpCode.NRefactory.Documentation;
  22. using ICSharpCode.NRefactory.TypeSystem;
  23. using ICSharpCode.NRefactory.TypeSystem.Implementation;
  24. using ICSharpCode.NRefactory.TypeSystem.TestCase;
  25. using ICSharpCode.NRefactory.Utils;
  26. using NUnit.Framework;
  27. namespace ICSharpCode.NRefactory.CSharp.Parser
  28. {
  29. [TestFixture]
  30. public class TypeSystemConvertVisitorTests : TypeSystemTests
  31. {
  32. [TestFixtureSetUp]
  33. public void FixtureSetUp()
  34. {
  35. compilation = ParseTestCase().CreateCompilation();
  36. }
  37. internal static IProjectContent ParseTestCase()
  38. {
  39. const string fileName = "TypeSystemTests.TestCase.cs";
  40. CSharpParser parser = new CSharpParser();
  41. SyntaxTree syntaxTree;
  42. using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
  43. syntaxTree = parser.Parse(s, fileName);
  44. }
  45. var unresolvedFile = syntaxTree.ToTypeSystem();
  46. return new CSharpProjectContent()
  47. .AddOrUpdateFiles(unresolvedFile)
  48. .AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib })
  49. .SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name);
  50. }
  51. [Test]
  52. public void ConvertStandaloneTypeReference()
  53. {
  54. var typeRef = new MemberType(new SimpleType("System"), "Array").ToTypeReference();
  55. Assert.AreEqual(compilation.FindType(KnownTypeCode.Array), typeRef.Resolve(compilation.TypeResolveContext));
  56. }
  57. [Test]
  58. public void PartialMethodWithImplementation()
  59. {
  60. var t = compilation.FindType(typeof(PartialClass));
  61. var methods = t.GetMethods(m => m.Name == "PartialMethodWithImplementation").ToList();
  62. Assert.AreEqual(2, methods.Count);
  63. var method1 = methods.Single(m => m.Parameters[0].Type.FullName == "System.Int32");
  64. var method2 = methods.Single(m => m.Parameters[0].Type.FullName == "System.String");
  65. Assert.AreEqual(2, method1.Parts.Count);
  66. Assert.AreEqual(2, method2.Parts.Count);
  67. }
  68. [Test]
  69. public void PartialMethodWithoutImplementation()
  70. {
  71. var t = compilation.FindType(typeof(PartialClass));
  72. var method = t.GetMethods(m => m.Name == "PartialMethodWithoutImplementation").Single();
  73. Assert.AreEqual(1, method.Parts.Count);
  74. }
  75. }
  76. [TestFixture]
  77. public class SerializedTypeSystemConvertVisitorTests : TypeSystemTests
  78. {
  79. [TestFixtureSetUp]
  80. public void FixtureSetUp()
  81. {
  82. FastSerializer serializer = new FastSerializer();
  83. using (MemoryStream ms = new MemoryStream()) {
  84. serializer.Serialize(ms, TypeSystemConvertVisitorTests.ParseTestCase());
  85. ms.Position = 0;
  86. var pc = (IProjectContent)serializer.Deserialize(ms);
  87. compilation = pc.CreateCompilation();
  88. }
  89. }
  90. }
  91. }