|
| 1 | +'use strict'; |
| 2 | +require('mocha'); |
| 3 | +var fs = require('fs'); |
| 4 | +var assert = require('assert'); |
| 5 | +var regex = require('..'); |
| 6 | + |
| 7 | +function isWhitespace(str) { |
| 8 | + return regex().test(str); |
| 9 | +} |
| 10 | + |
| 11 | +function read(name) { |
| 12 | + return fs.readFileSync('test/fixtures/' + name, 'utf8'); |
| 13 | +} |
| 14 | + |
| 15 | +describe('when non-whitespace exists:', function () { |
| 16 | + it('should return false.', function () { |
| 17 | + assert(!isWhitespace('foo')); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should return false.', function () { |
| 21 | + assert(!isWhitespace(read('text.txt'))); |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +describe('when non-whitespace exists:', function () { |
| 26 | + it('should return true for spaces', function () { |
| 27 | + assert(isWhitespace(' ')); |
| 28 | + }); |
| 29 | + it('should return true for spaces', function () { |
| 30 | + assert(isWhitespace(read('spaces.txt'))); |
| 31 | + }); |
| 32 | + it('should return true for tabs', function () { |
| 33 | + assert(isWhitespace(read('tabs.txt'))); |
| 34 | + }); |
| 35 | + it('should return true for newlines and spaces', function () { |
| 36 | + assert(isWhitespace(read('multiline.txt'))); |
| 37 | + }); |
| 38 | + it('should return true for varied spaces, newlines, and tabs', function () { |
| 39 | + assert(isWhitespace(read('varied.txt'))); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +describe('ES5-compliant whitespace', function () { |
| 44 | + it('should be true for all expected whitespace values', function () { |
| 45 | + assert(isWhitespace("\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF")); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should not be true for the zero-width space', function () { |
| 49 | + assert(!isWhitespace('\u200b')); |
| 50 | + }); |
| 51 | +}); |
0 commit comments