2026-05-30 21:49:25 +03:00
|
|
|
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;
|
|
|
|
|
}
|
2026-05-30 21:48:56 +03:00
|
|
|
|
|
|
|
|
describe('computeLineRenderModel', () => {
|
2026-05-30 21:49:25 +03:00
|
|
|
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('');
|
|
|
|
|
});
|
2026-05-30 21:48:56 +03:00
|
|
|
});
|