@@ -41,6 +41,44 @@ test('scanBgzfBlocks on T_ko.2bit.gz', () => {
4141 expect ( totalDecompressed ) . toBeGreaterThan ( 0 )
4242} )
4343
44+ test ( 'scanBgzfBlocks returns empty for empty input' , ( ) => {
45+ const blocks = scanBgzfBlocks ( new Uint8Array ( 0 ) , 0 , 0 )
46+ expect ( blocks ) . toEqual ( [ ] )
47+ } )
48+
49+ test ( 'scanBgzfBlocks returns empty for input shorter than min block size' , ( ) => {
50+ const blocks = scanBgzfBlocks ( new Uint8Array ( 25 ) , 0 , 100 )
51+ expect ( blocks ) . toEqual ( [ ] )
52+ } )
53+
54+ test ( 'scanBgzfBlocks stops on truncated block' , ( ) => {
55+ const testData = fs . readFileSync ( require . resolve ( './data/paired.bam' ) )
56+ const allBlocks = scanBgzfBlocks ( testData , 0 , testData . length )
57+ const firstBlockSize = allBlocks [ 0 ] ! . compressedSize
58+
59+ // truncate in the middle of the second block
60+ const truncated = testData . subarray ( 0 , firstBlockSize + 10 )
61+ const blocks = scanBgzfBlocks ( truncated , 0 , truncated . length )
62+ expect ( blocks . length ) . toBe ( 1 )
63+ expect ( blocks [ 0 ] ! . compressedSize ) . toBe ( firstBlockSize )
64+ } )
65+
66+ test ( 'scanBgzfBlocks stops on non-bgzf data' , ( ) => {
67+ const blocks = scanBgzfBlocks ( new Uint8Array ( 1000 ) , 0 , 1000 )
68+ expect ( blocks ) . toEqual ( [ ] )
69+ } )
70+
71+ test ( 'scanBgzfBlocks includes block at maxBlockPosition' , ( ) => {
72+ const testData = fs . readFileSync ( require . resolve ( './data/paired.bam' ) )
73+ const allBlocks = scanBgzfBlocks ( testData , 0 , testData . length )
74+ // set maxBlockPosition to exactly the second block's position
75+ const secondBlockPos = allBlocks [ 1 ] ! . filePosition
76+ const blocks = scanBgzfBlocks ( testData , 0 , secondBlockPos )
77+ // should include the block at maxBlockPosition (inclusive)
78+ expect ( blocks . length ) . toBe ( 2 )
79+ expect ( blocks [ 1 ] ! . filePosition ) . toBe ( secondBlockPos )
80+ } )
81+
4482test ( 'scanBgzfBlocks with large filePosition offset' , ( ) => {
4583 const testData = fs . readFileSync ( require . resolve ( './data/paired.bam' ) )
4684 const startPos = 5_000_000_000_000
0 commit comments