feat(sdk): plugin contract, http client, fixture harness
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
27ec24eb4b
commit
a14c4e7747
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { comparePartialDates, parsePartialDate } from "../src/partial-date.ts";
|
||||
|
||||
describe("parsePartialDate", () => {
|
||||
const table: [string | null | undefined, { value: string; precision: string } | null][] = [
|
||||
["2019", { value: "2019", precision: "year" }],
|
||||
["2019-03", { value: "2019-03", precision: "month" }],
|
||||
["2019-03-04", { value: "2019-03-04", precision: "day" }],
|
||||
["2019-03-04T10:20:30Z", { value: "2019-03-04T10:20:30Z", precision: "day" }],
|
||||
["2019-03-04T10:20:30.123+02:00", { value: "2019-03-04T10:20:30.123+02:00", precision: "day" }],
|
||||
["03/04/2019", null],
|
||||
["", null],
|
||||
[null, null],
|
||||
[undefined, null],
|
||||
["2019-13", null],
|
||||
["2019-02-30", null],
|
||||
["garbage", null],
|
||||
];
|
||||
for (const [input, expected] of table) {
|
||||
test(`${JSON.stringify(input)}`, () => {
|
||||
expect(parsePartialDate(input)).toEqual(expected as never);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("comparePartialDates", () => {
|
||||
test("orders by value", () => {
|
||||
const y = { value: "2019", precision: "year" as const };
|
||||
const m = { value: "2019-03", precision: "month" as const };
|
||||
const d = { value: "2019-03-04", precision: "day" as const };
|
||||
expect(comparePartialDates(y, m)).toBeLessThan(0);
|
||||
expect(comparePartialDates(d, m)).toBeGreaterThan(0);
|
||||
expect(comparePartialDates(d, d)).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user