word-count.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ( function( QUnit, wordCounter ) {
  2. QUnit.module( 'word-count' );
  3. QUnit.test( 'All.', function( assert ) {
  4. _.each( [
  5. {
  6. message: 'Basic test.',
  7. string: 'one two three',
  8. words: 3,
  9. characters_excluding_spaces: 11,
  10. characters_including_spaces: 13
  11. },
  12. {
  13. message: 'HTML tags.',
  14. string: 'one <em class="test">two</em><br />three',
  15. words: 3,
  16. characters_excluding_spaces: 11,
  17. characters_including_spaces: 12
  18. },
  19. {
  20. message: 'Line breaks.',
  21. string: 'one\ntwo\nthree',
  22. words: 3,
  23. characters_excluding_spaces: 11,
  24. characters_including_spaces: 11
  25. },
  26. {
  27. message: 'Encoded spaces.',
  28. string: 'one&nbsp;two&#160;three',
  29. words: 3,
  30. characters_excluding_spaces: 11,
  31. characters_including_spaces: 13
  32. },
  33. {
  34. message: 'Punctuation.',
  35. string: 'It\'s two three \u2026 4?',
  36. words: 3,
  37. characters_excluding_spaces: 15,
  38. characters_including_spaces: 19
  39. },
  40. {
  41. message: 'Em dash.',
  42. string: 'one\u2014two--three',
  43. words: 3,
  44. characters_excluding_spaces: 14,
  45. characters_including_spaces: 14
  46. },
  47. {
  48. message: 'Shortcodes.',
  49. string: 'one [shortcode attribute="value"]two[/shortcode]three',
  50. words: 3,
  51. characters_excluding_spaces: 11,
  52. characters_including_spaces: 12
  53. },
  54. {
  55. message: 'Astrals.',
  56. string: '\uD83D\uDCA9',
  57. words: 1,
  58. characters_excluding_spaces: 1,
  59. characters_including_spaces: 1
  60. },
  61. {
  62. message: 'HTML comment.',
  63. string: 'one<!-- comment -->two three',
  64. words: 2,
  65. characters_excluding_spaces: 11,
  66. characters_including_spaces: 12
  67. },
  68. {
  69. message: 'HTML entity.',
  70. string: '&gt; test',
  71. words: 1,
  72. characters_excluding_spaces: 5,
  73. characters_including_spaces: 6
  74. }
  75. ], function( test ) {
  76. _.each( [ 'words', 'characters_excluding_spaces', 'characters_including_spaces' ], function( type ) {
  77. assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' );
  78. } );
  79. } );
  80. } );
  81. } )( window.QUnit, new window.wp.utils.WordCounter( {
  82. l10n: {
  83. shortcodes: [ 'shortcode' ]
  84. }
  85. } ) );