private static string GetMessage(string method, VerificationResult failure) { if (failure.IsStackUnderflow) { if (failure.ExpectedStackSize == 1) { return method + " expects a value on the stack, but it was empty"; } return method + " expects " + failure.ExpectedStackSize + " values on the stack"; } if (failure.IsTypeMismatch) { if (failure.ExpectedAtStackIndex != null) { var expected = ErrorMessageString(failure.ExpectedAtStackIndex); var found = ErrorMessageString(failure.Stack.ElementAt(failure.StackIndex)); return method + " expected " + (ExtensionMethods.StartsWithVowel(expected) ? "an " : "a ") + expected + "; found " + found; } var ex = ErrorMessageString(failure.ExpectedOnStack); var ac = ErrorMessageString(failure.ActuallyOnStack); return method + " expected " + (ExtensionMethods.StartsWithVowel(ex) ? "an " : "a ") + ex + "; found " + ac; } if (failure.IsStackMismatch) { return method + " resulted in stack mismatches"; } if (failure.IsStackSizeFailure) { if (failure.ExpectedStackSize == 0) { return method + " expected the stack of be empty"; } if (failure.ExpectedStackSize == 1) { return method + " expected the stack to have 1 value"; } return method + " expected the stack to have " + failure.ExpectedStackSize + " values"; } throw new Exception("Shouldn't be possible!"); }
internal SigilVerificationException(string method, VerificationResult failure, string[] instructions) : this(GetMessage(method, failure), instructions) { VerificationFailure = failure; }