Guest User

Untitled

a guest
Nov 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // checks our test conditions
  2. // @param - condition (function) test to run
  3. // @param - ref (string) to display for result
  4. assert = function (condition, ref){
  5. if(condition){
  6. console.log("+ Passed: " + ref);
  7. } else {
  8. console.log("- Failed: " + ref, 'warn');
  9. }
  10. };
  11.  
  12. // tests that special characters \r, \n have been
  13. // removed from a string
  14. testsRemoveSpecialCharactersFromString = function (){
  15. var specialString = '\rI am \nreally\n\rspecial\r\n dont_you_think_so? maybe-not';
  16.  
  17. assert(specialString.indexOf('_') > -1, '_ in string');
  18. assert(specialString.indexOf('?') > -1, '? in string');
  19. assert(specialString.indexOf('-') > -1, '- in string');
  20. assert(specialString.indexOf('\r') > -1, '\\r in string');
  21. assert(specialString.indexOf('\n') > -1, '\\n in string');
  22.  
  23. assert(specialString.removeSpecialCharacters().indexOf('?') == -1, '\? removed from string');
  24. assert(specialString.removeSpecialCharacters().indexOf('-') == -1, '\- removed from string');
  25. assert(specialString.removeSpecialCharacters().indexOf('_') == -1, '\_ removed from string');
  26. assert(specialString.removeSpecialCharacters().indexOf('\r') == -1, '\\r removed from string');
  27. assert(specialString.removeSpecialCharacters().indexOf('\n') == -1, '\\n removed from string');
  28. };
Add Comment
Please, Sign In to add comment