@@ -43,16 +43,32 @@ describe('rowset', () => {
43
43
expect ( Array . isArray ( rowset ) ) . toBeTruthy ( )
44
44
expect ( rowset ) . toHaveLength ( 50 )
45
45
46
+ // slice with correct bounds
46
47
const sliced = rowset . slice ( 10 , 20 )
47
48
expect ( sliced ) . toHaveLength ( 10 )
48
49
expect ( sliced [ 0 ] ) . toMatchObject ( rowset [ 10 ] )
49
50
50
- // slice more than actually exists!
51
+ // slice with end larger than length
51
52
const largerSlice = rowset . slice ( 10 , 100 )
52
53
expect ( largerSlice ) . toHaveLength ( 40 )
53
54
expect ( largerSlice [ 0 ] ) . toMatchObject ( rowset [ 10 ] )
54
55
expect ( largerSlice [ 39 ] ) . toMatchObject ( rowset [ 49 ] )
55
56
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
+
56
72
connection . close ( )
57
73
done ( )
58
74
} )
0 commit comments