b05cd546828790774cebfdcbe8c38c37704412cb526b3d7898d398459740c2d45a08ef050a335fdff109588ae0f643838ff335538e6dec6d142ee4362e86f9 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. module.exports = function (trimEnd, t) {
  3. t.test('normal cases', function (st) {
  4. st.equal(trimEnd(' \t\na \t\n'), ' \t\na', 'strips whitespace off the left side');
  5. st.equal(trimEnd('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(trimEnd(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. var mvsIsWS = (/^\s$/).test(mongolianVowelSeparator);
  13. t.test('mongolian vowel separator: unicode >= 4 && < 6.3', function (st) {
  14. st.equal(
  15. trimEnd(mongolianVowelSeparator + 'a' + mongolianVowelSeparator),
  16. mongolianVowelSeparator + 'a' + (mvsIsWS ? '' : mongolianVowelSeparator),
  17. 'mongolian vowel separator is ' + (mvsIsWS ? '' : 'not ') + 'whitespace'
  18. );
  19. st.end();
  20. });
  21. t.test('zero-width spaces', function (st) {
  22. var zeroWidth = '\u200b';
  23. st.equal(trimEnd(zeroWidth), zeroWidth, 'zero width space does not trim');
  24. st.end();
  25. });
  26. };