93 lines
3.1 KiB
JavaScript
93 lines
3.1 KiB
JavaScript
// Generated, do not edit. sha256:6af32d0d87cfc79565a819efa4f1b1242dc24918bed60c964dcd7e25b4033b27
|
|||
|
|
import { describe, it } from 'node:test';
|
||
|
|
import assert from 'node:assert/strict';
|
||
|
|
|
||
|
|
import { limitRows, limitedList, limitText, omittedNote } from '../../server/ai/limits.js';
|
||
|
|
import { CONFIG } from '../../shared/config.js';
|
||
|
|
|
||
|
|
const MAX = CONFIG.AI.LIMITS.MAX_ROWS_PER_LIST;
|
||
|
|
const reeks = n => Array.from({ length: n }, (_, i) => ({ id: i + 1 }));
|
||
|
|
|
||
|
|
describe('limitRows: de primaire grens', () => {
|
||
|
|
it('laat een lijst binnen de grens ongemoeid', () => {
|
||
|
|
const r = limitRows(reeks(3), 10);
|
||
|
|
assert.equal(r.rows.length, 3);
|
||
|
|
assert.equal(r.omitted, 0);
|
||
|
|
assert.equal(r.capped, false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('kort in en vertelt hoeveel er weg zijn', () => {
|
||
|
|
const r = limitRows(reeks(30), 10);
|
||
|
|
assert.equal(r.rows.length, 10);
|
||
|
|
assert.equal(r.omitted, 20);
|
||
|
|
assert.equal(r.capped, true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('kort NIET in op exact de grens', () => {
|
||
|
|
const r = limitRows(reeks(10), 10);
|
||
|
|
assert.equal(r.capped, false);
|
||
|
|
assert.equal(r.omitted, 0);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('valt terug op de SSOT-grens als er geen maat wordt meegegeven', () => {
|
||
|
|
assert.equal(limitRows(reeks(MAX + 5)).rows.length, MAX);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('verdraagt iets dat geen lijst is', () => {
|
||
|
|
for (const raar of [null, undefined, 'tekst', 42]) {
|
||
|
|
assert.deepEqual(limitRows(raar, 5).rows, []);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('limitedList: de vorm die een tool hoort te gebruiken', () => {
|
||
|
|
it('zet de mededeling ONDER de regels en niet ertussen', () => {
|
||
|
|
const { lines } = limitedList(reeks(30), r => `- ${r.id}`, 10);
|
||
|
|
assert.equal(lines.length, 11, 'tien regels plus de mededeling');
|
||
|
|
assert.match(lines.at(-1), /nog 20 niet getoond/);
|
||
|
|
assert.equal(lines[0], '- 1');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('voegt niets toe als er niets is ingekort', () => {
|
||
|
|
const { lines, capped } = limitedList(reeks(4), r => `- ${r.id}`, 10);
|
||
|
|
assert.equal(lines.length, 4);
|
||
|
|
assert.equal(capped, false);
|
||
|
|
for (const regel of lines) assert.doesNotMatch(regel, /niet getoond/);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('noemt de grens zelf in de mededeling', () => {
|
||
|
|
assert.match(omittedNote(7, 50), /grens: 50/);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('limitText: het vangnet', () => {
|
||
|
|
it('laat tekst binnen de grens ongemoeid', () => {
|
||
|
|
const r = limitText('kort', 100);
|
||
|
|
assert.equal(r.text, 'kort');
|
||
|
|
assert.equal(r.capped, false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('gaat NOOIT over de grens heen, ook niet met de markering erbij', () => {
|
||
|
|
for (const max of [40, 200, 5000]) {
|
||
|
|
const r = limitText('x'.repeat(20000), max);
|
||
|
|
assert.ok(r.text.length <= max, `${r.text.length} > ${max}`);
|
||
|
|
assert.equal(r.capped, true);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
it('maakt het afkappen zichtbaar in de tekst zelf', () => {
|
||
|
|
const r = limitText('y'.repeat(500), 200);
|
||
|
|
assert.match(r.text, /Afgekapt/);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('houdt zich aan de grens ook als die kleiner is dan de markering', () => {
|
||
|
|
const r = limitText('z'.repeat(100), 5);
|
||
|
|
assert.ok(r.text.length <= 5);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('valt terug op de SSOT-grens', () => {
|
||
|
|
const r = limitText('q'.repeat(CONFIG.AI.LIMITS.MAX_TEXT_CHARS + 100));
|
||
|
|
assert.ok(r.text.length <= CONFIG.AI.LIMITS.MAX_TEXT_CHARS);
|
||
|
|
assert.equal(r.capped, true);
|
||
|
|
});
|
||
|
|
});
|