Created
June 22, 2009 08:54
-
-
Save timblair/133874 to your computer and use it in GitHub Desktop.
Patch to allow case-sensitive text matching as part of assertEquals() in mxunit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: framework/Assert.cfc | |
=================================================================== | |
--- framework/Assert.cfc (revision 1148) | |
+++ framework/Assert.cfc (working copy) | |
@@ -128,21 +128,23 @@ | |
<cfargument name="expected" type="any" required="yes" hint="The expected string value" /> | |
<cfargument name="actual" type="any" required="yes" hint="The actual string value" /> | |
<cfargument name="message" required="false" default="This test failed" hint="Custom message to print in the failure." /> | |
+ <cfargument name="caseSensitive" type="boolean" required="false" default="false" hint="If set to TRUE checks the original string unaltered. Default is to check the string in lowercase" /> | |
<cfset arguments = normalizeArguments("equals",arguments)> | |
- <cfthrow type="mxunit.exception.AssertionFailedError" message="#arguments.message#:: Expected [#getStringValue(arguments.expected)#] BUT RECEIVED [#getStringValue(arguments.actual)#] " /> | |
+ <cfthrow type="mxunit.exception.AssertionFailedError" message="#arguments.message#:: Expected [#getStringValue(arguments.expected, arguments.caseSensitive)#] BUT RECEIVED [#getStringValue(arguments.actual, arguments.caseSensitive)#] instead" /> | |
</cffunction> | |
<cffunction name="failNotEquals" access="private" returntype="void" static="true" hint="Fails the test and prints the expected and actual values to the failure message"> | |
<cfargument name="expected" type="any" required="yes" hint="The expected string value" /> | |
<cfargument name="actual" type="any" required="yes" hint="The actual string value" /> | |
<cfargument name="message" required="false" default="This test failed" hint="Custom message to print in the failure." /> | |
+ <cfargument name="caseSensitive" type="boolean" required="false" default="false" hint="If set to TRUE checks the original string unaltered. Default is to check the string in lowercase" /> | |
<cfset arguments = normalizeArguments("equals",arguments)> | |
<cfif isSimpleValue(expected) AND isSimpleValue(actual)> | |
<cfset this.expected = arguments.expected> | |
<cfset this.actual = arguments.actual> | |
</cfif> | |
- <cfthrow type="mxunit.exception.AssertionFailedError" message="#arguments.message#:: Expected [#getStringValue(arguments.expected)#] BUT RECEIVED [#getStringValue(arguments.actual)#] " /> | |
+ <cfthrow type="mxunit.exception.AssertionFailedError" message="#arguments.message#:: Expected [#getStringValue(arguments.expected, arguments.caseSensitive)#] BUT RECEIVED [#getStringValue(arguments.actual, arguments.caseSensitive)#] instead" /> | |
</cffunction> | |
<cffunction name="getStringValue" returntype="string" access="public" hint="Attempts to return string representation of OBJ. Tests to see if object has toString or stringValue methods to be used for comparison and returns that string if present"> | |
@@ -201,12 +203,13 @@ | |
<cfargument name="expected" type="any" required="yes" hint="The expected object to compare." /> | |
<cfargument name="actual" type="any" required="yes" hint="The actual object to compare." /> | |
<cfargument name="message" type="string" required="no" default="" hint="Optional custom message to display if comparison fails." /> | |
+ <cfargument name="caseSensitive" type="boolean" required="false" default="false" hint="If set to TRUE checks the original string unaltered. Default is to check the string in lowercase" /> | |
<cfset var expectedStringValue = ""> | |
<cfset var actualStringValue = ""> | |
<cfset arguments = normalizeArguments("equals",arguments)> | |
- <cfset expectedStringValue = getStringValue(arguments.expected) /> | |
- <cfset actualStringValue = getStringValue(arguments.actual) /> | |
+ <cfset expectedStringValue = getStringValue(arguments.expected, arguments.caseSensitive) /> | |
+ <cfset actualStringValue = getStringValue(arguments.actual, arguments.caseSensitive) /> | |
<cfscript> | |
if (isNumeric(arguments.expected) AND isnumeric(arguments.actual) AND arguments.expected eq arguments.actual){ | |
return; | |
@@ -217,7 +220,7 @@ | |
if (expectedStringValue is not "" AND expectedStringValue.equals(actualStringValue)){ | |
return; | |
} | |
- failNotEquals(expectedStringValue, actualStringValue, arguments.message); | |
+ failNotEquals(expectedStringValue, actualStringValue, arguments.message, arguments.caseSensitive); | |
</cfscript> | |
</cffunction> | |
@@ -225,21 +228,22 @@ | |
<cfargument name="expected" type="any" required="yes" hint="The expected object to compare." /> | |
<cfargument name="actual" type="any" required="yes" hint="The actual object to compare." /> | |
<cfargument name="message" type="string" required="no" default="" hint="Optional custom message to display if comparison fails." /> | |
+ <cfargument name="caseSensitive" type="boolean" required="false" default="false" hint="If set to TRUE checks the original string unaltered. Default is to check the string in lowercase" /> | |
<cfset var expectedStringValue = ""> | |
<cfset var actualStringValue = ""> | |
<cfset arguments = normalizeArguments("equals",arguments)> | |
- <cfset expectedStringValue = getStringValue(arguments.expected) /> | |
- <cfset actualStringValue = getStringValue(arguments.actual) /> | |
+ <cfset expectedStringValue = getStringValue(arguments.expected, arguments.caseSensitive) /> | |
+ <cfset actualStringValue = getStringValue(arguments.actual, arguments.caseSensitive) /> | |
<cfscript> | |
if (isNumeric(arguments.expected) AND isnumeric(arguments.actual) AND arguments.expected eq arguments.actual){ | |
- failEquals(expectedStringValue, actualStringValue, arguments.message); | |
+ failEquals(expectedStringValue, actualStringValue, arguments.message, arguments.caseSensitive); | |
} | |
if (expectedStringValue is "" AND actualStringValue is ""){ | |
- failEquals(expectedStringValue, actualStringValue, arguments.message); | |
+ failEquals(expectedStringValue, actualStringValue, arguments.message, arguments.caseSensitive); | |
} | |
if (expectedStringValue is not "" AND expectedStringValue.equals(actualStringValue)){ | |
- failEquals(expectedStringValue, actualStringValue,arguments.message); | |
+ failEquals(expectedStringValue, actualStringValue,arguments.message, arguments.caseSensitive); | |
} | |
return; | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment