AssertGeneric.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using XGame.Framework.Assertions;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. namespace XGame.Framework
  5. {
  6. public static partial class Assert
  7. {
  8. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  9. public static void AreEqual<T>(T expected, T actual)
  10. {
  11. AreEqual(expected, actual, null);
  12. }
  13. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  14. public static void AreEqual<T>(T expected, T actual, string format, params object[] args)
  15. {
  16. AreEqual(expected, actual, EqualityComparer<T>.Default, format, args);
  17. }
  18. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  19. public static void AreEqual<TValue, TExpection>(TValue expected, TValue actual, TExpection e) where TExpection : System.Exception
  20. {
  21. AreEqual(expected, actual, EqualityComparer<TValue>.Default, e);
  22. }
  23. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  24. public static void AreEqual<T>(T expected, T actual, IEqualityComparer<T> comparer, string format, params object[] args)
  25. {
  26. if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(T)))
  27. {
  28. AreEqual(expected as UnityEngine.Object, actual as UnityEngine.Object, format, args);
  29. return;
  30. }
  31. if (!comparer.Equals(actual, expected))
  32. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, true), format, args);
  33. }
  34. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  35. public static void AreEqual<TValue, TExpection>(TValue expected, TValue actual, IEqualityComparer<TValue> comparer, TExpection e) where TExpection : System.Exception
  36. {
  37. if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(TValue)))
  38. {
  39. AreEqual(expected as UnityEngine.Object, actual as UnityEngine.Object, e);
  40. return;
  41. }
  42. if (!comparer.Equals(actual, expected))
  43. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, true), e);
  44. }
  45. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  46. public static void AreEqual(UnityEngine.Object expected, UnityEngine.Object actual, string format, params object[] args)
  47. {
  48. if (actual != expected)
  49. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, true), format, args);
  50. }
  51. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  52. public static void AreEqual<TExpection>(UnityEngine.Object expected, UnityEngine.Object actual, TExpection e) where TExpection : System.Exception
  53. {
  54. if (actual != expected)
  55. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, true), e);
  56. }
  57. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  58. public static void AreNotEqual<T>(T expected, T actual)
  59. {
  60. AreNotEqual(expected, actual, null);
  61. }
  62. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  63. public static void AreNotEqual<T>(T expected, T actual, string format, params object[] args)
  64. {
  65. AreNotEqual(expected, actual, EqualityComparer<T>.Default, format, args);
  66. }
  67. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  68. public static void AreNotEqual<TValue, TExpection>(TValue expected, TValue actual, TExpection e) where TExpection : System.Exception
  69. {
  70. AreNotEqual(expected, actual, EqualityComparer<TValue>.Default, e);
  71. }
  72. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  73. public static void AreNotEqual<T>(T expected, T actual, IEqualityComparer<T> comparer, string format, params object[] args)
  74. {
  75. if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(T)))
  76. {
  77. AreNotEqual(expected as UnityEngine.Object, actual as UnityEngine.Object, format, args);
  78. return;
  79. }
  80. if (comparer.Equals(actual, expected))
  81. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, false), format, args);
  82. }
  83. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  84. public static void AreNotEqual<TValue, TExpection>(TValue expected, TValue actual, IEqualityComparer<TValue> comparer, TExpection e) where TExpection : System.Exception
  85. {
  86. if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(TValue)))
  87. {
  88. AreNotEqual(expected as UnityEngine.Object, actual as UnityEngine.Object, e);
  89. return;
  90. }
  91. if (comparer.Equals(actual, expected))
  92. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, false), e);
  93. }
  94. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  95. public static void AreNotEqual(UnityEngine.Object expected, UnityEngine.Object actual, string format, params object[] args)
  96. {
  97. if (actual == expected)
  98. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, false), format, args);
  99. }
  100. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  101. public static void AreNotEqual<TExpection>(UnityEngine.Object expected, UnityEngine.Object actual, TExpection e) where TExpection : System.Exception
  102. {
  103. if (actual == expected)
  104. Fail(AssertionMessageUtil.GetEqualityMessage(actual, expected, false), e);
  105. }
  106. }
  107. }