import { writeString , readString } from '../src/string' ; describe ( 'string' , ( ) => { describe ( 'writer' , ( ) => { it ( 'should encode string' , ( ) => { const message = Buffer . from ( 'my-string' , 'utf8' ) ; const lengthInBuffer = Buffer . from ( [ message . length ] ) ; const data = Buffer . concat ( [ lengthInBuffer , message ] ) ; expect ( writeString ( 'my-string' ) ) . toEqual ( data ) ; } ) ; it ( 'should encode empty string' , ( ) => { const message = Buffer . from ( '' , 'utf8' ) ; const lengthInBuffer = Buffer . from ( [ message . length ] ) ; const data = Buffer . concat ( [ lengthInBuffer , message ] ) ; expect ( writeString ( '' ) ) . toEqual ( data ) ; } ) ; } ) ; describe ( 'reader' , ( ) => { it ( 'should decode string' , ( ) => { const message = Buffer . from ( 'my-string' , 'utf8' ) ; const lengthInBuffer = Buffer . from ( [ message . length ] ) ; const data = Buffer . concat ( [ lengthInBuffer , message ] ) ; expect ( readString ( data , 0 ) ) . toEqual ( [ 'my-string' , message . length + 1 ] ) ; } ) ; it ( 'should decode empty string' , ( ) => { const message = Buffer . from ( '' , 'utf8' ) ; const lengthInBuffer = Buffer . from ( [ message . length ] ) ; const data = Buffer . concat ( [ lengthInBuffer , message ] ) ; expect ( readString ( data , 0 ) ) . toEqual ( [ '' , message . length + 1 ] ) ; } ) ; } ) ; } ) ;