Files
genoffice/apps/docs/tests/print-range.test.ts
T
ANIRUDDHA ADAKandAniruddha Adak af9a63e462 fix(print-range): accept em-dash, tilde and fullwidth dash variants (#356)
* fix(print-range): accept em-dash, tilde and fullwidth dash variants

* fix(sheets): satisfy exactOptionalPropertyTypes for LazyCellMatch rawValue

---------

Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
2026-09-14 10:55:34 +08:00

39 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest'
import { parsePrintRange } from '../src/renderer/print-range'
describe('parsePrintRange', () => {
it('parses single pages and ranges into 0-based indices', () => {
expect(parsePrintRange('1,3,5-8', 10)).toEqual([0, 2, 4, 5, 6, 7])
})
it('dedupes overlaps and sorts', () => {
expect(parsePrintRange('5-6, 2, 5', 10)).toEqual([1, 4, 5])
})
it('accepts CJK separators and en-dash', () => {
expect(parsePrintRange('1,3、5–6', 6)).toEqual([0, 2, 4, 5])
})
it('accepts spaces around dashes', () => {
expect(parsePrintRange('1 - 3', 5)).toEqual([0, 1, 2])
expect(parsePrintRange('1 – 3, 5', 5)).toEqual([0, 1, 2, 4])
})
it('accepts em-dash, tilde, fullwidth tilde and wave dash (IME variants)', () => {
expect(parsePrintRange('1—3', 5)).toEqual([0, 1, 2])
expect(parsePrintRange('1~3', 5)).toEqual([0, 1, 2])
expect(parsePrintRange('1~3', 5)).toEqual([0, 1, 2])
expect(parsePrintRange('1〜3', 5)).toEqual([0, 1, 2])
expect(parsePrintRange('1 — 3, 5~6', 6)).toEqual([0, 1, 2, 4, 5])
})
it('rejects empty, malformed, reversed, and out-of-bounds input', () => {
expect(parsePrintRange('', 5)).toBeNull()
expect(parsePrintRange('a-b', 5)).toBeNull()
expect(parsePrintRange('4-2', 5)).toBeNull()
expect(parsePrintRange('0', 5)).toBeNull()
expect(parsePrintRange('6', 5)).toBeNull()
expect(parsePrintRange('1-9', 5)).toBeNull()
})
})