mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
src/next is src (the main export), src/next-node is src/node with short subpaths (/http, /workers, /plugins, /plugins/runtime, /app, /surfaces, /web, /react, /tui, /tui/launcher); the foundations get /json and /watch; Chord v1 moves to src/old (/old, /old/node) until p2 runs on v2; tests and docs move likewise (test/, docs/, test/old, docs/old). Durable and env import the foundations from their subpaths.
24 lines
1,002 B
TypeScript
24 lines
1,002 B
TypeScript
// Tests of the id allocator (slice 6b D3, §1.2): from 2, raised by explicit ids, saturating at the safe range.
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
import { FIRST_ID, IdAllocator } from "../../src/store/allocator.ts";
|
|
|
|
describe("the allocator", () => {
|
|
it("mints from its value, and an explicit id raises it above itself, never lowering it", () => {
|
|
const ids = new IdAllocator(FIRST_ID);
|
|
expect([ids.mint(), ids.mint()]).toEqual([2, 3]);
|
|
ids.raise(100);
|
|
expect(ids.mint()).toBe(101);
|
|
ids.raise(50);
|
|
expect(ids.value).toBe(102);
|
|
});
|
|
|
|
it("saturates at Number.MAX_SAFE_INTEGER: that id may be written, every later mint is refused", () => {
|
|
const ids = new IdAllocator(Number.MAX_SAFE_INTEGER - 1);
|
|
expect(ids.mint()).toBe(Number.MAX_SAFE_INTEGER - 1);
|
|
expect(() => ids.mint()).toThrow("ID space is exhausted");
|
|
ids.raise(Number.MAX_SAFE_INTEGER);
|
|
expect(ids.value).toBe(Number.MAX_SAFE_INTEGER);
|
|
expect(() => ids.mint()).toThrow("ID space is exhausted");
|
|
});
|
|
});
|