Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iampeterbanjo/2991209 to your computer and use it in GitHub Desktop.
Save iampeterbanjo/2991209 to your computer and use it in GitHub Desktop.
test String.removeSpecialCharacters
// 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