@@ -467,19 +467,25 @@ describe('byte.test.js', function () {
467467 assert ( bytes . getRawString ( 0 , 11 ) === 'hello world' ) ;
468468 assert ( bytes . getRawStringByStringLength ( 0 , 11 ) === 'hello world' ) ;
469469 bytes . position ( 0 ) ;
470+ assert ( bytes . getRawStringFast ( 11 ) === 'hello world' ) ;
471+ bytes . position ( 0 ) ;
472+ assert ( bytes . getUTFString ( 11 ) === 'hello world' ) ;
473+ bytes . position ( 0 ) ;
470474 assert ( bytes . getRawString ( ) === 'h' ) ;
471475
472476 bytes = ByteBuffer . allocate ( 1 ) ;
473477 bytes . putRawString ( '你好' ) ;
474478 assert ( bytes . toString ( ) === '<ByteBuffer e4 bd a0 e5 a5 bd>' ) ;
475479 assert ( bytes . position ( 0 ) . readRawString ( 6 ) === '你好' ) ;
476480 assert ( bytes . position ( 0 ) . getRawString ( 0 , 6 ) === '你好' ) ;
481+ assert ( bytes . position ( 0 ) . getRawStringFast ( 2 ) === '你好' ) ;
477482 assert ( bytes . position ( 0 ) . getRawStringByStringLength ( 2 ) === '你好' ) ;
478483 bytes . putRawString ( 0 , '我们' ) ;
479484 assert ( bytes . toString ( ) === '<ByteBuffer e6 88 91 e4 bb ac>' ) ;
480485 assert ( bytes . getRawString ( 0 , 6 ) === '我们' ) ;
481486 assert ( bytes . getRawStringByStringLength ( 0 , 2 ) === '我们' ) ;
482487 assert ( bytes . readRawString ( 0 , 6 ) === '我们' ) ;
488+ assert ( bytes . position ( 0 ) . getRawStringFast ( 2 ) === '我们' ) ;
483489
484490 bytes = ByteBuffer . allocate ( 1 ) ;
485491 bytes . putRawString ( '' ) ;
@@ -637,13 +643,15 @@ describe('byte.test.js', function () {
637643 assert ( bytes . toString ( ) === '<ByteBuffer 68 65 6c 6c 6f e9 a6 83 e5 b0 b2>' ) ;
638644 assert . deepEqual ( bytes . getRawString ( 0 , 11 ) , str ) ;
639645 assert . deepEqual ( bytes . getRawStringByStringLength ( 0 , 7 ) , str ) ;
646+ assert . deepEqual ( bytes . position ( 0 ) . getRawStringFast ( 7 ) , str ) ;
640647 // gbk
641648 var bytes = ByteBuffer . allocate ( 1 ) ;
642649 var str = 'hello\ud83c\udf3c' ;
643650 bytes . putRawString ( str ) ;
644651 assert ( bytes . toString ( ) === '<ByteBuffer 68 65 6c 6c 6f ed a0 bc ed bc bc>' ) ;
645652 assert . deepEqual ( bytes . getRawString ( 0 , 11 ) , str ) ;
646653 assert . deepEqual ( bytes . getRawStringByStringLength ( 0 , 7 ) , str ) ;
654+ assert . deepEqual ( bytes . position ( 0 ) . getRawStringFast ( 7 ) , str ) ;
647655
648656 var bytes = ByteBuffer . allocate ( 1 ) ;
649657 // java encode bytes: [-19, -96, -67, -19, -72, -128, 87, 119, 119, -23, -126, -93]
@@ -652,6 +660,7 @@ describe('byte.test.js', function () {
652660 assert ( bytes . toString ( ) === '<ByteBuffer ed a0 bd ed b8 80 57 77 77 e9 82 a3>' ) ;
653661 assert . deepEqual ( bytes . getRawString ( 0 , 12 ) , str ) ;
654662 assert . deepEqual ( bytes . getRawStringByStringLength ( 0 , 6 ) , str ) ;
663+ assert . deepEqual ( bytes . position ( 0 ) . getRawStringFast ( 6 ) , str ) ;
655664
656665 // Construction of a special test case which triggers the bug
657666 // of allocating insufficient space via _checkSize
@@ -662,6 +671,17 @@ describe('byte.test.js', function () {
662671 } ) ;
663672 } ) ;
664673
674+ describe ( 'putUTFString/getUTFString' , function ( ) {
675+ it ( 'should put & get utf string ok' , function ( ) {
676+ var bytes = ByteBuffer . allocate ( 1 ) ;
677+ var str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234' ;
678+ bytes . putUTFString ( str ) ;
679+ bytes . flip ( ) ;
680+ var output = bytes . getUTFString ( bytes . limit ( ) ) ;
681+ assert ( output === str ) ;
682+ } ) ;
683+ } ) ;
684+
665685 describe ( 'array(), copy()' , function ( ) {
666686 it ( 'should copy(start)' , function ( ) {
667687 var bytes = ByteBuffer . allocate ( 8 ) ;
@@ -782,8 +802,13 @@ describe('byte.test.js', function () {
782802 bytes . position ( 0 ) ;
783803 assert ( str === bytes . getRawStringByStringLength ( 0 , str . length ) ) ;
784804 assert ( bytes . position ( ) === 0 ) ;
805+ assert ( str === bytes . getRawStringFast ( str . length ) ) ;
806+ bytes . position ( 0 ) ;
785807 assert ( str === bytes . getRawStringByStringLength ( str . length ) ) ;
786808 assert ( bytes . position ( ) === pos ) ;
809+ bytes . position ( 0 ) ;
810+ assert ( str === bytes . getRawStringFast ( str . length ) ) ;
811+ assert ( bytes . position ( ) === pos ) ;
787812 } ) ;
788813
789814 it ( 'should throw if encode error' , function ( ) {
@@ -794,6 +819,10 @@ describe('byte.test.js', function () {
794819 assert . throws ( function ( ) {
795820 bytes . getRawStringByStringLength ( 0 , str . length + 1 ) ;
796821 } , 'string is not valid UTF-8 encode' ) ;
822+ assert . throws ( function ( ) {
823+ bytes . position ( 0 )
824+ bytes . getRawStringFast ( str . length + 1 ) ;
825+ } , 'string is not valid UTF-8 encode' ) ;
797826 } ) ;
798827 } ) ;
799828} ) ;
0 commit comments