You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tests.js 1.2KB

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. module.exports = function (trimRight, t) {
  3. t.test('normal cases', function (st) {
  4. st.equal(trimRight(' \t\na \t\n'), ' \t\na', 'strips whitespace off the left side');
  5. st.equal(trimRight('a'), 'a', 'noop when no whitespace');
  6. var allWhitespaceChars = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
  7. st.equal(trimRight(allWhitespaceChars + 'a' + allWhitespaceChars), allWhitespaceChars + 'a', 'all expected whitespace chars are trimmed');
  8. st.end();
  9. });
  10. // see https://codeblog.jonskeet.uk/2014/12/01/when-is-an-identifier-not-an-identifier-attack-of-the-mongolian-vowel-separator/
  11. var mongolianVowelSeparator = '\u180E';
  12. t.test('unicode >= 4 && < 6.3', { skip: !(/^\s$/).test(mongolianVowelSeparator) }, function (st) {
  13. st.equal(trimRight(mongolianVowelSeparator + 'a' + mongolianVowelSeparator), mongolianVowelSeparator + 'a', 'mongolian vowel separator is whitespace');
  14. st.end();
  15. });
  16. t.test('zero-width spaces', function (st) {
  17. var zeroWidth = '\u200b';
  18. st.equal(trimRight(zeroWidth), zeroWidth, 'zero width space does not trim');
  19. st.end();
  20. });
  21. };