@@ -21,46 +21,41 @@ const {
2121// =============================================================================
2222
2323async function testBytesSyncBasic ( ) {
24- const source = fromSync ( 'hello' ) ;
25- const data = bytesSync ( source ) ;
24+ const data = bytesSync ( fromSync ( 'hello' ) ) ;
2625 assert . deepStrictEqual ( data , new TextEncoder ( ) . encode ( 'hello' ) ) ;
2726}
2827
2928async function testBytesSyncLimit ( ) {
30- const source = fromSync ( 'hello world' ) ;
3129 assert . throws (
32- ( ) => bytesSync ( source , { limit : 3 } ) ,
30+ ( ) => bytesSync ( fromSync ( 'hello world' ) , { limit : 3 } ) ,
3331 { name : 'RangeError' } ,
3432 ) ;
3533}
3634
3735async function testBytesAsync ( ) {
38- const source = from ( 'hello-async' ) ;
39- const data = await bytes ( source ) ;
36+ const data = await bytes ( from ( 'hello-async' ) ) ;
4037 assert . deepStrictEqual ( data , new TextEncoder ( ) . encode ( 'hello-async' ) ) ;
4138}
4239
4340async function testBytesAsyncLimit ( ) {
44- const source = from ( 'hello world' ) ;
4541 await assert . rejects (
46- ( ) => bytes ( source , { limit : 3 } ) ,
42+ ( ) => bytes ( from ( 'hello world' ) , { limit : 3 } ) ,
4743 { name : 'RangeError' } ,
4844 ) ;
4945}
5046
5147async function testBytesAsyncAbort ( ) {
5248 const ac = new AbortController ( ) ;
5349 ac . abort ( ) ;
54- const source = from ( 'data' ) ;
5550 await assert . rejects (
56- ( ) => bytes ( source , { signal : ac . signal } ) ,
57- ( err ) => err . name === 'AbortError' ,
51+ ( ) => bytes ( from ( 'data' ) , { signal : ac . signal } ) ,
52+ { name : 'AbortError' } ,
5853 ) ;
5954}
6055
6156async function testBytesEmpty ( ) {
62- const source = from ( [ ] ) ;
63- const data = await bytes ( source ) ;
57+ const data = await bytes ( from ( [ ] ) ) ;
58+ assert . ok ( data instanceof Uint8Array ) ;
6459 assert . strictEqual ( data . byteLength , 0 ) ;
6560}
6661
@@ -69,17 +64,15 @@ async function testBytesEmpty() {
6964// =============================================================================
7065
7166async function testArrayBufferSyncBasic ( ) {
72- const source = fromSync ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) ;
73- const ab = arrayBufferSync ( source ) ;
67+ const ab = arrayBufferSync ( fromSync ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) ) ;
7468 assert . ok ( ab instanceof ArrayBuffer ) ;
7569 assert . strictEqual ( ab . byteLength , 3 ) ;
7670 const view = new Uint8Array ( ab ) ;
7771 assert . deepStrictEqual ( view , new Uint8Array ( [ 1 , 2 , 3 ] ) ) ;
7872}
7973
8074async function testArrayBufferAsync ( ) {
81- const source = from ( new Uint8Array ( [ 10 , 20 , 30 ] ) ) ;
82- const ab = await arrayBuffer ( source ) ;
75+ const ab = await arrayBuffer ( from ( new Uint8Array ( [ 10 , 20 , 30 ] ) ) ) ;
8376 assert . ok ( ab instanceof ArrayBuffer ) ;
8477 assert . strictEqual ( ab . byteLength , 3 ) ;
8578 const view = new Uint8Array ( ab ) ;
@@ -96,8 +89,7 @@ async function testArraySyncBasic() {
9689 yield new Uint8Array ( [ 2 ] ) ;
9790 yield new Uint8Array ( [ 3 ] ) ;
9891 }
99- const source = fromSync ( gen ( ) ) ;
100- const chunks = arraySync ( source ) ;
92+ const chunks = arraySync ( fromSync ( gen ( ) ) ) ;
10193 assert . strictEqual ( chunks . length , 3 ) ;
10294 assert . deepStrictEqual ( chunks [ 0 ] , new Uint8Array ( [ 1 ] ) ) ;
10395 assert . deepStrictEqual ( chunks [ 1 ] , new Uint8Array ( [ 2 ] ) ) ;
0 commit comments