1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use core::num::NonZeroU16;
use crate::parser::Stream;
pub fn parse(data: &[u8]) -> Option<NonZeroU16> {
let mut s = Stream::new(data);
let version: u32 = s.read()?;
if !(version == 0x00005000 || version == 0x00010000) {
return None;
}
let n: u16 = s.read()?;
NonZeroU16::new(n)
}
#[cfg(test)]
mod tests {
#[test]
fn version_05() {
let num_glyphs = super::parse(&[
0x00, 0x00, 0x50, 0x00,
0x00, 0x01,
]).map(|n| n.get());
assert_eq!(num_glyphs, Some(1));
}
#[test]
fn version_1_full() {
let num_glyphs = super::parse(&[
0x00, 0x01, 0x00, 0x00,
0x00, 0x01,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
]).map(|n| n.get());
assert_eq!(num_glyphs, Some(1));
}
#[test]
fn version_1_trimmed() {
let num_glyphs = super::parse(&[
0x00, 0x01, 0x00, 0x00,
0x00, 0x01,
]).map(|n| n.get());
assert_eq!(num_glyphs, Some(1));
}
#[test]
fn unknown_version() {
let num_glyphs = super::parse(&[
0x00, 0x00, 0x00, 0x00,
0x00, 0x01,
]).map(|n| n.get());
assert_eq!(num_glyphs, None);
}
#[test]
fn zero_glyphs() {
let num_glyphs = super::parse(&[
0x00, 0x00, 0x50, 0x00,
0x00, 0x00,
]).map(|n| n.get());
assert_eq!(num_glyphs, None);
}
}