{
my $match = "d'+p+<<<+accent+_B" ~~ m/ <ABC::broken_rhythm> /;
isa_ok $match, Match, '"d+p+<<<+accent+_B" is a broken rhythm';
given $match<ABC::broken_rhythm>
{
is .<note>[0]<pitch><basenote>, "d", 'first note is d';
is .<note>[0]<pitch><octave>, "'", 'first note has an octave tick';
is .<note>[0]<pitch><accidental>, "", 'first note has no accidental';
is .<note>[0]<note_length>, "", 'first note has no length';
is .<g1>[0], "+p+", 'first gracing is +p+';
is .<broken_rhythm_bracket>, "<<<", 'angle is <<<';
is .<g2>[0], "+accent+", 'second gracing is +accent+';
is .<note>[1]<pitch><basenote>, "B", 'second note is B';
is .<note>[1]<pitch><octave>, "", 'second note has no octave';
is .<note>[1]<pitch><accidental>, "_", 'second note is flat';
is .<note>[1]<note_length>, "", 'second note has no length';
}
}
This is far from the amazing new testing form I was hoping to find, but it sure is a big improvement over what I had. If I don't think of something else better, I will go back and redo all of the longer test cases this way.
He also said about the barline regex, "Looks like it would need LTM to work." I believe he's talking about longest-token matching, but I don't fully understand the issues, I fear. I did finally write tests for this case:
for ':|:', '|:', '|', ':|', '::'
{
my $match = $_ ~~ m/ <ABC::barline> /;
isa_ok $match, Match, "barline $_ recognized";
is $match<ABC::barline>, $_, "barline $_ is correct";
And they didn't work -- sometimes it would match the first barline it recognized rather than the longest. Moritz also suggested, "Reordering the longest alternatives to the front would help," so I did, and then all the tests passed. I hope that means the problems are actually gone, and not just that I've managed to hide them for the moment.
Anyway, big kudos for Moritz! Thanks to him, it definitely feels like I am getting closer here. Now if I can just figure out the proper way to ask for an entire line of ABC music in Perl 6, I will be there!
No comments:
Post a Comment