Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of map like structures #39

Open
PPakalns opened this issue Sep 8, 2021 · 0 comments · May be fixed by #40
Open

Incorrect handling of map like structures #39

PPakalns opened this issue Sep 8, 2021 · 0 comments · May be fixed by #40

Comments

@PPakalns
Copy link

PPakalns commented Sep 8, 2021

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 PPakalns linked a pull request Sep 8, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant