summaryrefslogtreecommitdiff
path: root/tst/collections_jsonds.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tst/collections_jsonds.test.ts')
-rw-r--r--tst/collections_jsonds.test.ts37
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);
+ });
+});