---
source: crates/laburnum-syntax-macro/src/tests/mod.rs
expression: "use laburnum_syntax_macro::tests::test_real_world_cst_example"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(CST)]
  pub struct FunctionDeclaration {
      span: Span,
      pub_token: Option<NodeId<crate::Token>>,
      fn_token: NodeId<crate::Token>,
      identifier: NodeId<crate::Identifier>,
      generic_params: Option<NodeId<crate::GenericParameters>>,
      lparen: NodeId<crate::Token>,
      params: Vec<NodeId<crate::Parameter>>,
      rparen: NodeId<crate::Token>,
      return_type: Option<NodeId<crate::ReturnType>>,
      body: NodeId<crate::BlockExpression>,
      trivia: Vec<crate::Trivia>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct FunctionDeclaration {
      pub span: laburnum::Span,
      pub pub_token: Option<NodeId<crate::Token>>,
      pub fn_token: NodeId<crate::Token>,
      pub identifier: NodeId<crate::Identifier>,
      pub generic_params: Option<NodeId<crate::GenericParameters>>,
      pub lparen: NodeId<crate::Token>,
      pub params: Vec<NodeId<crate::Parameter>>,
      pub rparen: NodeId<crate::Token>,
      pub return_type: Option<NodeId<crate::ReturnType>>,
      pub body: NodeId<crate::BlockExpression>,
      pub trivia: Vec<crate::Trivia>,
  }
  impl FunctionDeclaration {
      pub fn span(&self) -> laburnum::Span {
          self.span
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for FunctionDeclaration {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name =
                      stringify!(FunctionDeclaration); let __seg_norm : std::string::String
                      = __last_seg.chars().filter(| c | * c != '_').collect(); let
                      __name_norm : std::string::String = __name.chars().filter(| c | * c
                      != '_').collect(); if __seg_norm.eq_ignore_ascii_case(& __name_norm)
                      { & __stripped[..__last_sep] } else { __stripped } } else {
                      __stripped } }, stringify!(FunctionDeclaration)
                  ),
              )
              .field("span", &self.span)
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for FunctionDeclaration {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name =
                      stringify!(FunctionDeclaration); let __seg_norm : std::string::String
                      = __last_seg.chars().filter(| c | * c != '_').collect(); let
                      __name_norm : std::string::String = __name.chars().filter(| c | * c
                      != '_').collect(); if __seg_norm.eq_ignore_ascii_case(& __name_norm)
                      { & __stripped[..__last_sep] } else { __stripped } } else {
                      __stripped } }, stringify!(FunctionDeclaration)
                  ),
              )
              .field("span", &self.span)
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for FunctionDeclaration {
      fn node(&self, b: &mut bluegum::Builder) {
          use owo_colors::OwoColorize;
          b.name(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name =
                      stringify!(FunctionDeclaration); let __seg_norm : std::string::String
                      = __last_seg.chars().filter(| c | * c != '_').collect(); let
                      __name_norm : std::string::String = __name.chars().filter(| c | * c
                      != '_').collect(); if __seg_norm.eq_ignore_ascii_case(& __name_norm)
                      { & __stripped[..__last_sep] } else { __stripped } } else {
                      __stripped } }, stringify!(FunctionDeclaration)
                  ),
              )
              .debug("span", self.span);
      }
  }
  #[allow(unused)]
  impl bluegum::BluegumWithState<crate::Printer<'_>> for FunctionDeclaration {
      fn node_with_state(&self, b: &mut bluegum::Builder, state: &crate::Printer<'_>) {
          use owo_colors::OwoColorize;
          use unicode_width::UnicodeWidthStr;
          b.name(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name =
                      stringify!(FunctionDeclaration); let __seg_norm : std::string::String
                      = __last_seg.chars().filter(| c | * c != '_').collect(); let
                      __name_norm : std::string::String = __name.chars().filter(| c | * c
                      != '_').collect(); if __seg_norm.eq_ignore_ascii_case(& __name_norm)
                      { & __stripped[..__last_sep] } else { __stripped } } else {
                      __stripped } }, stringify!(FunctionDeclaration)
                  ),
              )
              .debug("span", self.span);
          {
              if let Some(ref pub_token) = self.pub_token {
                  let mut t = bluegum::Builder::new();
                  t.name("Literal");
                  let s = format!("{}", pub_token);
                  if s.width() > 80 {
                      t.alt(format!("{:.80}...", s).bright_green());
                  } else {
                      t.alt(format!("{:.80}", s).bright_green());
                  };
                  b.add_named_builder(stringify!(pub_token), t);
              }
              let fn_token = &self.fn_token;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", fn_token);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(fn_token), t);
              let identifier = &self.identifier;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", identifier);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(identifier), t);
              if let Some(ref generic_params) = self.generic_params {
                  let mut t = bluegum::Builder::new();
                  t.name("Literal");
                  let s = format!("{}", generic_params);
                  if s.width() > 80 {
                      t.alt(format!("{:.80}...", s).bright_green());
                  } else {
                      t.alt(format!("{:.80}", s).bright_green());
                  };
                  b.add_named_builder(stringify!(generic_params), t);
              }
              let lparen = &self.lparen;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", lparen);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(lparen), t);
              let params = &self.params;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", params);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(params), t);
              let rparen = &self.rparen;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", rparen);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(rparen), t);
              if let Some(ref return_type) = self.return_type {
                  let mut t = bluegum::Builder::new();
                  t.name("Literal");
                  let s = format!("{}", return_type);
                  if s.width() > 80 {
                      t.alt(format!("{:.80}...", s).bright_green());
                  } else {
                      t.alt(format!("{:.80}", s).bright_green());
                  };
                  b.add_named_builder(stringify!(return_type), t);
              }
              let body = &self.body;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", body);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(body), t);
              let trivia = &self.trivia;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", trivia);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(trivia), t);
          };
      }
  }
