Changeset 33290
- Timestamp:
- 07/15/2015 11:47:02 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/word-count.js
r32856 r33290 18 18 wordsRegExp: /\S\s+/g, 19 19 charactersRegExp: /\S/g, 20 allRegExp: /[^\f\n\r\t\v\u00ad\u2028\u2029]/g, 20 21 l10n: window.wordCountL10n || {} 21 22 }; … … 27 28 28 29 if ( text ) { 29 text = ' ' + text + '';30 text = text + '\n'; 30 31 31 text = text.replace( this.settings.HTMLRegExp, ' 32 text = text.replace( this.settings.HTMLRegExp, '\n' ); 32 33 text = text.replace( this.settings.spaceRegExp, ' ' ); 33 34 text = text.replace( this.settings.removeRegExp, '' ); -
trunk/tests/qunit/wp-admin/js/word-count.js
r32856 r33290 1 ( function( QUnit ) { 2 var wordCounter = new window.wp.utils.WordCounter(); 3 1 ( function( QUnit, wordCounter ) { 4 2 QUnit.module( 'word-count' ); 5 3 6 4 QUnit.test( 'All.', function( assert ) { 7 var tests =[5 _.each( [ 8 6 { 9 7 message: 'Basic test.', 10 8 string: 'one two three', 11 wordCount: 3, 12 charCount: 11 9 words: 3, 10 characters: 11, 11 all: 13 13 12 }, 14 13 { 15 14 message: 'HTML tags.', 16 15 string: 'one <em class="test">two</em><br />three', 17 wordCount: 3, 18 charCount: 11 16 words: 3, 17 characters: 11, 18 all: 12 19 19 }, 20 20 { 21 21 message: 'Line breaks.', 22 22 string: 'one\ntwo\nthree', 23 wordCount: 3, 24 charCount: 11 23 words: 3, 24 characters: 11, 25 all: 11 25 26 }, 26 27 { 27 28 message: 'Encoded spaces.', 28 29 string: 'one two three', 29 wordCount: 3, 30 charCount: 11 30 words: 3, 31 characters: 11, 32 all: 13 31 33 }, 32 34 { 33 35 message: 'Punctuation.', 34 36 string: 'It\'s two three... 4?', 35 wordCount: 3, 36 charCount: 11 37 words: 3, 38 characters: 11, 39 all: 14 37 40 } 38 ]; 39 40 var i = tests.length; 41 42 while ( i-- ) { 43 assert.equal( wordCounter.count( tests[ i ].string ), tests[ i ].wordCount, tests[ i ].message + ' (words)' ); 44 assert.equal( wordCounter.count( tests[ i ].string, 'characters' ), tests[ i ].charCount, tests[ i ].message + ' (characters)' ); 45 } 41 ], function( test ) { 42 _.each( [ 'words', 'characters', 'all' ], function( type ) { 43 assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' ); 44 } ); 45 } ); 46 46 } ); 47 } )( window.QUnit );47 } )( window.QUnit, new window.wp.utils.WordCounter() );
Note: See TracChangeset
for help on using the changeset viewer.