File size: 1,004 Bytes
57b63b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import assert from "node:assert/strict";
import { test } from "node:test";
import { readPages } from "../src/read-pages.js";

test("reads beyond the upstream row cap with inclusive, ordered ranges", async () => {
  const input = Array.from({ length: 1203 }, (_, index) => index);
  const ranges: number[][] = [];
  const rows = await readPages(async (from, to) => {
    ranges.push([from, to]);
    return input.slice(from, to + 1);
  });
  assert.deepEqual(rows, input);
  assert.deepEqual(ranges, [[0, 499], [500, 999], [1000, 1499]]);
});

test("handles empty and exact page boundaries, and propagates failure", async () => {
  assert.deepEqual(await readPages(async () => []), []);
  let calls = 0;
  assert.deepEqual(await readPages(async (from) => { calls++; return from ? [] : [1, 2]; }, 2), [1, 2]);
  assert.equal(calls, 2);
  await assert.rejects(readPages(async () => { throw new Error("offline"); }), /offline/);
  await assert.rejects(readPages(async () => [], 0), /Invalid page size/);
});