---
source: crates/laburnum-syntax-macro/src/tests/ast_tests.rs
expression: "use laburnum_syntax_macro::tests::ast_tests::test_ast_error_node"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(AST, error)]
  pub struct ErrorNode {
      message: String,
      span: Span,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct ErrorNode {
      /// The unique identifier for this node.
      pub(crate) id: crate::NodeId,
      /// The syntax node id that this node is based on.
      pub(crate) syntax: crate::SyntaxId,
      /// Any meta information that is associated with this node.
      pub(crate) meta: Option<crate::NodeId>,
      pub(crate) message: laburnum::Span,
      pub(crate) span: laburnum::Span,
  }
  impl ErrorNode {
      pub fn get_id(&self) -> crate::NodeId {
          self.id
      }
      pub fn get_syntax(&self) -> crate::SyntaxId {
          self.syntax
      }
      pub fn get_meta(&self) -> Option<crate::NodeId> {
          self.meta
      }
  }
  pub mod error_node_field {}
  #[allow(unused)]
  impl ErrorNode {
      ///Returns the `laburnum::Span` for the `message` field
      pub fn get_message_spur<'ast>(&self, ast: &'ast crate::AST) -> laburnum::Span {
          self.message
      }
      ///Returns the `message` field
      pub fn get_message<'ast>(&self, ast: &'ast crate::AST) -> std::string::String {
          {
              let message = &self.message;
              ast.intern.resolve(message).to_string()
          }
      }
      ///Returns the `span` field
      pub fn get_span<'ast>(&self, ast: &'ast crate::AST) -> laburnum::Span {
          {
              let span = &self.span;
              *span
          }
      }
  }
  #[allow(unused)]
  impl<'ast> ErrorNode {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for ErrorNode {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "ErrorNode"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for ErrorNode {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "ErrorNode"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for ErrorNode {
      fn node(&self, b: &mut bluegum::Builder) {
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"ErrorNode",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for ErrorNode {
      fn node_with_state(
          &self,
          b: &mut bluegum::Builder,
          state: &crate::Printer<'tokens>,
      ) {
          use owo_colors::OwoColorize;
          use unicode_width::UnicodeWidthStr;
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"ErrorNode",
              ),
          );
          if let Some(cst_node) = state.get_syntax(self.syntax) {
              let span = cst_node.span();
              if let Some(span_data) = span.data(state.get_span_cache()) {
                  b.debug(
                      "span",
                      format!("{}..{}", span_data.start, span_data.start + span_data.len),
                  );
              }
          }
          if let Some(meta) = self.meta {
              b.add_node_with_state(state, &"meta".blue().italic().to_string(), &meta);
          }
          {
              {
                  let message = &self.message;
                  use {owo_colors::OwoColorize, unicode_width::UnicodeWidthStr};
                  b.debug(stringify!(message), format!("{:?}", message));
                  let val = state.get_interned(message).to_string();
                  if val.width() > 80 {
                      b.alt(format!("{:.80}...", val).bright_white());
                  } else {
                      b.alt(format!("{:.80}", val).bright_white());
                  };
              };
              {
                  let span = &self.span;
                  use {owo_colors::OwoColorize, unicode_width::UnicodeWidthStr};
                  let val = span
                      .text(state.get_span_cache(), state.get_source())
                      .unwrap_or("");
                  b.field(stringify!(span), "Span".cyan().to_string());
                  if val.width() > 80 {
                      b.alt(format!("{:.80}...", val).bright_white());
                  } else {
                      b.alt(format!("{:.80}", val).bright_white());
                  };
              };
          };
      }
  }
