2015-07-16 01:47:02 +02:00
|
|
|
( function( QUnit, wordCounter ) {
|
2015-06-19 12:34:59 +02:00
|
|
|
QUnit.module( 'word-count' );
|
|
|
|
|
|
|
|
QUnit.test( 'All.', function( assert ) {
|
2015-07-16 01:47:02 +02:00
|
|
|
_.each( [
|
2015-06-19 12:34:59 +02:00
|
|
|
{
|
|
|
|
message: 'Basic test.',
|
|
|
|
string: 'one two three',
|
2015-07-16 01:47:02 +02:00
|
|
|
words: 3,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 11,
|
|
|
|
characters_including_spaces: 13
|
2015-06-19 12:34:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'HTML tags.',
|
|
|
|
string: 'one <em class="test">two</em><br />three',
|
2015-07-16 01:47:02 +02:00
|
|
|
words: 3,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 11,
|
|
|
|
characters_including_spaces: 12
|
2015-06-19 12:34:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Line breaks.',
|
|
|
|
string: 'one\ntwo\nthree',
|
2015-07-16 01:47:02 +02:00
|
|
|
words: 3,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 11,
|
|
|
|
characters_including_spaces: 11
|
2015-06-19 12:34:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Encoded spaces.',
|
|
|
|
string: 'one two three',
|
2015-07-16 01:47:02 +02:00
|
|
|
words: 3,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 11,
|
|
|
|
characters_including_spaces: 13
|
2015-06-19 12:34:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Punctuation.',
|
2015-07-16 11:44:43 +02:00
|
|
|
string: 'It\'s two three \u2026 4?',
|
2015-07-16 01:47:02 +02:00
|
|
|
words: 3,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 15,
|
|
|
|
characters_including_spaces: 19
|
2015-07-16 11:44:43 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Em dash.',
|
|
|
|
string: 'one\u2014two--three',
|
|
|
|
words: 3,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 14,
|
|
|
|
characters_including_spaces: 14
|
2015-07-16 23:08:05 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Shortcodes.',
|
|
|
|
string: 'one [shortcode attribute="value"]two[/shortcode]three',
|
|
|
|
words: 3,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 11,
|
|
|
|
characters_including_spaces: 12
|
2015-07-18 13:41:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Astrals.',
|
|
|
|
string: '\uD83D\uDCA9',
|
|
|
|
words: 1,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 1,
|
|
|
|
characters_including_spaces: 1
|
2015-07-21 17:23:45 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'HTML comment.',
|
|
|
|
string: 'one<!-- comment -->two three',
|
|
|
|
words: 2,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 11,
|
|
|
|
characters_including_spaces: 12
|
2015-07-21 17:23:45 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'HTML entity.',
|
|
|
|
string: '> test',
|
|
|
|
words: 1,
|
2015-07-27 13:18:55 +02:00
|
|
|
characters_excluding_spaces: 5,
|
|
|
|
characters_including_spaces: 6
|
2015-06-19 12:34:59 +02:00
|
|
|
}
|
2015-07-16 01:47:02 +02:00
|
|
|
], function( test ) {
|
2015-07-27 13:18:55 +02:00
|
|
|
_.each( [ 'words', 'characters_excluding_spaces', 'characters_including_spaces' ], function( type ) {
|
2015-07-16 01:47:02 +02:00
|
|
|
assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' );
|
|
|
|
} );
|
|
|
|
} );
|
2015-06-19 12:34:59 +02:00
|
|
|
} );
|
2015-07-16 23:08:05 +02:00
|
|
|
} )( window.QUnit, new window.wp.utils.WordCounter( {
|
|
|
|
l10n: {
|
|
|
|
shortcodes: [ 'shortcode' ]
|
|
|
|
}
|
|
|
|
} ) );
|