Refactor/reacrhitecture to fsd+ #49

Merged
ilia merged 70 commits from refactor/reacrhitecture-to-fsd+ into main 2026-06-03 09:55:47 +00:00
2 changed files with 45 additions and 2 deletions
Showing only changes of commit efbc464b14 - Show all commits
@@ -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', () => { 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('');
});
}); });
@@ -41,5 +41,8 @@ export function computeLineRenderModel(
containerWidth: number, containerWidth: number,
windowSize: number, windowSize: number,
): LineRenderModel { ): LineRenderModel {
if (line.chars.length === 0) {
return { leftText: '', windowChars: [], rightText: '' };
}
throw new Error('not implemented'); throw new Error('not implemented');
} }