From c7c1fb19e20e10128f9ec77d3773b750b5abc247 Mon Sep 17 00:00:00 2001 From: p6nj Date: Mon, 14 Oct 2024 11:31:57 -0400 Subject: [PATCH] inflate L2 tests passing, fix TupleEnd stack history cleaning --- src/bng/score/utils.rs | 5 ++- src/bng/score/utils/tests.rs | 71 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/bng/score/utils.rs b/src/bng/score/utils.rs index 4229a60..1fdb255 100644 --- a/src/bng/score/utils.rs +++ b/src/bng/score/utils.rs @@ -112,7 +112,10 @@ fn inflate(mut flat_atoms: Vec) -> Vec { } .last_mut() .unwrap() - .push(Atom::Tuple(popped)) + .push({ + stack_history.pop(); + Atom::Tuple(popped) + }) } else { result.push(Atom::Tuple(popped)) } diff --git a/src/bng/score/utils/tests.rs b/src/bng/score/utils/tests.rs index 88739d1..5c833a0 100644 --- a/src/bng/score/utils/tests.rs +++ b/src/bng/score/utils/tests.rs @@ -83,4 +83,75 @@ mod inflate { ]) ) } + + #[test] + fn inflate_loop_l2() { + assert_eq!( + vec![Atom::Loop( + unsafe { NonZeroU8::new_unchecked(2) }, + vec![Atom::Loop( + unsafe { NonZeroU8::new_unchecked(3) }, + vec![Atom::Note(2), Atom::Note(3)] + )] + )], + inflate(vec![ + FlatAtom::LoopStarts(unsafe { NonZeroU8::new_unchecked(2) }), + FlatAtom::LoopStarts(unsafe { NonZeroU8::new_unchecked(3) }), + FlatAtom::Note(2), + FlatAtom::Note(3), + FlatAtom::LoopEnds, + FlatAtom::LoopEnds + ]) + ) + } + + #[test] + fn inflate_tuple_l2() { + assert_eq!( + vec![Atom::Tuple(vec![Atom::Tuple(vec![ + Atom::Note(2), + Atom::Note(3) + ])])], + inflate(vec![ + FlatAtom::TupleStarts, + FlatAtom::TupleStarts, + FlatAtom::Note(2), + FlatAtom::Note(3), + FlatAtom::TupleEnds, + FlatAtom::TupleEnds + ]) + ) + } + + #[test] + fn inflate_slope_l2() { + let instruction = || { + let parser = fasteval::Parser::new(); + let mut slab = fasteval::Slab::new(); + parser + .parse(FASTEVAL_INSTRUCTION, &mut slab.ps) + .unwrap() + .from(&slab.ps) + .compile(&slab.ps, &mut slab.cs) + }; + assert_eq!( + vec![Atom::Slope( + SlopeModifier::Note, + instruction(), + vec![Atom::Slope( + SlopeModifier::Note, + instruction(), + vec![Atom::Note(2), Atom::Note(3)] + )] + )], + inflate(vec![ + FlatAtom::SlopeStarts(SlopeModifier::Note, instruction()), + FlatAtom::SlopeStarts(SlopeModifier::Note, instruction()), + FlatAtom::Note(2), + FlatAtom::Note(3), + FlatAtom::SlopeEnds, + FlatAtom::SlopeEnds + ]) + ) + } }