fix(ListWrapper): make list slice in dart return empty list if start and end are inverted like JS
This commit is contained in:
parent
105db02e07
commit
bced3aaa17
@ -182,6 +182,10 @@ class ListWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static List slice(List l, [int from = 0, int to]) {
|
static List slice(List l, [int from = 0, int to]) {
|
||||||
|
//in JS if from > to an empty array is returned
|
||||||
|
if(to != null && from > to) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
return l.sublist(_startOffset(l, from), _endOffset(l, to));
|
return l.sublist(_startOffset(l, from), _endOffset(l, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,9 @@ export function main() {
|
|||||||
|
|
||||||
it('should support negative end',
|
it('should support negative end',
|
||||||
() => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); });
|
() => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); });
|
||||||
|
|
||||||
|
it('should return empty list if start is greater than end',
|
||||||
|
() => { expect(ListWrapper.slice(l, 4, 2)).toEqual([]); });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('indexOf', () => {
|
describe('indexOf', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user