ferrotype 0.1.3

An opinionated wrapper for insta.rs
Documentation
// Copyright Two Neutron Stars Incorporated and contributors
// SPDX-License-Identifier: BlueOak-1.0.0

use ferrotype::Ferrotype;

#[test]
fn test_macro_compiles_and_runs() {
  let mut snapshot = Ferrotype::new();
  snapshot.add("Test", "Hello from macro test".to_string());

  // This should compile and run without panicking
  // Note: In a real test environment, this would create a snapshot file
  // For now, we're just testing that the macro expands correctly
  ferrotype::assert!(snapshot);
}

#[test]
fn test_macro_with_expect_errors() {
  let mut snapshot = Ferrotype::new();
  snapshot.set_expect_errors(true);
  snapshot.add("Error Test", "This test expects errors".to_string());

  // This should handle the expect_errors flag correctly
  ferrotype::assert!(snapshot);
}

#[test]
fn test_macro_with_memory_filtering() {
  let mut snapshot = Ferrotype::new();
  snapshot.set_filter_memory_addresses(true);
  snapshot.add(
    "Memory Test",
    "Test with 0x7fff5fbff710 address".to_string(),
  );

  // The macro should filter memory addresses when enabled
  ferrotype::assert!(snapshot);
}

#[test]
fn test_macro_without_memory_filtering() {
  let mut snapshot = Ferrotype::new();
  snapshot.set_filter_memory_addresses(false);
  snapshot.add(
    "No Filter Test",
    "Test with 0x7fff5fbff710 address".to_string(),
  );

  // The macro should preserve memory addresses when disabled
  ferrotype::assert!(snapshot);
}

// Test the use_folder functionality
#[test]
fn test_macro_with_custom_folder() {
  let mut snapshot = Ferrotype::new();
  snapshot.add("Custom Folder", "Test with custom folder".to_string());

  // This would use a custom folder structure
  // #[use_folder(custom, subfolder)]
  ferrotype::assert!(snapshot);
}

#[test]
fn test_macro_with_multiple_sections() {
  let mut snapshot = Ferrotype::new();
  snapshot.add("Section 1", "First section content".to_string());
  snapshot.add("Section 2", "Second section content".to_string());
  snapshot.add_debug("Debug Section", vec![1, 2, 3]);

  // Test that macro handles multiple sections correctly
  ferrotype::assert!(snapshot);
}

#[test]
fn test_macro_function_name_detection() {
  // The macro should automatically detect this function name
  let mut snapshot = Ferrotype::new();
  snapshot.add(
    "Function Name Test",
    "Testing automatic function name detection".to_string(),
  );

  // The snapshot name should include "test_macro_function_name_detection"
  ferrotype::assert!(snapshot);
}

// Test edge cases
#[test]
fn test_macro_with_empty_snapshot() {
  let snapshot = Ferrotype::new();

  // Should handle empty snapshots
  ferrotype::assert!(snapshot);
}

#[test]
fn test_macro_with_special_characters() {
  let mut snapshot = Ferrotype::new();
  snapshot.add(
    "Special Characters",
    "Content with\nnewlines\tand\ttabs".to_string(),
  );

  // Should handle special characters correctly
  ferrotype::assert!(snapshot);
}

// Test that the macro works in different module contexts
mod submodule {
  use super::*;

  #[test]
  fn test_macro_in_submodule() {
    let mut snapshot = Ferrotype::new();
    snapshot.add("Submodule Test", "Testing from submodule".to_string());

    // Should work correctly from within a submodule
    ferrotype::assert!(snapshot);
  }
}

// Test macro with different feature combinations
#[cfg(feature = "hex")]
#[test]
fn test_macro_with_hex_feature() {
  let mut snapshot = Ferrotype::new();
  snapshot.add_hex("Hex Data", b"Binary data for hex test");

  // Should work with hex feature enabled
  ferrotype::assert!(snapshot);
}

#[cfg(feature = "bluegum")]
#[test]
fn test_macro_with_bluegum_feature() {
  #[derive(Debug)]
  struct TestTree {
    name: String,
  }

  impl bluegum::Bluegum for TestTree {
    fn node(&self, builder: &mut bluegum::Builder) {
      builder.name(&self.name);
    }
  }

  impl bluegum::BluegumWithState<()> for TestTree {}

  let mut snapshot = Ferrotype::new();
  let tree = TestTree {
    name: "Test Tree".to_string(),
  };
  snapshot.add_bluegum("Tree", &tree);

  // Should work with bluegum feature enabled
  ferrotype::assert!(snapshot);
}

#[cfg(feature = "tokenstream")]
#[test]
fn test_macro_with_tokenstream_feature() {
  let mut snapshot = Ferrotype::new();
  let tokens: proc_macro2::TokenStream = "fn test() {}".parse().unwrap();
  snapshot.add_token_stream("Tokens", &tokens);

  // Should work with tokenstream feature enabled
  ferrotype::assert!(snapshot);
}

// Test the internal macro helpers
#[test]
fn test_get_output_dir_function() {
  let dir = ferrotype::get_output_dir();

  #[cfg(feature = "dot_snapshots")]
  assert_eq!(dir, ".snapshots");

  #[cfg(not(feature = "dot_snapshots"))]
  assert_eq!(dir, "snapshots");
}

// Test that demonstrates the expected workflow
#[test]
fn test_typical_workflow() {
  // Create a new snapshot
  let mut snapshot = Ferrotype::new();

  // Configure it
  snapshot.set_filter_memory_addresses(true);

  // Add various types of content
  snapshot.add("Input", "Hello, world!".to_string());
  snapshot.add_debug("Data Structure", vec!["item1", "item2", "item3"]);

  #[cfg(feature = "hex")]
  snapshot.add_hex("Binary", b"Hello");

  ferrotype::assert!(snapshot);
}