baobao_codegen/builder/
indent.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Indent {
6 Spaces(u8),
8 Tab,
10}
11
12impl Indent {
13 pub const RUST: Self = Self::Spaces(4);
15
16 pub const TYPESCRIPT: Self = Self::Spaces(2);
18
19 pub const GO: Self = Self::Tab;
21
22 pub fn as_str(&self) -> &'static str {
24 match self {
25 Self::Spaces(2) => " ",
26 Self::Spaces(4) => " ",
27 Self::Spaces(8) => " ",
28 Self::Spaces(_) => " ",
30 Self::Tab => "\t",
31 }
32 }
33}
34
35impl Default for Indent {
36 fn default() -> Self {
37 Self::RUST
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_indent_as_str() {
47 assert_eq!(Indent::Spaces(2).as_str(), " ");
48 assert_eq!(Indent::Spaces(4).as_str(), " ");
49 assert_eq!(Indent::Tab.as_str(), "\t");
50 }
51
52 #[test]
53 fn test_indent_constants() {
54 assert_eq!(Indent::RUST, Indent::Spaces(4));
55 assert_eq!(Indent::TYPESCRIPT, Indent::Spaces(2));
56 assert_eq!(Indent::GO, Indent::Tab);
57 }
58
59 #[test]
60 fn test_default() {
61 assert_eq!(Indent::default(), Indent::RUST);
62 }
63}