diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
| commit | 666674327f009e9b1013218fc384f193b64c6997 (patch) | |
| tree | acebae7b425b469584eb0a5bec396899c2739501 /tst/collections_jsonds.test.ts | |
| parent | 594ce452693a71b501d3aff3f35ef3732c06c341 (diff) | |
| download | pengueno-666674327f009e9b1013218fc384f193b64c6997.tar.gz pengueno-666674327f009e9b1013218fc384f193b64c6997.zip | |
Adds unit tests
Diffstat (limited to 'tst/collections_jsonds.test.ts')
| -rw-r--r-- | tst/collections_jsonds.test.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tst/collections_jsonds.test.ts b/tst/collections_jsonds.test.ts new file mode 100644 index 0000000..17b23a6 --- /dev/null +++ b/tst/collections_jsonds.test.ts @@ -0,0 +1,37 @@ +import { JSONHashMap, JSONSet } from '../lib/index'; + +describe('types/collections/jsonds', () => { + test('JSONSet uses stable JSON identity', () => { + const set = new JSONSet<{ a: number; b: number }>(); + set.add({ a: 1, b: 2 }); + + expect(set.has({ b: 2, a: 1 })).toBe(true); + expect(set.size()).toBe(1); + + expect(set.delete({ b: 2, a: 1 })).toBe(true); + expect(set.has({ a: 1, b: 2 })).toBe(false); + + set.add({ a: 1, b: 2 }); + set.clear(); + expect(set.size()).toBe(0); + }); + + test('JSONHashMap stable keying and keys()', () => { + const map = new JSONHashMap<{ a: number; b: number }, { v: string }>(); + + map.set({ a: 1, b: 2 }, { v: 'x' }); + expect(map.get({ b: 2, a: 1 })).toEqual({ v: 'x' }); + expect(map.has({ b: 2, a: 1 })).toBe(true); + expect(map.size()).toBe(1); + + const keys = map.keys(); + expect(keys).toEqual([{ a: 1, b: 2 }]); + + expect(map.delete({ b: 2, a: 1 })).toBe(true); + expect(map.size()).toBe(0); + + map.set({ a: 1, b: 2 }, { v: 'x' }); + map.clear(); + expect(map.size()).toBe(0); + }); +}); |
