Allow equals() to receive functions from which it then extracts the code for the message.

This commit is contained in:
Jürg Lehni 2011-05-07 17:25:34 +01:00
parent 566f52201c
commit 66824b780a

View file

@ -1,5 +1,18 @@
// Let's be strict
equals = strictEqual;
function equals(actual, expected, message) {
if (typeof actual === 'function') {
if (!message) {
message = actual.toString().match(
/^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1]
.replace(/ /g, '')
.replace(/^\s+|\s+$/g, '')
.replace(/^return /, '');
}
actual = actual();
}
return strictEqual(actual, expected, message);
}
function compareNumbers(number1, number2, message) {
if (number1 !== 0)