Created
June 25, 2012 21:00
-
-
Save iampeterbanjo/2991209 to your computer and use it in GitHub Desktop.
test String.removeSpecialCharacters
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
// checks our test conditions | |
// @param - condition (function) test to run | |
// @param - ref (string) to display for result | |
assert = function (condition, ref){ | |
if(condition){ | |
console.log("+ Passed: " + ref); | |
} else { | |
console.log("- Failed: " + ref, 'warn'); | |
} | |
}; | |
// tests that special characters \r, \n have been | |
// removed from a string | |
testsRemoveSpecialCharactersFromString = function (){ | |
var specialString = '\rI am \nreally\n\rspecial\r\n dont_you_think_so? maybe-not'; | |
assert(specialString.indexOf('_') > -1, '_ in string'); | |
assert(specialString.indexOf('?') > -1, '? in string'); | |
assert(specialString.indexOf('-') > -1, '- in string'); | |
assert(specialString.indexOf('\r') > -1, '\\r in string'); | |
assert(specialString.indexOf('\n') > -1, '\\n in string'); | |
assert(specialString.removeSpecialCharacters().indexOf('?') == -1, '\? removed from string'); | |
assert(specialString.removeSpecialCharacters().indexOf('-') == -1, '\- removed from string'); | |
assert(specialString.removeSpecialCharacters().indexOf('_') == -1, '\_ removed from string'); | |
assert(specialString.removeSpecialCharacters().indexOf('\r') == -1, '\\r removed from string'); | |
assert(specialString.removeSpecialCharacters().indexOf('\n') == -1, '\\n removed from string'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment