From eb6ff5698cd23a110c99d42ec672584d1c8b85b2 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Wed, 21 Aug 2024 17:39:09 +0200 Subject: [PATCH] Add test on better handling for unicode in JS-side prepared statement --- .../test/regression/github_1833.test.ts | 36 +++++++++++++++++++ packages/duckdb-wasm/test/regression/index.ts | 2 ++ 2 files changed, 38 insertions(+) create mode 100644 packages/duckdb-wasm/test/regression/github_1833.test.ts diff --git a/packages/duckdb-wasm/test/regression/github_1833.test.ts b/packages/duckdb-wasm/test/regression/github_1833.test.ts new file mode 100644 index 000000000..4e597ed2c --- /dev/null +++ b/packages/duckdb-wasm/test/regression/github_1833.test.ts @@ -0,0 +1,36 @@ +import * as duckdb from '../../src'; + +// https://github.com/duckdb/duckdb-wasm/issues/1833 +export function test1833(db: () => duckdb.AsyncDuckDB): void { + let conn: duckdb.AsyncDuckDBConnection; + beforeEach(async () => { + await db().flushFiles(); + conn = await db().connect(); + }); + afterEach(async () => { + await conn.close(); + await db().flushFiles(); + await db().dropFiles(); + }); + describe('GitHub issues', () => { + it('1833', async () => { + await conn.query(` + CREATE TABLE "Test" (value VARCHAR) + `); + const stmt = await conn.prepare(` + INSERT INTO "Test" (value) + VALUES (?) + `); + await stmt.query('🦆🦆🦆🦆🦆'); + await stmt.query('goo␀se'); + await stmt.query('goo\u0000se'); + const result = await conn.query(` + SELECT * FROM "Test" + `); + expect(result.schema.fields.length).toBe(1); + expect(result.schema.fields[0].name).toBe('value'); + expect(result.toArray().length).toEqual(3); + expect(result.toArray()[2].value.length).toEqual(6); + }); + }); +} diff --git a/packages/duckdb-wasm/test/regression/index.ts b/packages/duckdb-wasm/test/regression/index.ts index 5f323976b..6e9b4ebbe 100644 --- a/packages/duckdb-wasm/test/regression/index.ts +++ b/packages/duckdb-wasm/test/regression/index.ts @@ -6,6 +6,7 @@ import { test448 } from './github_448.test'; import { test470 } from './github_470.test'; import { test477 } from './github_477.test'; import { test1467 } from './github_1467.test'; +import { test1833 } from './github_1833.test'; export function testRegressionAsync(adb: () => duckdb.AsyncDuckDB): void { test332(adb); @@ -15,4 +16,5 @@ export function testRegressionAsync(adb: () => duckdb.AsyncDuckDB): void { test470(adb); test477(adb); test1467(adb); + test1833(adb); }