From 557c34311a72301a97875ab28caef09101458a95 Mon Sep 17 00:00:00 2001 From: Lyle Mantooth Date: Sat, 10 Feb 2024 16:16:52 -0500 Subject: [PATCH] Add variation tests. --- src/mfvi.rs | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/mfvi.rs b/src/mfvi.rs index 9073581..1c923d6 100644 --- a/src/mfvi.rs +++ b/src/mfvi.rs @@ -194,3 +194,83 @@ pub fn select_variant<'i>(input: &'i str, var: &'i Variant) -> String { output } + +#[cfg(test)] +mod test { + use super::SfxMode; + + const INPUT: &'static str = " +#VARIANT ~ +#VARIANT _ tr +#SFXV ` * + +#WAVE 0x20 0x62 violins +#WAVE 0x21 0x63 violas +#WAVE 0x22 ~0x01~ _0x09_ piano high +#WAVE 0x23 0x02 piano mid +#WAVE 0x24 0x07 piano lo-mid +#WAVE 0x25 0x04 piano low +##WAVE 0x26 0x06 piano x-high +#WAVE 0x27 0x75 vox +#WAVE 0x28 0x7E horn +#WAVE 0x29 0x92 oboe +"; + + #[test] + fn default_variant() { + let vlist = super::get_variants(INPUT, SfxMode::Off); + let def = vlist + .get("_default_") + .expect("_default_ variant always exists"); + + let variation = super::select_variant(INPUT, def); + assert_eq!( + variation, + " +#VARIANT +#VARIANT _ tr +#SFXV ` * + +#WAVE 0x20 0x62 violins +#WAVE 0x21 0x63 violas +#WAVE 0x22 0x01 piano high +#WAVE 0x23 0x02 piano mid +#WAVE 0x24 0x07 piano lo-mid +#WAVE 0x25 0x04 piano low +##WAVE 0x26 0x06 piano x-high +#WAVE 0x27 0x75 vox +#WAVE 0x28 0x7E horn +#WAVE 0x29 0x92 oboe +" + ); + } + + #[test] + fn tr_variant() { + let vlist = super::get_variants(INPUT, SfxMode::Off); + let tr = vlist + .get("tr") + .expect("tr variant is in input"); + + let variation = super::select_variant(INPUT, tr); + assert_eq!( + variation, + " +#VARIANT ~ +#VARIANT tr +#SFXV ` * + +#WAVE 0x20 0x62 violins +#WAVE 0x21 0x63 violas +#WAVE 0x22 0x09 piano high +#WAVE 0x23 0x02 piano mid +#WAVE 0x24 0x07 piano lo-mid +#WAVE 0x25 0x04 piano low +##WAVE 0x26 0x06 piano x-high +#WAVE 0x27 0x75 vox +#WAVE 0x28 0x7E horn +#WAVE 0x29 0x92 oboe +" + ); + } +}