Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Dec 29, 2023
1 parent e58e320 commit 07ba676
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/designspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,87 @@ mod tests {
);
}

#[test]
fn serialize_lib() {
use plist::Value;
use serde_test::{assert_tokens, Token};

// JSON representation of the test lib, abbreviated from Cantarell.designspace:
// {
// "GSDimensionPlugin.Dimensions": {
// "0B2E441B-685E-400D-9B9B-E078DEED62EF": {
// "HH": "19",
// "HV": "22"
// },
// "51C2DFEF-3776-4D13-9284-96485B799B57": {
// "HH": "156",
// "HV": "176"
// }
// },
// "public.skipExportGlyphs": [
// "_slash.zero",
// "_slash.zero.osf",
// "_typoquote"
// ]
// }

let mut d1 = plist::Dictionary::new();
d1.insert("HH".into(), "19".into());
d1.insert("HV".into(), "22".into());
let mut d2 = plist::Dictionary::new();
d2.insert("HH".into(), "156".into());
d2.insert("HV".into(), "176".into());
let mut dim = plist::Dictionary::new();
dim.insert("0B2E441B-685E-400D-9B9B-E078DEED62EF".into(), Value::Dictionary(d1));
dim.insert("51C2DFEF-3776-4D13-9284-96485B799B57".into(), Value::Dictionary(d2));
let seg = plist::Value::Array(vec![
Value::String("_slash.zero".into()),
Value::String("_slash.zero.osf".into()),
Value::String("_typoquote".into()),
]);
let mut lib = plist::Dictionary::new();
lib.insert("GSDimensionPlugin.Dimensions".into(), Value::Dictionary(dim));
lib.insert("public.skipExportGlyphs".into(), seg);

let designspace = DesignSpaceDocument { lib, ..Default::default() };

assert_tokens(
&designspace,
&[
Token::Struct { name: "designspace", len: 2 },
Token::Str("@format"),
Token::F32(0.0),
Token::Str("lib"),
Token::Map { len: Some(2) },
Token::Str("GSDimensionPlugin.Dimensions".into()),
Token::Map { len: Some(2) },
Token::Str("0B2E441B-685E-400D-9B9B-E078DEED62EF".into()),
Token::Map { len: Some(2) },
Token::Str("HH".into()),
Token::Str("19".into()),
Token::Str("HV".into()),
Token::Str("22".into()),
Token::MapEnd,
Token::Str("51C2DFEF-3776-4D13-9284-96485B799B57".into()),
Token::Map { len: Some(2) },
Token::Str("HH".into()),
Token::Str("156".into()),
Token::Str("HV".into()),
Token::Str("176".into()),
Token::MapEnd,
Token::MapEnd,
Token::Str("public.skipExportGlyphs".into()),
Token::Seq { len: Some(3) },
Token::Str("_slash.zero".into()),
Token::Str("_slash.zero.osf".into()),
Token::Str("_typoquote".into()),
Token::SeqEnd,
Token::MapEnd,
Token::StructEnd,
],
);
}

#[test]
fn do_not_serialize_empty_lib() {
let ds_initial = DesignSpaceDocument::load("testdata/single_wght.designspace").unwrap();
Expand Down

0 comments on commit 07ba676

Please sign in to comment.