html_helpers/slimmer/
slim_options.rs1#[derive(Clone, Copy, Debug, Default)]
5pub struct SlimOptions {
6 pub indent_with_tabs: bool,
8 pub indent: Option<u8>,
10}
11
12impl SlimOptions {
17 pub fn with_indent(mut self, spaces: u8) -> Self {
19 self.indent = Some(spaces);
20 self
21 }
22
23 pub fn with_indent_with_tabs(mut self, tabs: bool) -> Self {
25 self.indent_with_tabs = tabs;
26 self
27 }
28}
29
30#[cfg(test)]
35mod tests {
36 type TestResult<T> = core::result::Result<T, Box<dyn std::error::Error>>;
37
38 use super::*;
39
40 #[test]
41 fn test_slim_options_default() -> TestResult<()> {
42 let opts = SlimOptions::default();
45
46 assert!(!opts.indent_with_tabs, "indent_with_tabs should default to false");
48 assert!(opts.indent.is_none(), "indent should default to None");
49
50 Ok(())
51 }
52
53 #[test]
54 fn test_slim_options_with_indent() -> TestResult<()> {
55 let opts = SlimOptions::default().with_indent(4);
58
59 assert_eq!(opts.indent, Some(4));
61 assert!(!opts.indent_with_tabs);
62
63 Ok(())
64 }
65
66 #[test]
67 fn test_slim_options_with_indent_with_tabs() -> TestResult<()> {
68 let opts = SlimOptions::default().with_indent_with_tabs(true);
71
72 assert!(opts.indent_with_tabs);
74 assert!(opts.indent.is_none());
75
76 Ok(())
77 }
78
79 #[test]
80 fn test_slim_options_combined() -> TestResult<()> {
81 let opts = SlimOptions::default().with_indent(2).with_indent_with_tabs(true);
84
85 assert_eq!(opts.indent, Some(2));
87 assert!(opts.indent_with_tabs);
88
89 Ok(())
90 }
91}
92
93