11
22var utf8 = require ( '../../build/node/internal/utf8' ) ;
3+ var buffers = require ( '../../build/node/internal/buf' ) ;
34
45describe ( 'utf8' , function ( ) {
56 it ( 'should have a nice clean buffer position after serializing' , function ( ) {
@@ -14,6 +15,40 @@ describe('utf8', function() {
1415 expect ( packAndUnpack ( "" ) ) . toBe ( "" ) ;
1516 expect ( packAndUnpack ( "åäö123" ) ) . toBe ( "åäö123" ) ;
1617 } ) ;
18+
19+ it ( 'should read/write utf8 from a complete combined buffer' , function ( ) {
20+ // Given
21+ var msg = "asåfqwer" ;
22+ var buf = utf8 . encode ( msg ) ;
23+ var bufa = buf . readSlice ( 3 ) ;
24+ var bufb = buf . readSlice ( 3 ) ;
25+ var bufc = buf . readSlice ( 3 ) ;
26+ var combined = new buffers . CombinedBuffer ( [ bufa , bufb , bufc ] ) ;
27+
28+ // When
29+ var decoded = utf8 . decode ( combined , combined . length ) ;
30+
31+ // Then
32+ expect ( decoded ) . toBe ( msg ) ;
33+ } ) ;
34+
35+ it ( 'should read/write utf8 from part of a combined buffer' , function ( ) {
36+ // Given
37+ var msg = "asåfq" ;
38+ var expectMsg = msg . substring ( 0 , msg . length - 1 ) ;
39+ var buf = utf8 . encode ( msg ) ;
40+ var bufa = buf . readSlice ( 3 ) ;
41+ var bufb = buf . readSlice ( 3 ) ;
42+ var unrelatedData = buffers . alloc ( 3 ) ;
43+ var combined = new buffers . CombinedBuffer ( [ bufa , bufb , unrelatedData ] ) ;
44+
45+ // When
46+ // We read all but the unrelatedData and the last character of bufb
47+ var decoded = utf8 . decode ( combined , combined . length - 1 - unrelatedData . length ) ;
48+
49+ // Then
50+ expect ( decoded ) . toBe ( expectMsg ) ;
51+ } ) ;
1752} ) ;
1853
1954function packAndUnpack ( str ) {
0 commit comments