insta_fun/macros.rs
1/// Macro for audio node snapshot testing
2///
3/// This macro processes an audio node with the given configuration,
4/// generates an SVG visualization, and asserts it against a stored snapshot.
5///
6/// ## Examples
7///
8/// ```
9/// use fundsp::prelude::*;
10/// use insta_fun::{assert_audio_node_snapshot, SnapshotConfig, InputSource};
11///
12///
13/// // With a custom name
14/// let node = saw_hz(220.0);
15/// assert_audio_node_snapshot!("doc_sawtooth", node);
16///
17/// // With input source
18/// let node = lowpass_hz(1000.0, 1.0);
19/// assert_audio_node_snapshot!("doc_lowpass", node, InputSource::impulse());
20///
21/// // With input source and custom config
22/// let config = SnapshotConfig::with_samples(512);
23/// let node = highpass_hz(2000.0, 0.7);
24/// assert_audio_node_snapshot!("doc_highpass", node, InputSource::sine(100.0, 44100.0), config);
25/// ```
26#[macro_export]
27macro_rules! assert_audio_node_snapshot {
28 // With just the node
29 ($node:expr) => {{
30 let svg = $crate::snapshot_audio_node($node);
31
32 ::insta::assert_binary_snapshot!(".svg", svg.as_bytes().to_vec());
33 }};
34
35 // With name and node
36 ($name:expr, $node:expr) => {{
37 let svg = $crate::snapshot_audio_node($node);
38
39 ::insta::assert_binary_snapshot!(&format!("{}.svg", $name), svg.as_bytes().to_vec());
40 }};
41
42 // With input source
43 ($name:expr, $node:expr, $input:expr) => {{
44 let svg = $crate::snapshot_audio_node_with_input($node, $input);
45
46 ::insta::assert_binary_snapshot!(&format!("{}.svg", $name), svg.as_bytes().to_vec());
47 }};
48
49 // With input source and config
50 ($name:expr, $node:expr, $input:expr, $config:expr) => {{
51 let svg = $crate::snapshot_audio_node_with_input_and_options($node, $input, $config);
52
53 ::insta::assert_binary_snapshot!(&format!("{}.svg", $name), svg.as_bytes().to_vec());
54 }};
55}