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,
|
|
|
|
characters: 11,
|
|
|
|
all: 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,
|
|
|
|
characters: 11,
|
|
|
|
all: 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,
|
|
|
|
characters: 11,
|
|
|
|
all: 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,
|
|
|
|
characters: 11,
|
|
|
|
all: 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-16 11:44:43 +02:00
|
|
|
characters: 15,
|
|
|
|
all: 19
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Em dash.',
|
|
|
|
string: 'one\u2014two--three',
|
|
|
|
words: 3,
|
|
|
|
characters: 14,
|
2015-07-16 01:47:02 +02:00
|
|
|
all: 14
|
2015-07-16 23:08:05 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Shortcodes.',
|
|
|
|
string: 'one [shortcode attribute="value"]two[/shortcode]three',
|
|
|
|
words: 3,
|
|
|
|
characters: 11,
|
|
|
|
all: 12
|
2015-07-18 13:41:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'Astrals.',
|
|
|
|
string: '\uD83D\uDCA9',
|
|
|
|
words: 1,
|
|
|
|
characters: 1,
|
|
|
|
all: 1
|
2015-07-21 17:23:45 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'HTML comment.',
|
|
|
|
string: 'one<!-- comment -->two three',
|
|
|
|
words: 2,
|
|
|
|
characters: 11,
|
|
|
|
all: 12
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message: 'HTML entity.',
|
|
|
|
string: '> test',
|
|
|
|
words: 1,
|
|
|
|
characters: 5,
|
|
|
|
all: 6
|
2015-06-19 12:34:59 +02:00
|
|
|
}
|
2015-07-16 01:47:02 +02:00
|
|
|
], function( test ) {
|
|
|
|
_.each( [ 'words', 'characters', 'all' ], function( type ) {
|
|
|
|
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' ]
|
|
|
|
}
|
|
|
|
} ) );
|