Skip to content

Commit 9a9872a

Browse files
committed
test(coverage): dissolve coverage-gaps into per-topic spec files, remove dead code
Remove unreachable leading-whitespace trims from naive array deserializers (bool, float, integer, string) and delete the dead deserializeEscapedStringContinuation_SWAR_MergedTuned function from swar/string.ts. Add success-path tests for TypedArrays, escaped struct string fields, and SWAR/SIMD integer/float paths. Coverage improves from ~86.4% to 88.97% (3258/3662). Distribute all tests from coverage-gaps.spec.ts into their respective topic files (string, float, integer, array, struct, typedarray, set, box, whitespace, json-runtime, jsonarray-extra) and delete the consolidated file.
1 parent 6309e2b commit 9a9872a

18 files changed

Lines changed: 1370 additions & 1417 deletions

assembly/__tests__/array.spec.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,82 @@ describe("Should serialize string[] of non-null elements through nullable type",
445445
'["a","b","c"]',
446446
);
447447
});
448+
449+
// ─── helpers ──────────────────────────────────────────────────────────────────
450+
451+
@json
452+
class BoolArr {
453+
flags: bool[] = [];
454+
}
455+
456+
457+
@json
458+
class Matrix {
459+
rows: i32[][] = [];
460+
}
461+
462+
// ─── Naive array success paths ───────────────────────────────────────────────
463+
464+
describe("NAIVE: bool[] round-trips", () => {
465+
expect(JSON.stringify(JSON.parse<bool[]>("[true,false,true]"))).toBe(
466+
"[true,false,true]",
467+
);
468+
});
469+
470+
describe("NAIVE: f64[] round-trips with negative and fractional", () => {
471+
expect(JSON.stringify(JSON.parse<f64[]>("[-1.5,0,2.5]"))).toBe(
472+
"[-1.5,0,2.5]",
473+
);
474+
});
475+
476+
describe("Serialize: f32 array elements round-trip", () => {
477+
expect(JSON.stringify<f32[]>([-1.5, 0.25, 3.75])).toBe("[-1.5,0.25,3.75]");
478+
});
479+
480+
describe("Serialize: empty i8[] array", () => {
481+
expect(JSON.stringify<i8[]>([])).toBe("[]");
482+
});
483+
484+
describe("Serialize: empty u8[] array", () => {
485+
expect(JSON.stringify<u8[]>([])).toBe("[]");
486+
});
487+
488+
// bool[] as @json field → deserializeBooleanArrayBody (SWAR)
489+
describe("SWAR: bool[] field with inner whitespace covers whitespace loops", () => {
490+
const r = JSON.parse<BoolArr>('{"flags":[ true , false , true ]}');
491+
expect(r.flags.length).toBe(3);
492+
expect(r.flags[0]).toBe(true);
493+
expect(r.flags[1]).toBe(false);
494+
});
495+
496+
describe("SWAR: bool[] field reparse with fewer elements (resize)", () => {
497+
const r = JSON.parse<BoolArr>('{"flags":[true,false,true]}');
498+
expect(r.flags.length).toBe(3);
499+
const r2 = JSON.parse<BoolArr>('{"flags":[true]}', r);
500+
expect(r2.flags.length).toBe(1);
501+
expect(r2.flags[0]).toBe(true);
502+
});
503+
504+
// Array of arrays → naive/array/array.ts
505+
describe("Naive: i32[][] round-trips in all modes", () => {
506+
expect(JSON.stringify(JSON.parse<i32[][]>("[[1,2],[3,4,5]]"))).toBe(
507+
"[[1,2],[3,4,5]]",
508+
);
509+
});
510+
511+
// naive/array/array.ts path 1: JSON.Value[][]
512+
describe("Naive: JSON.Value[][] covers path-1 arbitraryInner Reference branch", () => {
513+
const arr = JSON.parse<JSON.Value[][]>('[[1,2],[3,"a"]]');
514+
expect(arr.length).toBe(2);
515+
expect(arr[0].length).toBe(2);
516+
expect(arr[1].length).toBe(2);
517+
});
518+
519+
// swar/array/array.ts: shrink path when reparsing fewer inner arrays
520+
describe("SWAR: Matrix.rows reparse with fewer inner arrays covers array-array body shrink path", () => {
521+
const m1 = JSON.parse<Matrix>('{"rows":[[1,2],[3,4],[5,6]]}');
522+
expect(m1.rows.length).toBe(3);
523+
const m2 = JSON.parse<Matrix>('{"rows":[[7,8]]}', m1);
524+
expect(m2.rows.length).toBe(1);
525+
expect(m2.rows[0][0]).toBe(7);
526+
});

assembly/__tests__/box.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,19 @@ describe("Extended regression coverage - nested and escaped payloads", () => {
8686
'"line\\nbreak"',
8787
);
8888
});
89+
90+
// ─── JSON.Box ─────────────────────────────────────────────────────────────────
91+
92+
describe("JSON.Box: fromValue() returns null for JSON null", () => {
93+
const b = JSON.Box.fromValue<i32>(JSON.parse<JSON.Value>("null"));
94+
expect(changetype<usize>(b) == 0 ? "null" : "set").toBe("null");
95+
});
96+
97+
describe("JSON.Box: fromValue() returns boxed value for non-null", () => {
98+
const b = JSON.Box.fromValue<f64>(JSON.parse<JSON.Value>("42"));
99+
expect(b!.value).toBe(42.0);
100+
});
101+
102+
describe("JSON.Box: toString() on null box serializes as null", () => {
103+
expect(JSON.stringify<JSON.Box<i32> | null>(null)).toBe("null");
104+
});

0 commit comments

Comments
 (0)