BasicTests.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEngine.TestTools;
  6. using com.bbbirder;
  7. using bt_it;
  8. public class BasicTests
  9. {
  10. static void AssertCount<T>(int count) where T : DirectRetrieveAttribute
  11. {
  12. var al = Retriever.GetAllAttributes<T>(typeof(BasicTests).Assembly);
  13. Assert.AreEqual(count, al.Length);
  14. }
  15. static void AssertSubTypeCount<T>(int count)
  16. {
  17. var sl = Retriever.GetAllSubtypes(typeof(T), typeof(BasicTests).Assembly);
  18. Assert.AreEqual(count, sl.Length);
  19. }
  20. // A Test behaves as an ordinary method
  21. [Test]
  22. public void TestGenerics()
  23. {
  24. AssertCount<TGAttribute>(4);
  25. }
  26. [Test]
  27. public void TestNest()
  28. {
  29. AssertCount<INNAttribute>(3);
  30. }
  31. [Test]
  32. public void TestBaseType()
  33. {
  34. AssertSubTypeCount<MyBaseType>(5);
  35. }
  36. [Test]
  37. public void TestInterface()
  38. {
  39. AssertSubTypeCount<IMyInterface>(4);
  40. }
  41. [Test]
  42. public void TestEnum()
  43. {
  44. AssertCount<EnumAttribute>(2);
  45. }
  46. }
  47. class EnumAttribute : DirectRetrieveAttribute { }
  48. class TGAttribute : DirectRetrieveAttribute { }
  49. class INNAttribute : DirectRetrieveAttribute { }
  50. namespace innerA.innerB
  51. {
  52. public class TestClassA<T>
  53. {
  54. [TG]
  55. public void Bar(T t)
  56. {
  57. }
  58. [TG]
  59. public void Foo<G>(G g)
  60. {
  61. }
  62. [TG]
  63. public void Foo2<G, H>(G g)
  64. {
  65. }
  66. }
  67. [TG]
  68. internal class TestGenericB<T, F, G>
  69. {
  70. [INN]
  71. internal class Inner
  72. {
  73. [INN]
  74. static void Bar()
  75. {
  76. }
  77. [INN]
  78. internal class Far
  79. {
  80. }
  81. }
  82. }
  83. }
  84. namespace bt_it
  85. {
  86. enum FooEnum
  87. {
  88. Default,
  89. Foo,
  90. [Enum]
  91. Bar,
  92. [Enum]
  93. Baz,
  94. Length,
  95. }
  96. class MyBaseType : IDirectRetrieve
  97. {
  98. }
  99. class SubA<T> : MyBaseType
  100. {
  101. internal class SubA_A<G, F> : MyBaseType { }
  102. }
  103. class SubB : SubA<int> { }
  104. class SubC<T> : SubA<T> { }
  105. class SubD : SubB { }
  106. interface IMyInterface : IDirectRetrieve
  107. {
  108. }
  109. class ImpA<T> : IMyInterface
  110. {
  111. internal class ImpA_A<G, F> : IMyInterface { }
  112. }
  113. class ImpB : ImpA<int> { }
  114. struct ImpS : IMyInterface { }
  115. }