Skip to content

Commit

Permalink
Stop using serde(flatten) due to a bug in serde
Browse files Browse the repository at this point in the history
  • Loading branch information
dkellner committed Sep 18, 2020
1 parent 76a53b8 commit 8cae1ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/offsetmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::collections::BTreeMap;
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub(crate) struct OffsetMap<K: Ord, O> {
#[cfg_attr(feature = "serde", serde(flatten))]
map: BTreeMap<K, Option<O>>,
}

Expand Down
1 change: 0 additions & 1 deletion src/rangemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::collections::BTreeMap;
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub(crate) struct RangeFromMap<K: Ord, V> {
#[cfg_attr(feature = "serde", serde(flatten))]
map: BTreeMap<K, V>,
}

Expand Down
13 changes: 11 additions & 2 deletions tests/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#![cfg(feature = "serde")]
use chronofold::{Chronofold, LogIndex};

#[test]
fn roundtrip() {
let mut cfold = Chronofold::<usize, char>::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::<usize, char>::new();
assert_json_max_len(&cfold, 100);
assert_json_max_len(&cfold, 132);
}

#[test]
Expand All @@ -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<usize, char>, max_len: usize) {
Expand Down

0 comments on commit 8cae1ef

Please sign in to comment.