Skip to content

Commit

Permalink
Skip serializing empty libs
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyDaMa committed Aug 1, 2023
1 parent 5e713ca commit d440af5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/designspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct DesignSpaceDocument {
#[serde(default, with = "serde_impls::instances", skip_serializing_if = "Vec::is_empty")]
pub instances: Vec<Instance>,
/// Additional arbitrary user data
#[serde(default, with = "serde_plist")]
#[serde(default, with = "serde_plist", skip_serializing_if = "Dictionary::is_empty")]
pub lib: Dictionary,
}

Expand Down Expand Up @@ -140,7 +140,7 @@ pub struct Instance {
#[serde(with = "serde_impls::location")]
pub location: Vec<Dimension>,
/// Arbitrary data about this instance
#[serde(default, with = "serde_plist")]
#[serde(default, with = "serde_plist", skip_serializing_if = "Dictionary::is_empty")]
pub lib: Dictionary,
}

Expand Down Expand Up @@ -389,6 +389,15 @@ mod tests {
);
}

#[test]
fn do_not_serialize_empty_lib() {
let ds_initial = DesignSpaceDocument::load("testdata/single_wght.designspace").unwrap();
let serialized = quick_xml::se::to_string(&ds_initial).expect("should serialize");

assert!(!serialized.contains("<lib>"));
assert!(!serialized.contains("<lib/>"));
}

#[test]
fn load_save_round_trip() {
// Given
Expand Down

0 comments on commit d440af5

Please sign in to comment.