hwpforge_core/
tab.rs

1//! Tab property definitions.
2//!
3//! Maps to HWPX `<hh:tabProperties>` and `<hh:tabPr>`.
4
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8/// A single tab property definition.
9///
10/// Maps to HWPX `<hh:tabPr>`.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
12pub struct TabDef {
13    /// Tab property ID (0-based).
14    pub id: u32,
15    /// Auto-insert tab at left margin.
16    pub auto_tab_left: bool,
17    /// Auto-insert tab at right margin.
18    pub auto_tab_right: bool,
19}
20
21impl TabDef {
22    /// Returns the 3 default tab properties (한글 Modern).
23    ///
24    /// Matches golden fixture `tests/fixtures/textbox.hwpx`:
25    ///
26    /// - id=0: no auto tabs (default for most paragraphs)
27    /// - id=1: `autoTabLeft=1` (outline numbering auto-indent)
28    /// - id=2: `autoTabRight=1` (right-aligned tab)
29    pub fn defaults() -> [Self; 3] {
30        [
31            Self { id: 0, auto_tab_left: false, auto_tab_right: false },
32            Self { id: 1, auto_tab_left: true, auto_tab_right: false },
33            Self { id: 2, auto_tab_left: false, auto_tab_right: true },
34        ]
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn defaults_has_3_entries() {
44        let tabs = TabDef::defaults();
45        assert_eq!(tabs.len(), 3);
46    }
47
48    #[test]
49    fn defaults_ids_sequential() {
50        let tabs = TabDef::defaults();
51        assert_eq!(tabs[0].id, 0);
52        assert_eq!(tabs[1].id, 1);
53        assert_eq!(tabs[2].id, 2);
54    }
55
56    #[test]
57    fn defaults_auto_tab_values() {
58        let tabs = TabDef::defaults();
59        // id=0: no auto tabs
60        assert!(!tabs[0].auto_tab_left);
61        assert!(!tabs[0].auto_tab_right);
62        // id=1: auto tab left
63        assert!(tabs[1].auto_tab_left);
64        assert!(!tabs[1].auto_tab_right);
65        // id=2: auto tab right
66        assert!(!tabs[2].auto_tab_left);
67        assert!(tabs[2].auto_tab_right);
68    }
69}