Skip to content

Commit

Permalink
Improve exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stefnotch committed Nov 4, 2019
1 parent 2aa2221 commit b19a244
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions Source/Editor/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,34 @@ public SuccessException(string message, Exception innerException) : base(message
}
}

/// <summary>
/// Exception thrown when an assertion fails
/// </summary>
/// <seealso cref="System.Exception" />
public class AssertException : Exception
{
public AssertException()
{
}

public AssertException(string message) : base(message)
{
}

public AssertException(string message, Exception innerException) : base(message, innerException)
{
}
}

public static class Assert
{
public static void Pass() => throw new SuccessException();
public static void Fail() => throw new Exception();
public static void Fail() => throw new AssertException("Fail");

public static void AreEqual(object a, object b) { if (!Equals(a, b)) throw new Exception(); }
public static void AreNotEqual(object a, object b) { if (Equals(a, b)) throw new Exception(); }
public static void AreEqual(object a, object b) { if (!Equals(a, b)) throw new AssertException($"{a} does not equal {b}"); }
public static void AreNotEqual(object a, object b) { if (Equals(a, b)) throw new Exception($"{a} is equal to {b}"); }

public static void True(bool a) { if (!a) throw new Exception(); }
public static void False(bool a) { if (a) throw new Exception(); }
public static void True(bool a) { if (!a) throw new Exception($"{a} is not true"); }
public static void False(bool a) { if (a) throw new Exception($"{a} is not false"); }
}
}

0 comments on commit b19a244

Please sign in to comment.