From 8cae1efd9696f6a61b4ee1e0ae9ca28357734796 Mon Sep 17 00:00:00 2001 From: Dominik Kellner Date: Fri, 18 Sep 2020 17:19:18 +0200 Subject: [PATCH] Stop using `serde(flatten)` due to a bug in serde see https://github.com/serde-rs/serde/issues/1638 --- src/offsetmap.rs | 1 - src/rangemap.rs | 1 - tests/serialization.rs | 13 +++++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/offsetmap.rs b/src/offsetmap.rs index a4f365d..abd63cc 100644 --- a/src/offsetmap.rs +++ b/src/offsetmap.rs @@ -13,7 +13,6 @@ use std::collections::BTreeMap; #[derive(Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub(crate) struct OffsetMap { - #[cfg_attr(feature = "serde", serde(flatten))] map: BTreeMap>, } diff --git a/src/rangemap.rs b/src/rangemap.rs index 5fb7b30..7901a48 100644 --- a/src/rangemap.rs +++ b/src/rangemap.rs @@ -5,7 +5,6 @@ use std::collections::BTreeMap; #[derive(Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub(crate) struct RangeFromMap { - #[cfg_attr(feature = "serde", serde(flatten))] map: BTreeMap, } diff --git a/tests/serialization.rs b/tests/serialization.rs index 7e97b0c..792f1be 100644 --- a/tests/serialization.rs +++ b/tests/serialization.rs @@ -1,10 +1,19 @@ #![cfg(feature = "serde")] use chronofold::{Chronofold, LogIndex}; +#[test] +fn roundtrip() { + let mut cfold = Chronofold::::new(); + cfold.session(1).extend("Hello world!".chars()); + let json = serde_json::to_string(&cfold).unwrap(); + eprintln!("{}", json); + assert_eq!(cfold, serde_json::from_str(&json).unwrap()); +} + #[test] fn empty() { let cfold = Chronofold::::new(); - assert_json_max_len(&cfold, 100); + assert_json_max_len(&cfold, 132); } #[test] @@ -14,7 +23,7 @@ fn local_edits_only() { cfold .session(1) .splice(LogIndex(6)..LogIndex(11), "cfold".chars()); - assert_json_max_len(&cfold, 360); + assert_json_max_len(&cfold, 390); } fn assert_json_max_len(cfold: &Chronofold, max_len: usize) {