#[derive(Clone, Copy, Debug, Default)]
pub struct SlimOptions {
pub indent_with_tabs: bool,
pub indent: Option<u8>,
}
impl SlimOptions {
pub fn with_indent(mut self, spaces: u8) -> Self {
self.indent = Some(spaces);
self
}
pub fn with_indent_with_tabs(mut self, tabs: bool) -> Self {
self.indent_with_tabs = tabs;
self
}
}
#[cfg(test)]
mod tests {
type TestResult<T> = core::result::Result<T, Box<dyn std::error::Error>>;
use super::*;
#[test]
fn test_slim_options_default() -> TestResult<()> {
let opts = SlimOptions::default();
assert!(!opts.indent_with_tabs, "indent_with_tabs should default to false");
assert!(opts.indent.is_none(), "indent should default to None");
Ok(())
}
#[test]
fn test_slim_options_with_indent() -> TestResult<()> {
let opts = SlimOptions::default().with_indent(4);
assert_eq!(opts.indent, Some(4));
assert!(!opts.indent_with_tabs);
Ok(())
}
#[test]
fn test_slim_options_with_indent_with_tabs() -> TestResult<()> {
let opts = SlimOptions::default().with_indent_with_tabs(true);
assert!(opts.indent_with_tabs);
assert!(opts.indent.is_none());
Ok(())
}
#[test]
fn test_slim_options_combined() -> TestResult<()> {
let opts = SlimOptions::default().with_indent(2).with_indent_with_tabs(true);
assert_eq!(opts.indent, Some(2));
assert!(opts.indent_with_tabs);
Ok(())
}
}