|
| 1 | +import { move } from '../../src'; |
| 2 | + |
| 3 | +describe('Array > move', () => { |
| 4 | + test('empty array', () => { |
| 5 | + expect(move([], 0, 1)).toEqual([]); |
| 6 | + }); |
| 7 | + |
| 8 | + it('returns same ref', () => { |
| 9 | + const arr = [1, 5, 8]; |
| 10 | + expect(move(arr, 0, 0)).toBe(arr); |
| 11 | + }); |
| 12 | + |
| 13 | + it('moves within range', () => { |
| 14 | + expect(move([1, 2, 3], 0, 2)).toEqual([2, 3, 1]); |
| 15 | + }); |
| 16 | + |
| 17 | + it('moves the element to the last index if to > length', () => { |
| 18 | + expect(move([1, 2, 3], 0, 5)).toEqual([2, 3, 1]); |
| 19 | + }); |
| 20 | + |
| 21 | + it('does not move the element', () => { |
| 22 | + expect(move([1, 2, 3], 5, 0)).toEqual([1, 2, 3]); |
| 23 | + }); |
| 24 | + |
| 25 | + test('negative index', () => { |
| 26 | + expect(move([1, 2, 3, 4, 5], 0, -1)).toEqual([2, 3, 4, 1, 5]); |
| 27 | + expect(move([1, 2, 3, 4, 5], -1, 2)).toEqual([1, 2, 5, 3, 4]); |
| 28 | + }); |
| 29 | +}); |
0 commit comments