1use crate::basic_type::ST_Loc;
7
8#[derive(Debug, Clone, Default)]
15pub struct Res {
16 pub base_loc: Option<ST_Loc>,
18 pub resources: Vec<String>,
20}
21
22impl Res {
23 #[must_use]
25 pub fn new() -> Self {
26 Self::default()
27 }
28
29 #[must_use]
31 pub fn base_loc(mut self, loc: ST_Loc) -> Self {
32 self.base_loc = Some(loc);
33 self
34 }
35
36 pub fn add_resource(&mut self, resource: impl Into<String>) {
38 self.resources.push(resource.into());
39 }
40
41 #[must_use]
43 pub fn resource_count(&self) -> usize {
44 self.resources.len()
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn res_new() {
54 let r = Res::new();
55 assert!(r.base_loc.is_none());
56 assert_eq!(r.resource_count(), 0);
57 }
58
59 #[test]
60 fn res_builder() {
61 let r = Res::new().base_loc(ST_Loc::new("./Res"));
62 assert!(r.base_loc.is_some());
63 }
64
65 #[test]
66 fn res_add_resource() {
67 let mut r = Res::new();
68 r.add_resource("<ofd:Font/>");
69 r.add_resource("<ofd:ColorSpace/>");
70 assert_eq!(r.resource_count(), 2);
71 }
72}