@@ -761,23 +761,38 @@ suite(`Filesystem - ${memoryQualifier}`, () => {
761761 test ( 'fd_write - multiple ciovec' , ( ) => {
762762 const memory = createMemory ( ) ;
763763 const filename = `/tmp/${ uuid . v4 ( ) } ` ;
764- const hw = [ 'Hello ' , 'World ' , '!!!' ] ;
764+ const hw1 = [ 'Hello ' , 'World ' , '!!!' ] ;
765+ const hw2 = [ 'Hello ' , 'World ' , ', again' , '!!!' ] ;
765766 const fd = FileSystem . createFile ( memory , rootFd , filename ) ;
766- const ciovecs = memory . allocStructArray ( 3 , Ciovec ) ;
767- let contentLength : number = 0 ;
768- for ( let i = 0 ; i < hw . length ; i ++ ) {
769- const content = memory . allocBytes ( encoder . encode ( hw [ i ] ) ) ;
770- ciovecs . get ( i ) . buf = content . $ptr ;
771- ciovecs . get ( i ) . buf_len = content . byteLength ;
772- contentLength += content . byteLength ;
767+ const ciovecs1 = memory . allocStructArray ( 3 , Ciovec ) ;
768+ let contentLength1 : number = 0 ;
769+ for ( let i = 0 ; i < hw1 . length ; i ++ ) {
770+ const content = memory . allocBytes ( encoder . encode ( hw1 [ i ] ) ) ;
771+ ciovecs1 . get ( i ) . buf = content . $ptr ;
772+ ciovecs1 . get ( i ) . buf_len = content . byteLength ;
773+ contentLength1 += content . byteLength ;
773774 }
775+ const ciovecs2 = memory . allocStructArray ( 4 , Ciovec ) ;
776+ let contentLength2 : number = 0 ;
777+ for ( let i = 0 ; i < hw2 . length ; i ++ ) {
778+ const content = memory . allocBytes ( encoder . encode ( hw2 [ i ] ) ) ;
779+ ciovecs2 . get ( i ) . buf = content . $ptr ;
780+ ciovecs2 . get ( i ) . buf_len = content . byteLength ;
781+ contentLength2 += content . byteLength ;
782+ }
783+
774784 const bytesWritten = memory . allocUint32 ( ) ;
775- let errno = wasi . fd_write ( fd , ciovecs . $ptr , ciovecs . size , bytesWritten . $ptr ) ;
785+ let errno1 = wasi . fd_write ( fd , ciovecs1 . $ptr , ciovecs1 . size , bytesWritten . $ptr ) ;
786+ assert . strictEqual ( errno1 , Errno . success ) ;
787+ assert . strictEqual ( bytesWritten . value , contentLength1 ) ;
788+
789+ let errno2 = wasi . fd_write ( fd , ciovecs2 . $ptr , ciovecs2 . size , bytesWritten . $ptr ) ;
790+ assert . strictEqual ( errno2 , Errno . success ) ;
791+ assert . strictEqual ( bytesWritten . value , contentLength2 ) ;
776792 FileSystem . close ( fd ) ;
793+
777794 const check = FileSystem . openFile ( memory , rootFd , filename ) ;
778- assert . strictEqual ( errno , Errno . success ) ;
779- assert . strictEqual ( bytesWritten . value , contentLength ) ;
780- assert . strictEqual ( decoder . decode ( FileSystem . read ( memory , check ) ) , hw . join ( '' ) ) ;
795+ assert . strictEqual ( decoder . decode ( FileSystem . read ( memory , check ) ) , hw1 . join ( '' ) + hw2 . join ( '' ) ) ;
781796 FileSystem . close ( check ) ;
782797 } ) ;
783798
0 commit comments