test(ci): add exporter heading levels and a11y typography smoke; update MAIN_PLAN
CI / test (pull_request) Has been cancelled
CI / test (pull_request) Has been cancelled
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { move } from './reorder'
|
||||
|
||||
describe('reorder.move', () => {
|
||||
it('같은 배열 인스턴스를 변형하지 않고 from→to로 아이템을 이동한다', () => {
|
||||
const src = ['a', 'b', 'c', 'd']
|
||||
const out = move(src, 1, 3)
|
||||
expect(src).toEqual(['a', 'b', 'c', 'd'])
|
||||
expect(out).toEqual(['a', 'c', 'd', 'b'])
|
||||
})
|
||||
|
||||
it('경계 밖 인덱스는 원본을 그대로 반환한다', () => {
|
||||
const src = ['x', 'y']
|
||||
expect(move(src, -1, 1)).toBe(src)
|
||||
expect(move(src, 0, 5)).toBe(src)
|
||||
expect(move(src, 2, 0)).toBe(src)
|
||||
})
|
||||
|
||||
it('from과 to가 같으면 원본을 그대로 반환한다', () => {
|
||||
const src = [1, 2, 3]
|
||||
expect(move(src, 1, 1)).toBe(src)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,15 @@
|
||||
export function move<T>(arr: T[], from: number, to: number): T[] {
|
||||
if (
|
||||
from === to ||
|
||||
from < 0 ||
|
||||
to < 0 ||
|
||||
from >= arr.length ||
|
||||
to >= arr.length
|
||||
) {
|
||||
return arr
|
||||
}
|
||||
const next = arr.slice()
|
||||
const [sp] = next.splice(from, 1)
|
||||
next.splice(to, 0, sp)
|
||||
return next
|
||||
}
|
||||
Reference in New Issue
Block a user