diff options
| author | Fuwn <[email protected]> | 2026-03-03 09:11:38 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-03 09:12:31 -0800 |
| commit | 0b3f4af0d8061fefcdeaba1352ea8176f34b1cbd (patch) | |
| tree | 5305af0876b70d0207df44febab27fb65236622d /src/lib/Effect/json.test.ts | |
| parent | refactor(effect): harden settings and media cache json parsing (diff) | |
| download | due.moe-0b3f4af0d8061fefcdeaba1352ea8176f34b1cbd.tar.xz due.moe-0b3f4af0d8061fefcdeaba1352ea8176f34b1cbd.zip | |
refactor(effect): migrate svelte json hotspots to typed decoders
Diffstat (limited to 'src/lib/Effect/json.test.ts')
| -rw-r--r-- | src/lib/Effect/json.test.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/Effect/json.test.ts b/src/lib/Effect/json.test.ts index b315fe61..c13824fe 100644 --- a/src/lib/Effect/json.test.ts +++ b/src/lib/Effect/json.test.ts @@ -2,7 +2,9 @@ import { describe, expect, it } from "vitest"; import { parseJsonStringOrDefault, parseJsonStringOrThrow, + parseJsonStringWithSchemaOrDefault, } from "$lib/Effect/json"; +import { Schema } from "effect"; describe("effect json parsing", () => { it("parses valid json strings", () => { @@ -21,4 +23,21 @@ describe("effect json parsing", () => { ok: false, }); }); + + it("decodes json with a schema and returns fallback on schema mismatch", () => { + expect( + parseJsonStringWithSchemaOrDefault( + "[1,2,3]", + Schema.Array(Schema.Number), + [], + ), + ).toEqual([1, 2, 3]); + expect( + parseJsonStringWithSchemaOrDefault( + `["a",2]`, + Schema.Array(Schema.Number), + [], + ), + ).toEqual([]); + }); }); |