Skip to content

Commit

Permalink
Implement MetaInfo's formatVersionMinor
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Sep 29, 2021
1 parent ffbfb82 commit d69d50d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ pub enum FormatVersion {
pub struct MetaInfo {
pub creator: String,
pub format_version: FormatVersion,
#[serde(default, skip_serializing_if = "is_zero")]
pub format_version_minor: u32,
}

fn is_zero(v: &u32) -> bool {
*v == 0
}

impl Default for MetaInfo {
fn default() -> Self {
MetaInfo {
creator: DEFAULT_METAINFO_CREATOR.to_string(),
format_version: FormatVersion::V3,
format_version_minor: 0,
}
}
}
Expand Down Expand Up @@ -632,4 +639,38 @@ mod tests {
let meta: MetaInfo = plist::from_file(path).expect("failed to load metainfo");
assert_eq!(meta.creator, "org.robofab.ufoLib");
}

#[test]
fn serialize_metainfo() {
use serde_test::{assert_ser_tokens, Token};

let meta1 = MetaInfo::default();
assert_ser_tokens(
&meta1,
&[
Token::Struct { name: "MetaInfo", len: 2 },
Token::Str("creator"),
Token::Str(DEFAULT_METAINFO_CREATOR),
Token::Str("formatVersion"),
Token::U8(3),
Token::StructEnd,
],
);

let mut meta2 = MetaInfo::default();
meta2.format_version_minor = 123;
assert_ser_tokens(
&meta2,
&[
Token::Struct { name: "MetaInfo", len: 3 },
Token::Str("creator"),
Token::Str(DEFAULT_METAINFO_CREATOR),
Token::Str("formatVersion"),
Token::U8(3),
Token::Str("formatVersionMinor"),
Token::U32(123),
Token::StructEnd,
],
);
}
}

0 comments on commit d69d50d

Please sign in to comment.