From 109e799a285b378c8263fb070267a789b110ed92 Mon Sep 17 00:00:00 2001 From: Damien Clarke Date: Thu, 17 Mar 2022 15:16:55 +1100 Subject: [PATCH] test: add duplicates tracking test, this may need revisiting --- .../test/optimise.test.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/dendriform-immer-patch-optimiser/test/optimise.test.ts b/packages/dendriform-immer-patch-optimiser/test/optimise.test.ts index 1157e71..2967588 100644 --- a/packages/dendriform-immer-patch-optimiser/test/optimise.test.ts +++ b/packages/dendriform-immer-patch-optimiser/test/optimise.test.ts @@ -431,7 +431,7 @@ describe(`change deep arrays`, () => { ); }); -describe(`sort with mutiple identical values`, () => { +describe(`dont optimise with primitive values`, () => { runTest( ['b','a','c','a','c','b','a'], d => { @@ -480,6 +480,27 @@ describe(`sort with mutiple identical values`, () => { ); }); +describe(`deal with multiple identical values`, () => { + runTest( + [A,A,B,A], + d => { + d.shift(); + }, + [A,B,A], + { + vanilla: [ + {op: 'replace', path: [1], value: B}, + {op: 'replace', path: [2], value: A}, + {op: 'replace', path: ['length'], value: 3} + ], + optimised: [ + {op: 'move', from: [2], path: [1]}, + {op: 'replace', path: ['length'], value: 3} + ] + } + ); +}); + describe(`filter with returned arrays`, () => { runTest( [A,B,C,D,E],