~dkellner/chronofold

8cae1efd9696f6a61b4ee1e0ae9ca28357734796 — Dominik Kellner 2 months ago 76a53b8
Stop using `serde(flatten)` due to a bug in serde

see https://github.com/serde-rs/serde/issues/1638
3 files changed, 11 insertions(+), 4 deletions(-)

M src/offsetmap.rs
M src/rangemap.rs
M tests/serialization.rs
M src/offsetmap.rs => src/offsetmap.rs +0 -1
@@ 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>>,
}


M src/rangemap.rs => src/rangemap.rs +0 -1
@@ 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>,
}


M tests/serialization.rs => tests/serialization.rs +11 -2
@@ 2,9 2,18 @@
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]


@@ 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) {