Setting the file. One moment.
Chapter 06 · Clickhouse Js Node Rowbinary
Subchapter 6.151
tests/Point.test.ts
TypeScript36 lines1 KB
import { describe, expect, it } from "vitest";
import { query } from "./clickhouse.js";
import { NeedMoreData, Cursor } from "../src/readers/core.js";
import { readPoint } from "../src/readers/geo.js";
async function reader(expr: string): Promise<Cursor> {
return new Cursor(await query(`SELECT ${expr} FORMAT RowBinary`));
}
describe("readPoint", () => {
it("decodes a Point as [x, y]", async () => {
const r = await reader("CAST((1.5, 2.5) AS Point)");
expect(readPoint(r)).toEqual([1.5, 2.5]);
expect(r.pos).toBe(16); // two Float64
});
describe("advance() edge cases", () => {
it("throws NeedMoreData for every incomplete prefix (0 .. full.length-1)", async () => {
const full = await query(
"SELECT CAST((1.5, 2.5) AS Point) FORMAT RowBinary",
);
for (let len = 0; len < full.length; len++) {
const r = new Cursor(full.subarray(0, len));
let thrown: unknown;
try {
readPoint(r);
} catch (e) {
thrown = e;
}
expect(thrown, `prefix length ${len} of ${full.length}`).toBe(
NeedMoreData,
);
}
});
});
});