Files
lancedb/nodejs/__test__/util.test.ts
Will Jones 15f8f4d627 ci: check license headers (#2076)
Based on the same workflow in Lance.
2025-01-29 08:27:07 -08:00

32 lines
1014 B
TypeScript

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
import { IntoSql, toSQL } from "../lancedb/util";
test.each([
["string", "'string'"],
[123, "123"],
[1.11, "1.11"],
[true, "TRUE"],
[false, "FALSE"],
[null, "NULL"],
[new Date("2021-01-01T00:00:00.000Z"), "'2021-01-01T00:00:00.000Z'"],
[[1, 2, 3], "[1, 2, 3]"],
[new ArrayBuffer(8), "X'0000000000000000'"],
[Buffer.from("hello"), "X'68656c6c6f'"],
["Hello 'world'", "'Hello ''world'''"],
])("toSQL(%p) === %p", (value, expected) => {
expect(toSQL(value)).toBe(expected);
});
test("toSQL({}) throws on unsupported value type", () => {
expect(() => toSQL({} as unknown as IntoSql)).toThrow(
"Unsupported value type: object value: ([object Object])",
);
});
test("toSQL() throws on unsupported value type", () => {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
expect(() => (<any>toSQL)()).toThrow(
"Unsupported value type: undefined value: (undefined)",
);
});