serde-diff icon indicating copy to clipboard operation
serde-diff copied to clipboard

Incorrect handling of map like structures

Open PPakalns opened this issue 4 years ago • 0 comments

See the applied test where "map" like structure is tested.

running 4 tests
test tests::test_targeted ... ok
test tests::test_array ... ok
test tests::test_tuple ... ok
test tests::test_option ... FAILED

failures:

---- tests::test_option stdout ----
thread 'tests::test_option' panicked at 'unexpected DiffCommand Value or Remove', src/apply.rs:96:49
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tests::test_option

test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '--lib'
diff --git a/src/tests.rs b/src/tests.rs
index 082846b..83d117c 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -1,7 +1,9 @@
 use crate as serde_diff;
 use crate::{Apply, Diff, SerdeDiff};
 use serde::{Deserialize, Serialize};
+use std::collections::HashMap;
 use std::fmt::Debug;
+use std::iter::FromIterator;
 
 #[derive(SerdeDiff, Serialize, Deserialize, PartialEq, Debug, Copy, Clone)]
 struct TestStruct {
@@ -59,6 +61,18 @@ fn test_option() {
         Some(TestStruct { a: 52, b: 32. }),
         Some(TestStruct { a: 42, b: 12. }),
     );
+    roundtrip(
+        HashMap::from_iter([
+            (1, TestStruct { a: 1, b: 1. }),
+            (2, TestStruct { a: 2, b: 2. }),
+            (3, TestStruct { a: 3, b: 3. }),
+        ]),
+        HashMap::from_iter([
+            (1, TestStruct { a: 1, b: 1. }),
+            (3, TestStruct { a: 4, b: 4. }),
+            (4, TestStruct { a: 1, b: 1. }),
+        ]),
+    );
 
     partial(
         Some(TestStruct { a: 5, b: 2. }),

PPakalns avatar Sep 08 '21 07:09 PPakalns