@@ -43,16 +43,32 @@ describe('rowset', () => {
4343 expect ( Array . isArray ( rowset ) ) . toBeTruthy ( )
4444 expect ( rowset ) . toHaveLength ( 50 )
4545
46+ // slice with correct bounds
4647 const sliced = rowset . slice ( 10 , 20 )
4748 expect ( sliced ) . toHaveLength ( 10 )
4849 expect ( sliced [ 0 ] ) . toMatchObject ( rowset [ 10 ] )
4950
50- // slice more than actually exists!
51+ // slice with end larger than length
5152 const largerSlice = rowset . slice ( 10 , 100 )
5253 expect ( largerSlice ) . toHaveLength ( 40 )
5354 expect ( largerSlice [ 0 ] ) . toMatchObject ( rowset [ 10 ] )
5455 expect ( largerSlice [ 39 ] ) . toMatchObject ( rowset [ 49 ] )
5556
57+ // slice last 3 elements
58+ const negativeStartSlice = rowset . slice ( - 3 )
59+ expect ( negativeStartSlice ) . toHaveLength ( 3 )
60+ expect ( negativeStartSlice [ 0 ] ) . toMatchObject ( rowset [ rowset . length - 3 ] )
61+
62+ // slice first 3 elements
63+ const negativeEndSlice = rowset . slice ( 0 , - 3 )
64+ expect ( negativeEndSlice ) . toHaveLength ( rowset . length - 3 )
65+ expect ( negativeEndSlice [ 0 ] ) . toMatchObject ( rowset [ 0 ] )
66+ expect ( negativeEndSlice [ negativeEndSlice . length - 1 ] ) . toMatchObject ( rowset [ rowset . length - 4 ] )
67+
68+ // slice to empty set
69+ const emptySlice = rowset . slice ( 20 , 10 )
70+ expect ( emptySlice ) . toHaveLength ( 0 )
71+
5672 connection . close ( )
5773 done ( )
5874 } )
0 commit comments