/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/StructureTests.cs

http://github.com/icsharpcode/ILSpy · C# · 74 lines · 52 code · 5 blank · 17 comment · 9 complexity · 88e95d7e3585031d6a8d71f96b999eea 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.Reflection;
  20. using NUnit.Framework;
  21. namespace ICSharpCode.NRefactory.TypeSystem
  22. {
  23. [TestFixture]
  24. public class StructureTests
  25. {
  26. [Test]
  27. public void ClassesThatSupportInterningAreSealed()
  28. {
  29. foreach (Type type in typeof(ISupportsInterning).Assembly.GetTypes()) {
  30. if (typeof(ISupportsInterning).IsAssignableFrom(type) && !type.IsInterface) {
  31. Assert.IsTrue(type.IsSealed, type.FullName);
  32. }
  33. }
  34. }
  35. [Test]
  36. public void System_TypeCode_corresponds_with_KnownTypeCode()
  37. {
  38. foreach (TypeCode typeCode in Enum.GetValues(typeof(System.TypeCode))) {
  39. if (typeCode == TypeCode.Empty)
  40. Assert.AreEqual("None", ((KnownTypeCode)typeCode).ToString());
  41. else
  42. Assert.AreEqual(typeCode.ToString(), ((KnownTypeCode)typeCode).ToString());
  43. }
  44. }
  45. [Test]
  46. public void KnownTypeReference_Get_returns_correct_KnownType()
  47. {
  48. foreach (KnownTypeCode typeCode in Enum.GetValues(typeof(KnownTypeCode))) {
  49. if (typeCode == KnownTypeCode.None) {
  50. Assert.IsNull(KnownTypeReference.Get(KnownTypeCode.None));
  51. } else {
  52. Assert.AreEqual(typeCode, KnownTypeReference.Get(typeCode).KnownTypeCode);
  53. }
  54. }
  55. }
  56. [Test]
  57. public void KnownTypeReference_has_static_fields_for_KnownTypes()
  58. {
  59. foreach (KnownTypeCode typeCode in Enum.GetValues(typeof(KnownTypeCode))) {
  60. if (typeCode == KnownTypeCode.None)
  61. continue;
  62. FieldInfo field = typeof(KnownTypeReference).GetField(typeCode.ToString());
  63. Assert.IsNotNull(field, "Missing field for " + typeCode.ToString());
  64. KnownTypeReference ktr = (KnownTypeReference)field.GetValue(null);
  65. Assert.AreEqual(typeCode, ktr.KnownTypeCode);
  66. }
  67. }
  68. }
  69. }