insta_fun/macros.rs
1/// Macro for audio unit snapshot testing
2///
3/// This macro processes an audio unit 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::prelude::*;
11///
12///
13/// // With a custom name
14/// let unit = saw_hz(220.0);
15/// assert_audio_unit_snapshot!("doc_sawtooth", unit);
16///
17/// // With input source
18/// let unit = lowpass_hz(1000.0, 1.0);
19/// assert_audio_unit_snapshot!("doc_lowpass", unit, InputSource::impulse());
20///
21/// // With input source and custom config
22/// let config = SnapshotConfigBuilder::default().num_samples(512).build().unwrap();
23/// let unit = highpass_hz(2000.0, 0.7);
24/// assert_audio_unit_snapshot!("doc_highpass", unit, InputSource::sine(100.0, 44100.0), config);
25/// ```
26#[macro_export]
27macro_rules! assert_audio_unit_snapshot {
28 // With just the unit
29 ($unit:expr) => {{
30 let svg = $crate::snapshot::snapshot_audio_unit($unit);
31
32 ::insta::assert_binary_snapshot!(".svg", svg.as_bytes().to_vec());
33 }};
34
35 // With name and unit
36 ($name:expr, $unit:expr) => {{
37 let svg = $crate::snapshot::snapshot_audio_unit($unit);
38
39 ::insta::assert_binary_snapshot!(&format!("{}.svg", $name), svg.as_bytes().to_vec());
40 }};
41
42 // With input source
43 ($name:expr, $unit:expr, $input:expr) => {{
44 let svg = $crate::snapshot::snapshot_audio_unit_with_input($unit, $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, $unit:expr, $input:expr, $config:expr) => {{
51 let svg =
52 $crate::snapshot::snapshot_audio_unit_with_input_and_options($unit, $input, $config);
53
54 ::insta::assert_binary_snapshot!(&format!("{}.svg", $name), svg.as_bytes().to_vec());
55 }};
56}