Skip to content

Commit 0ff3fb7

Browse files
committed
Add test case
1 parent e58e320 commit 0ff3fb7

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

src/designspace.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,87 @@ mod tests {
459459
);
460460
}
461461

462+
#[test]
463+
fn serialize_lib() {
464+
use plist::Value;
465+
use serde_test::{assert_tokens, Token};
466+
467+
// JSON representation of the test lib, abbreviated from Cantarell.designspace:
468+
// {
469+
// "GSDimensionPlugin.Dimensions": {
470+
// "0B2E441B-685E-400D-9B9B-E078DEED62EF": {
471+
// "HH": "19",
472+
// "HV": "22"
473+
// },
474+
// "51C2DFEF-3776-4D13-9284-96485B799B57": {
475+
// "HH": "156",
476+
// "HV": "176"
477+
// }
478+
// },
479+
// "public.skipExportGlyphs": [
480+
// "_slash.zero",
481+
// "_slash.zero.osf",
482+
// "_typoquote"
483+
// ]
484+
// }
485+
486+
let mut d1 = plist::Dictionary::new();
487+
d1.insert("HH".into(), "19".into());
488+
d1.insert("HV".into(), "22".into());
489+
let mut d2 = plist::Dictionary::new();
490+
d2.insert("HH".into(), "156".into());
491+
d2.insert("HV".into(), "176".into());
492+
let mut dim = plist::Dictionary::new();
493+
dim.insert("0B2E441B-685E-400D-9B9B-E078DEED62EF".into(), Value::Dictionary(d1));
494+
dim.insert("51C2DFEF-3776-4D13-9284-96485B799B57".into(), Value::Dictionary(d2));
495+
let seg = plist::Value::Array(vec![
496+
Value::String("_slash.zero".into()),
497+
Value::String("_slash.zero.osf".into()),
498+
Value::String("_typoquote".into()),
499+
]);
500+
let mut lib = plist::Dictionary::new();
501+
lib.insert("GSDimensionPlugin.Dimensions".into(), Value::Dictionary(dim));
502+
lib.insert("public.skipExportGlyphs".into(), seg);
503+
504+
let designspace = DesignSpaceDocument { lib, ..Default::default() };
505+
506+
assert_tokens(
507+
&designspace,
508+
&[
509+
Token::Struct { name: "designspace", len: 2 },
510+
Token::Str("@format"),
511+
Token::F32(0.0),
512+
Token::Str("lib"),
513+
Token::Map { len: Some(2) },
514+
Token::Str("GSDimensionPlugin.Dimensions"),
515+
Token::Map { len: Some(2) },
516+
Token::Str("0B2E441B-685E-400D-9B9B-E078DEED62EF"),
517+
Token::Map { len: Some(2) },
518+
Token::Str("HH"),
519+
Token::Str("19"),
520+
Token::Str("HV"),
521+
Token::Str("22"),
522+
Token::MapEnd,
523+
Token::Str("51C2DFEF-3776-4D13-9284-96485B799B57"),
524+
Token::Map { len: Some(2) },
525+
Token::Str("HH"),
526+
Token::Str("156"),
527+
Token::Str("HV"),
528+
Token::Str("176"),
529+
Token::MapEnd,
530+
Token::MapEnd,
531+
Token::Str("public.skipExportGlyphs"),
532+
Token::Seq { len: Some(3) },
533+
Token::Str("_slash.zero"),
534+
Token::Str("_slash.zero.osf"),
535+
Token::Str("_typoquote"),
536+
Token::SeqEnd,
537+
Token::MapEnd,
538+
Token::StructEnd,
539+
],
540+
);
541+
}
542+
462543
#[test]
463544
fn do_not_serialize_empty_lib() {
464545
let ds_initial = DesignSpaceDocument::load("testdata/single_wght.designspace").unwrap();

0 commit comments

Comments
 (0)