17 lines
1023 B
TypeScript
17 lines
1023 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { parseSetClause } from "./services.js";
|
|
const entity = { id: "entity", fields: [{ name: "name", label: "名称", type: "text" }, { name: "code", label: "编码", type: "text" }] } as any;
|
|
test("commas inside single and double quoted strings do not split assignments", () => {
|
|
expect(parseSetClause('名称="ACME, Inc.", 编码=ACME', entity)).toEqual({ name: "ACME, Inc.", code: "ACME" });
|
|
expect(parseSetClause("名称='A,B', 编码=C", entity)).toEqual({ name: "A,B", code: "C" });
|
|
});
|
|
test("escaped quotes preserve the quoted comma boundary", () => {
|
|
const parsed = parseSetClause(String.raw`name="ACME\", Inc.", code=C`, entity);
|
|
expect(parsed.code).toBe("C");
|
|
expect(parsed.name).toEndWith(", Inc.");
|
|
expect(Object.keys(parsed)).toHaveLength(2);
|
|
});
|
|
for (const clause of ['名称="unfinished', "名称=A,broken", "名称=A,", "=A"]) {
|
|
test(`rejects incomplete assignments: ${clause}`, () => { expect(() => parseSetClause(clause, entity)).toThrow(); });
|
|
}
|