Something went wrong. Try again.
The Serifu editor
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159import { describe, expect, it } from 'vitest';import { buildScriptDoc, type ScriptLine, type TextLine } from './scriptDoc';
/** Every line in the document, flattened — most assertions don't care where. */const allLines = (text: string): ScriptLine[] => buildScriptDoc(text).pages.flatMap((p) => p.panels.flatMap((panel) => panel.lines));
/** The n-th line, typed as a dialogue line. */function textLine(text: string, n = 0): TextLine { const line = allLines(text)[n]; if (line.kind !== 'text') throw new Error(`line ${n} is a ${line.kind}, not a text line`); return line;}
/** The single run list of a plain (non-style-block) dialogue line. */const runsOf = (source: string, n = 0) => textLine(source, n).lines[0];
describe('structure', () => { it('numbers pages and panels, resetting panels on each page', () => { const doc = buildScriptDoc('# \n- \n- \n# \n- \n'); expect(doc.pages.map((p) => p.number)).toEqual([1, 2]); expect(doc.pages.map((p) => p.panels.map((panel) => panel.number))).toEqual([[1, 2], [1]]); });
it('counts a spread as two pages', () => { const doc = buildScriptDoc('# \n- \n## \n- \n# \n- \n'); expect(doc.pages.map((p) => ({ number: p.number, spread: p.spread }))).toEqual([ { number: 1, spread: false }, { number: 2, spread: true }, { number: 4, spread: false }, ]); });
it('keeps empty panels, so panel numbering stays aligned with the art', () => { const doc = buildScriptDoc('# \n- \n- \nTANAKA: hi\n'); expect(doc.pages[0].panels).toHaveLength(2); expect(doc.pages[0].panels[0].lines).toEqual([]); expect(doc.pages[0].panels[1].lines).toHaveLength(1); });});
describe('attribution carryover', () => { it('carries the origin to lines that omit one', () => { const lines = ['# ', '- ', 'TANAKA: first', ': second', '- ', ': third'].join('\n'); expect([0, 1, 2].map((n) => textLine(lines, n).origin)).toEqual(['TANAKA', 'TANAKA', 'TANAKA']); });
it('marks which lines named their own origin', () => { const lines = '# \n- \nTANAKA: first\n: second\n'; expect([0, 1].map((n) => textLine(lines, n).explicitOrigin)).toEqual([true, false]); });
it('carries the style until a new origin ends its run', () => { const lines = ['# ', '- ', 'TANAKA/loud: a', ': b', 'YUKI: c'].join('\n'); expect([0, 1, 2].map((n) => textLine(lines, n).style)).toEqual(['loud', 'loud', '']); });
it('keeps the carried origin when a line names only a style', () => { const line = textLine('# \n- \nTANAKA: a\n/loud: b\n', 1); expect(line).toMatchObject({ origin: 'TANAKA', style: 'loud', explicitOrigin: false }); });
it('carries attribution across panel and page boundaries', () => { const lines = '# \n- \nTANAKA/loud: a\n# \n- \n: b\n'; expect(textLine(lines, 1)).toMatchObject({ origin: 'TANAKA', style: 'loud' }); });});
describe('content runs', () => { it('unwraps emphasis markers', () => { expect(runsOf('# \n- \nA: plain *bold* _ital_ **both**\n')).toEqual([ { text: 'plain ' }, { text: 'bold', bold: true }, { text: ' ' }, { text: 'ital', italic: true }, { text: ' ' }, { text: 'both', bold: true, italic: true }, ]); });
it('unwraps a block-text span as verbatim text', () => { expect(runsOf('# \n- \nA: /=no *markup* here=/\n')).toEqual([{ text: 'no *markup* here' }]); });
it('keeps unpaired punctuation as literal text', () => { expect(runsOf('# \n- \nA: 3 * 4: yes\n').map((r) => r.text).join('')).toBe('3 * 4: yes'); });
it('gives an empty translation one empty line rather than none', () => { const line = textLine('# \n- \nTANAKA: \n'); expect(line.lines).toEqual([[]]); expect(line.styleBlock).toBe(false); });
it('splits a style block into one line per hand-break', () => { const line = textLine('# \n- \nA: ===\nfirst\n*second*\n===\n'); expect(line.styleBlock).toBe(true); expect(line.lines).toEqual([[{ text: 'first' }], [{ text: 'second', bold: true }]]); });});
describe('non-dialogue lines', () => { it('reads a note without its exclamation point', () => { expect(allLines('# \n- \n! check the honorific here\n')).toEqual([ { kind: 'note', text: 'check the honorific here' }, ]); });
it('reads an sfx line, unwrapping the source sound from its parens', () => { expect(allLines('# \n- \n*KRAK (バキ)\n')).toEqual([ { kind: 'sfx', translation: 'KRAK', origin: 'バキ' }, ]); });
it('reads an sfx line with no source sound', () => { expect(allLines('# \n- \n*KRAK\n')).toEqual([{ kind: 'sfx', translation: 'KRAK', origin: null }]); });
it('keeps an SFX awaiting its sound, and an empty note, in the model', () => { // Dropping them here made this model disagree with Find and pairing about // what the script contains: no SFX in Document Info while Find's kind // filter counted one, and the corpus handing the `@` under it to whoever // spoke before. Whether a publisher sees them is the formats' call. expect(allLines('# \n- \n*\n!\n*(ドン)\n')).toEqual([ { kind: 'sfx', translation: '', origin: null }, { kind: 'note', text: '' }, { kind: 'sfx', translation: '', origin: 'ドン' }, ]); });
it('a bare * in the house indentation keeps the lines after it', () => { // The old grammar read `\t\t@ ドン` as the SFX's sound — an SFX reading // "@ ドン" in the deliverable, and the dialogue after it gone too. expect(allLines('# \n\t- \n\t\t*\n\t\t@ ドン\n\t\tKEN: hi\n').map((l) => l.kind)).toEqual([ 'sfx', 'source', 'text', ]); });
it('reads a source line without its at-sign', () => { expect(allLines('# \n- \nTL: \n@ 許さない!\n')[1]).toEqual({ kind: 'source', text: '許さない!', }); });});
describe('leading blank lines (the phantom-page regression)', () => { it('numbers the first page 1 with blank lines before the page token', () => { // Recovery used to mint a phantom Page from two leading newlines, // shifting every page number — and with it every publisher export's // numbering — by one. const doc = buildScriptDoc('\n\n# PAGE 1\nText here\n- \nA: hi\n'); expect(doc.pages.map((p) => p.number)).toEqual([1]); expect(doc.pages[0].panels[0].lines).toHaveLength(1); });});