Permalink
Browse files

Handle and test rests.

  • Loading branch information...
LastOfTheCarelessMen committed Dec 16, 2009
1 parent 6493ea1 commit af6d791f668ac3b9130a29d47b5a5ee3f9e8b2e2
Showing with 24 additions and 0 deletions.
  1. +3 −0 lib/ABC.pm
  2. +21 −0 t/01-regexes.t
View
@@ -15,6 +15,9 @@ grammar ABC
regex tie { '-' }
regex note_length { [\d* ['/' \d*]? ] | '/' }
regex note { <pitch> <note_length>? <tie>? }
+
+ regex rest_type { <[x..z]> }
+ regex rest { <rest_type> <note_length>? }
}
class ABCHeader
View
@@ -63,5 +63,26 @@ plan *;
is $match<ABC::note><note_length>, "2/3", '"G,2/3" has note length 2/3';
}
+{
+ my $match = "z2/3" ~~ m/ <ABC::rest> /;
+ isa_ok $match, Match, '"z2/3" is a rest';
+ is $match<ABC::rest><rest_type>, "z", '"z2/3" has base rest z';
+ is $match<ABC::rest><note_length>, "2/3", '"z2/3" has note length 2/3';
+}
+
+{
+ my $match = "y/3" ~~ m/ <ABC::rest> /;
+ isa_ok $match, Match, '"y/3" is a rest';
+ is $match<ABC::rest><rest_type>, "y", '"y/3" has base rest y';
+ is $match<ABC::rest><note_length>, "/3", '"y/3" has note length 2/3';
+}
+
+{
+ my $match = "x" ~~ m/ <ABC::rest> /;
+ isa_ok $match, Match, '"x" is a rest';
+ is $match<ABC::rest><rest_type>, "x", '"x" has base rest x';
+ is $match<ABC::rest><note_length>, "", '"x" has no note length';
+}
+
done_testing;

0 comments on commit af6d791

Please sign in to comment.