diff --git a/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.test.ts b/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.test.ts index 1d9575b..8b95fd9 100644 --- a/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.test.ts +++ b/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.test.ts @@ -1,5 +1,45 @@ -import { describe } from 'vitest'; +import { + describe, + expect, + it, +} from 'vitest'; +import type { ComparisonLine } from '../DualFontLayout/DualFontLayout'; +import { computeLineRenderModel } from './computeLineRenderModel'; + +/** + * Build a ComparisonLine fixture with given per-char widths. xA/xB are + * cumulative prefix sums of widthA/widthB respectively. + */ +function makeLine( + chars: { char: string; widthA: number; widthB: number }[], +): ComparisonLine { + let xA = 0; + let xB = 0; + const out: ComparisonLine = { + text: chars.map(c => c.char).join(''), + width: chars.reduce((s, c) => s + Math.max(c.widthA, c.widthB), 0), + chars: chars.map(c => { + const entry = { + char: c.char, + xA, + xB, + widthA: c.widthA, + widthB: c.widthB, + }; + xA += c.widthA; + xB += c.widthB; + return entry; + }), + }; + return out; +} describe('computeLineRenderModel', () => { - // tests added in subsequent tasks + it('returns empty model for an empty line', () => { + const line = makeLine([]); + const model = computeLineRenderModel(line, 50, 500, 5); + expect(model.leftText).toBe(''); + expect(model.windowChars).toEqual([]); + expect(model.rightText).toBe(''); + }); }); diff --git a/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.ts b/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.ts index b179382..aa31215 100644 --- a/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.ts +++ b/src/entities/Font/lib/dualFontLayout/computeLineRenderModel/computeLineRenderModel.ts @@ -41,5 +41,8 @@ export function computeLineRenderModel( containerWidth: number, windowSize: number, ): LineRenderModel { + if (line.chars.length === 0) { + return { leftText: '', windowChars: [], rightText: '' }; + } throw new Error('not implemented'); }