16e22cd0aa
This makes sure an emoji, for example, is counted as one character. See #30966. git-svn-id: https://develop.svn.wordpress.org/trunk@33320 602fd350-edb4-49c9-b593-d223f7449a82
73 lines
1.4 KiB
JavaScript
73 lines
1.4 KiB
JavaScript
( function( QUnit, wordCounter ) {
|
|
QUnit.module( 'word-count' );
|
|
|
|
QUnit.test( 'All.', function( assert ) {
|
|
_.each( [
|
|
{
|
|
message: 'Basic test.',
|
|
string: 'one two three',
|
|
words: 3,
|
|
characters: 11,
|
|
all: 13
|
|
},
|
|
{
|
|
message: 'HTML tags.',
|
|
string: 'one <em class="test">two</em><br />three',
|
|
words: 3,
|
|
characters: 11,
|
|
all: 12
|
|
},
|
|
{
|
|
message: 'Line breaks.',
|
|
string: 'one\ntwo\nthree',
|
|
words: 3,
|
|
characters: 11,
|
|
all: 11
|
|
},
|
|
{
|
|
message: 'Encoded spaces.',
|
|
string: 'one two three',
|
|
words: 3,
|
|
characters: 11,
|
|
all: 13
|
|
},
|
|
{
|
|
message: 'Punctuation.',
|
|
string: 'It\'s two three \u2026 4?',
|
|
words: 3,
|
|
characters: 15,
|
|
all: 19
|
|
},
|
|
{
|
|
message: 'Em dash.',
|
|
string: 'one\u2014two--three',
|
|
words: 3,
|
|
characters: 14,
|
|
all: 14
|
|
},
|
|
{
|
|
message: 'Shortcodes.',
|
|
string: 'one [shortcode attribute="value"]two[/shortcode]three',
|
|
words: 3,
|
|
characters: 11,
|
|
all: 12
|
|
},
|
|
{
|
|
message: 'Astrals.',
|
|
string: '\uD83D\uDCA9',
|
|
words: 1,
|
|
characters: 1,
|
|
all: 1
|
|
}
|
|
], function( test ) {
|
|
_.each( [ 'words', 'characters', 'all' ], function( type ) {
|
|
assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' );
|
|
} );
|
|
} );
|
|
} );
|
|
} )( window.QUnit, new window.wp.utils.WordCounter( {
|
|
l10n: {
|
|
shortcodes: [ 'shortcode' ]
|
|
}
|
|
} ) );
|