59c67aa3af0ae613ea2d4b90ccfe6ea8d91741777e28d43f56498659563c82f9c2386704297d4dc8325aa261f08a9345b0dab45d293728201a04ee4e9e87d6 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. module.exports = function (trimStart, t) {
  3. t.test('normal cases', function (st) {
  4. st.equal(trimStart(' \t\na \t\n'), 'a \t\n', 'strips whitespace off the left side');
  5. st.equal(trimStart('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(trimStart(allWhitespaceChars + 'a' + allWhitespaceChars), 'a' + allWhitespaceChars, '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. trimStart(mongolianVowelSeparator + 'a' + mongolianVowelSeparator),
  16. (mvsIsWS ? '' : mongolianVowelSeparator) + 'a' + 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(trimStart(zeroWidth), zeroWidth, 'zero width space does not trim');
  24. st.end();
  25. });
  26. };