Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 527 lines (474 sloc) 18.965 kb
9972dc3 @LastOfTheCarelessMen Try to set up proper configuration.
LastOfTheCarelessMen authored
1 use v6;
2bed1ff @LastOfTheCarelessMen First working test.
LastOfTheCarelessMen authored
2 use Test;
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
3 use ABC::Grammar;
9972dc3 @LastOfTheCarelessMen Try to set up proper configuration.
LastOfTheCarelessMen authored
4
2bed1ff @LastOfTheCarelessMen First working test.
LastOfTheCarelessMen authored
5 {
e01b96b @colomon Add chords to the grammar.
authored
6 my $match = ABC::Grammar.parse('"Cmin"', :rule<chord_or_text>);
7 isa_ok $match, Match, 'Got a match';
8 ok $match, '"Cmin" is a chord';
9 is $match<chord>, "Cmin", '"Cmin" is chord Cmin';
10 is $match<chord>[0]<basenote>, "C", '"Cmin" has base note C';
11 is $match<chord>[0]<chord_type>, "min", '"Cmin" has chord_type "min"';
12 }
13
14 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
15 my $match = ABC::Grammar.parse("^A,", :rule<pitch>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
16 isa_ok $match, Match, 'Got a match';
17 ok $match, '"^A," is a pitch';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
18 is $match<basenote>, "A", '"^A," has base note A';
19 is $match<octave>, ",", '"^A," has octave ","';
20 is $match<accidental>, "^", '"^A," has accidental "#"';
2bed1ff @LastOfTheCarelessMen First working test.
LastOfTheCarelessMen authored
21 }
22
d81a69f @LastOfTheCarelessMen Add more tests.
LastOfTheCarelessMen authored
23 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
24 my $match = ABC::Grammar.parse("_B", :rule<pitch>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
25 isa_ok $match, Match, 'Got a match';
26 ok $match, '"_B" is a pitch';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
27 is $match<basenote>, "B", '"_B" has base note B';
28 is $match<octave>, "", '"_B" has octave ""';
29 is $match<accidental>, "_", '"_B" has accidental "_"';
d81a69f @LastOfTheCarelessMen Add more tests.
LastOfTheCarelessMen authored
30 }
31
32 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
33 my $match = ABC::Grammar.parse("C''", :rule<pitch>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
34 isa_ok $match, Match, 'Got a match';
35 ok $match, '"note" is a pitch';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
36 is $match<basenote>, "C", '"note" has base note C';
37 is $match<octave>, "''", '"note" has octave two-upticks';
38 is $match<accidental>, "", '"note" has accidental ""';
d81a69f @LastOfTheCarelessMen Add more tests.
LastOfTheCarelessMen authored
39 }
40
41 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
42 my $match = ABC::Grammar.parse("=d,,,", :rule<pitch>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
43 isa_ok $match, Match, 'Got a match';
44 ok $match, '"=d,,," is a pitch';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
45 is $match<basenote>, "d", '"=d,,," has base note d';
46 is $match<octave>, ",,,", '"=d,,," has octave ",,,"';
47 is $match<accidental>, "=", '"=d,,," has accidental "="';
d81a69f @LastOfTheCarelessMen Add more tests.
LastOfTheCarelessMen authored
48 }
49
bb96052 @LastOfTheCarelessMen Fix note_length regex. Two tests of ABC::note.
LastOfTheCarelessMen authored
50 {
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
51 my $match = ABC::Grammar.parse("2", :rule<note_length>);
52 isa_ok $match, Match, 'Got a match';
53 ok $match, '"2" is a note length';
54 is $match, "2", '"2" has note length 2';
55 }
56
57 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
58 my $match = ABC::Grammar.parse("^^e2", :rule<mnote>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
59 isa_ok $match, Match, 'Got a match';
60 ok $match, '"^^e2" is a note';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
61 is $match<pitch><basenote>, "e", '"^^e2" has base note e';
62 is $match<pitch><octave>, "", '"^^e2" has octave ""';
63 is $match<pitch><accidental>, "^^", '"^^e2" has accidental "^^"';
64 is $match<note_length>, "2", '"^^e2" has note length 2';
bb96052 @LastOfTheCarelessMen Fix note_length regex. Two tests of ABC::note.
LastOfTheCarelessMen authored
65 }
66
67 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
68 my $match = ABC::Grammar.parse("__f'/", :rule<mnote>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
69 isa_ok $match, Match, 'Got a match';
70 ok $match, '"__f/" is a note';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
71 is $match<pitch><basenote>, "f", '"__f/" has base note f';
72 is $match<pitch><octave>, "'", '"__f/" has octave tick';
73 is $match<pitch><accidental>, "__", '"__f/" has accidental "__"';
74 is $match<note_length>, "/", '"__f/" has note length /';
bb96052 @LastOfTheCarelessMen Fix note_length regex. Two tests of ABC::note.
LastOfTheCarelessMen authored
75 }
76
6493ea1 @LastOfTheCarelessMen Another note test.
LastOfTheCarelessMen authored
77 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
78 my $match = ABC::Grammar.parse("G,2/3", :rule<mnote>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
79 isa_ok $match, Match, 'Got a match';
80 ok $match, '"G,2/3" is a note';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
81 is $match<pitch><basenote>, "G", '"G,2/3" has base note G';
82 is $match<pitch><octave>, ",", '"G,2/3" has octave ","';
83 is $match<pitch><accidental>, "", '"G,2/3" has no accidental';
84 is $match<note_length>, "2/3", '"G,2/3" has note length 2/3';
6493ea1 @LastOfTheCarelessMen Another note test.
LastOfTheCarelessMen authored
85 }
d81a69f @LastOfTheCarelessMen Add more tests.
LastOfTheCarelessMen authored
86
af6d791 @LastOfTheCarelessMen Handle and test rests.
LastOfTheCarelessMen authored
87 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
88 my $match = ABC::Grammar.parse("z2/3", :rule<rest>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
89 isa_ok $match, Match, 'Got a match';
90 ok $match, '"z2/3" is a rest';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
91 is $match<rest_type>, "z", '"z2/3" has base rest z';
92 is $match<note_length>, "2/3", '"z2/3" has note length 2/3';
af6d791 @LastOfTheCarelessMen Handle and test rests.
LastOfTheCarelessMen authored
93 }
94
95 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
96 my $match = ABC::Grammar.parse("y/3", :rule<rest>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
97 isa_ok $match, Match, 'Got a match';
98 ok $match, '"y/3" is a rest';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
99 is $match<rest_type>, "y", '"y/3" has base rest y';
100 is $match<note_length>, "/3", '"y/3" has note length 2/3';
af6d791 @LastOfTheCarelessMen Handle and test rests.
LastOfTheCarelessMen authored
101 }
102
103 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
104 my $match = ABC::Grammar.parse("x", :rule<rest>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
105 isa_ok $match, Match, 'Got a match';
106 ok $match, '"x" is a rest';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
107 is $match<rest_type>, "x", '"x" has base rest x';
108 is $match<note_length>, "", '"x" has no note length';
af6d791 @LastOfTheCarelessMen Handle and test rests.
LastOfTheCarelessMen authored
109 }
110
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored
111 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
112 my $match = ABC::Grammar.parse("+trill+", :rule<element>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
113 isa_ok $match, Match, 'Got a match';
114 ok $match, '"+trill+" is an element';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
115 is $match<gracing>, "+trill+", '"+trill+" gracing is +trill+';
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored
116 }
117
118 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
119 my $match = ABC::Grammar.parse("~", :rule<element>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
120 isa_ok $match, Match, 'Got a match';
121 ok $match, '"~" is an element';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
122 is $match<gracing>, "~", '"~" gracing is ~';
fb0b7d2 @LastOfTheCarelessMen Add staccato and roll gracings, and basic grace note support.
LastOfTheCarelessMen authored
123 }
124
125 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
126 my $match = ABC::Grammar.parse("z/", :rule<element>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
127 isa_ok $match, Match, 'Got a match';
128 ok $match, '"z/" is an element';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
129 is $match<rest><rest_type>, "z", '"z/" has base rest z';
130 is $match<rest><note_length>, "/", '"z/" has length "/"';
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored
131 }
132
133 {
82ca886 @colomon Add very basic support for slurs in the grammar.
authored
134 my $match = ABC::Grammar.parse("(", :rule<element>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
135 isa_ok $match, Match, 'Got a match';
136 ok $match, '"(" is an element';
82ca886 @colomon Add very basic support for slurs in the grammar.
authored
137 is $match<slur_begin>, '(', '"(" is a slur begin';
138 }
139
140 {
141 my $match = ABC::Grammar.parse(")", :rule<element>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
142 isa_ok $match, Match, 'Got a match';
143 ok $match, '")" is an element';
82ca886 @colomon Add very basic support for slurs in the grammar.
authored
144 is $match<slur_end>, ')', '")" is a slur end';
145 }
146
147 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
148 my $match = ABC::Grammar.parse("_D,5/4", :rule<element>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
149 isa_ok $match, Match, 'Got a match';
150 ok $match, '"_D,5/4" is an element';
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
151 is $match<stem><mnote>[0]<pitch><basenote>, "D", '"_D,5/4" has base note D';
152 is $match<stem><mnote>[0]<pitch><octave>, ",", '"_D,5/4" has octave ","';
153 is $match<stem><mnote>[0]<pitch><accidental>, "_", '"_D,5/4" is flat';
154 is $match<stem><mnote>[0]<note_length>, "5/4", '"_D,5/4" has note length 5/4';
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored
155 }
d81a69f @LastOfTheCarelessMen Add more tests.
LastOfTheCarelessMen authored
156
1b40656 @LastOfTheCarelessMen Add broken_rhythm.
LastOfTheCarelessMen authored
157 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
158 my $match = ABC::Grammar.parse("A>^C'", :rule<broken_rhythm>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
159 isa_ok $match, Match, 'Got a match';
160 ok $match, '"A>^C" is a broken rhythm';
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
161 is $match<stem>[0]<mnote>[0]<pitch><basenote>, "A", 'first note is A';
162 is $match<stem>[0]<mnote>[0]<pitch><octave>, "", 'first note has no octave';
163 is $match<stem>[0]<mnote>[0]<pitch><accidental>, "", 'first note has no accidental';
164 is $match<stem>[0]<mnote>[0]<note_length>, "", 'first note has no length';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
165 is $match<broken_rhythm_bracket>, ">", 'angle is >';
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
166 is $match<stem>[1]<mnote>[0]<pitch><basenote>, "C", 'second note is C';
167 is $match<stem>[1]<mnote>[0]<pitch><octave>, "'", 'second note has octave tick';
168 is $match<stem>[1]<mnote>[0]<pitch><accidental>, "^", 'second note is sharp';
169 is $match<stem>[1]<mnote>[0]<note_length>, "", 'second note has no length';
1b40656 @LastOfTheCarelessMen Add broken_rhythm.
LastOfTheCarelessMen authored
170 }
171
46f0793 @LastOfTheCarelessMen Second test for broken_rhythm.
LastOfTheCarelessMen authored
172 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
173 my $match = ABC::Grammar.parse("d'+p+<<<+accent+_B", :rule<broken_rhythm>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
174 isa_ok $match, Match, 'Got a match';
175 ok $match, '"d+p+<<<+accent+_B" is a broken rhythm';
0cf2701 @colomon Rewrite a bunch of tests to work in current Rakudo.
authored
176 given $match
3d558f6 @LastOfTheCarelessMen Implement Moritz's suggestions, more or less.
LastOfTheCarelessMen authored
177 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
178 is .<stem>[0]<mnote>[0]<pitch><basenote>, "d", 'first note is d';
179 is .<stem>[0]<mnote>[0]<pitch><octave>, "'", 'first note has an octave tick';
180 is .<stem>[0]<mnote>[0]<pitch><accidental>, "", 'first note has no accidental';
181 is .<stem>[0]<mnote>[0]<note_length>, "", 'first note has no length';
3d558f6 @LastOfTheCarelessMen Implement Moritz's suggestions, more or less.
LastOfTheCarelessMen authored
182 is .<g1>[0], "+p+", 'first gracing is +p+';
183 is .<broken_rhythm_bracket>, "<<<", 'angle is <<<';
184 is .<g2>[0], "+accent+", 'second gracing is +accent+';
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
185 is .<stem>[1]<mnote>[0]<pitch><basenote>, "B", 'second note is B';
186 is .<stem>[1]<mnote>[0]<pitch><octave>, "", 'second note has no octave';
187 is .<stem>[1]<mnote>[0]<pitch><accidental>, "_", 'second note is flat';
188 is .<stem>[1]<mnote>[0]<note_length>, "", 'second note has no length';
3d558f6 @LastOfTheCarelessMen Implement Moritz's suggestions, more or less.
LastOfTheCarelessMen authored
189 }
190 }
191
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored
192 {
ed6dc7a @colomon Fix up long_gracing so that it works without breaking tests.
authored
193 my $match = ABC::Grammar.parse("(3abc", :rule<tuplet>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
194 isa_ok $match, Match, 'Got a match';
195 ok $match, '"(3abc" is a tuplet';
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored
196 is ~$match, "(3abc", '"(3abc" was the portion matched';
197 is +@( $match<stem> ), 3, 'Three notes matched';
198 is $match<stem>[0], "a", 'first note is a';
199 is $match<stem>[1], "b", 'second note is b';
200 is $match<stem>[2], "c", 'third note is c';
201 }
202
83d7ac7 @colomon Allow [ABC] chords to have durations and "is tied" flags. This goes …
authored
203 {
ea8c786 @colomon Support sixteenth note as a note length, and better (though note yet …
authored
204 my $match = ABC::Grammar.parse("(5abcde", :rule<tuplet>);
205 isa_ok $match, Match, 'Got a match';
206 ok $match, '"(5abcde" is a tuplet';
207 is ~$match, "(5abcde", '"(5abcde" was the portion matched';
208 is +@( $match<stem> ), 5, 'Three notes matched';
209 is $match<stem>[0], "a", 'first note is a';
210 is $match<stem>[1], "b", 'second note is b';
211 is $match<stem>[2], "c", 'third note is c';
212 is $match<stem>[3], "d", 'fourth note is d';
213 is $match<stem>[4], "e", 'fifth note is e';
214 }
215
216 {
83d7ac7 @colomon Allow [ABC] chords to have durations and "is tied" flags. This goes …
authored
217 my $match = ABC::Grammar.parse("[a2bc]3", :rule<stem>);
218 isa_ok $match, Match, 'Got a match';
219 ok $match, '"[a2bc]3" is a stem';
220 is ~$match, "[a2bc]3", '"[a2bc]3" was the portion matched';
221 is +@( $match<mnote> ), 3, 'Three notes matched';
222 is $match<mnote>[0], "a2", 'first note is a2';
223 is $match<mnote>[1], "b", 'second note is b';
224 is $match<mnote>[2], "c", 'third note is c';
225 is $match<note_length>, "3", 'correct duration';
226 nok ?$match<tie>, 'not tied';
227 }
228
229 {
230 my $match = ABC::Grammar.parse("[a2bc]3-", :rule<stem>);
231 isa_ok $match, Match, 'Got a match';
232 ok $match, '"[a2bc]3-" is a stem';
233 is ~$match, "[a2bc]3-", '"[a2bc]3-" was the portion matched';
234 is +@( $match<mnote> ), 3, 'Three notes matched';
235 is $match<mnote>[0], "a2", 'first note is a2';
236 is $match<mnote>[1], "b", 'second note is b';
237 is $match<mnote>[2], "c", 'third note is c';
238 is $match<note_length>, "3", 'correct duration';
239 ok ?$match<tie>, 'tied';
240 }
241
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored
242 # (3 is the only case that works currently. :(
243 # {
244 # my $match = ABC::Grammar.parse("(2abcd", :rule<tuple>);
245 # isa_ok $match, Match, '"(2ab" is a tuple';
246 # is ~$match, "(2ab", '"(2ab" was the portion matched';
247 # is $match<stem>[0], "a", 'first note is a';
248 # is $match<stem>[1], "b", 'second note is b';
249 # }
250
56c09ce @colomon Support length field and proper final bar line.
authored
251 for ':|:', '|:', '|', ':|', '::', '|]'
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
252 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
253 my $match = ABC::Grammar.parse($_, :rule<barline>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
254 isa_ok $match, Match, 'Got a match';
255 ok $match, "barline $_ recognized";
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
256 is $match, $_, "barline $_ is correct";
257 }
258
259 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
260 my $match = ABC::Grammar.parse("g>ecgece/f/g/e/|", :rule<bar>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
261 isa_ok $match, Match, 'Got a match';
262 ok $match, 'bar recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
263 is $match, "g>ecgece/f/g/e/|", "Entire bar was matched";
264 is $match<element>.map(~*), "g>e c g e c e/ f/ g/ e/", "Each element was matched";
265 is $match<barline>, "|", "Barline was matched";
266 }
267
268 {
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
269 my $match = ABC::Grammar.parse("g>ecg ec e/f/g/e/ |", :rule<bar>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
270 isa_ok $match, Match, 'Got a match';
271 ok $match, 'bar recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
272 is $match, "g>ecg ec e/f/g/e/ |", "Entire bar was matched";
273 is $match<element>.map(~*), "g>e c g e c e/ f/ g/ e/ ", "Each element was matched";
274 is $match<barline>, "|", "Barline was matched";
275 }
276
277 {
278 my $line = "g>ecg ec e/f/g/e/ | d/c/B/A/ Gd BG B/c/d/B/ |";
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
279 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
280 isa_ok $match, Match, 'Got a match';
281 ok $match, 'line of music recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
282 is $match, $line, "Entire line was matched";
283 is $match<bar>[0], "g>ecg ec e/f/g/e/ |", "First bar is correct";
284 is $match<bar>[1], " d/c/B/A/ Gd BG B/c/d/B/ |", "Second bar is correct";
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
285 # say $match<ABC::Grammar::line_of_music>.perl;
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
286 }
287
288 {
12b0278 @colomon Allow the hacky |1 and |2 nth repeats.
authored
289 my $line = "g>ecg ec e/f/g/e/ |1 d/c/B/A/ Gd BG B/c/d/B/ |";
290 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
291 isa_ok $match, Match, 'Got a match';
292 ok $match, 'line of music recognized';
293 is $match, $line, "Entire line was matched";
294 is $match<bar>[0], "g>ecg ec e/f/g/e/ |", "First bar is correct";
295 is $match<bar>[1], "1 d/c/B/A/ Gd BG B/c/d/B/ |", "Second bar is correct, even with stupid hacky |1 ending marker";
296 # say $match<ABC::Grammar::line_of_music>.perl;
297 }
298
299 {
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
300 my $line = "|A/B/c/A/ c>d e>deg | dB/A/ gB +trill+A2 +trill+e2 ::";
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
301 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
302 isa_ok $match, Match, 'Got a match';
303 ok $match, 'line of music recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
304 is $match, $line, "Entire line was matched";
305 is $match<bar>[0], "A/B/c/A/ c>d e>deg |", "First bar is correct";
306 is $match<bar>[1], " dB/A/ gB +trill+A2 +trill+e2 ::", "Second bar is correct";
307 is $match<barline>, "|", "Initial barline matched";
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
308 # say $match<ABC::Grammar::line_of_music>.perl;
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
309 }
310
311 {
312 my $line = 'g>ecg ec e/f/g/e/ |[2-3 d/c/B/A/ {Gd} BG B/c/d/B/ |';
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
313 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
314 isa_ok $match, Match, 'Got a match';
315 ok $match, 'line of music recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
316 is $match, $line, "Entire line was matched";
317 is $match<bar>[0], "g>ecg ec e/f/g/e/ |", "First bar is correct";
318 is $match<bar>[1], '[2-3 d/c/B/A/ {Gd} BG B/c/d/B/ |', "Second bar is correct";
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
319 # say $match<ABC::Grammar::line_of_music>.perl;
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
320 }
321
322 {
98189f2 @colomon Add inline_field to the grammar, plus some tests for it.
authored
323 my $match = ABC::Grammar.parse("[K:F]", :rule<inline_field>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
324 isa_ok $match, Match, 'Got a match';
325 ok $match, 'inline field recognized';
98189f2 @colomon Add inline_field to the grammar, plus some tests for it.
authored
326 is $match, "[K:F]", "Entire string was matched";
084141b @colomon Change inline_field to use a different sort of capture, to avoid a no…
authored
327 is $match<alpha>, "K", "Correct field name found";
328 is $match<value>, "F", "Correct field value found";
98189f2 @colomon Add inline_field to the grammar, plus some tests for it.
authored
329 }
330
331 {
f92e603 @colomon Add tests for inline meter changes.
authored
332 my $match = ABC::Grammar.parse("[M:3/4]", :rule<inline_field>);
333 isa_ok $match, Match, 'Got a match';
334 ok $match, 'inline field recognized';
335 is $match, "[M:3/4]", "Entire string was matched";
336 is $match<alpha>, "M", "Correct field name found";
337 is $match<value>, "3/4", "Correct field value found";
338 }
339
340 {
dda7786 @colomon Add the ability to have complete line comments in either the header s…
authored
341 my $match = ABC::Grammar.parse(" % this is a comment", :rule<comment_line>);
342 isa_ok $match, Match, 'Got a match';
343 ok $match, 'comment line recognized';
344 is $match, " % this is a comment", "Entire string was matched";
345 }
346
347 {
348 my $match = ABC::Grammar.parse("% this is a comment", :rule<comment_line>);
349 isa_ok $match, Match, 'Got a match';
350 ok $match, 'comment line recognized';
351 is $match, "% this is a comment", "Entire string was matched";
352 }
353
354 {
98189f2 @colomon Add inline_field to the grammar, plus some tests for it.
authored
355 my $line = "g>ecg ec e/f/g/e/ | d/c/B/A/ [K:F] Gd BG B/c/d/B/ |";
356 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
357 isa_ok $match, Match, 'Got a match';
358 ok $match, 'line of music recognized';
98189f2 @colomon Add inline_field to the grammar, plus some tests for it.
authored
359 is $match, $line, "Entire line was matched";
360 is $match<bar>[0], "g>ecg ec e/f/g/e/ |", "First bar is correct";
361 is $match<bar>[1], " d/c/B/A/ [K:F] Gd BG B/c/d/B/ |", "Second bar is correct";
362 ok @( $match<bar>[1]<element> ).grep("[K:F]"), "Key change got recognized";
363 # say $match<ABC::Grammar::line_of_music>.perl;
364 }
365
366 {
f92e603 @colomon Add tests for inline meter changes.
authored
367 my $line = "g>ecg ec e/f/g/e/ | d/c/B/A/ [M:C] Gd BG B/c/d/B/ |";
368 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
369 isa_ok $match, Match, 'Got a match';
370 ok $match, 'line of music recognized';
371 is $match, $line, "Entire line was matched";
372 is $match<bar>[0], "g>ecg ec e/f/g/e/ |", "First bar is correct";
373 is $match<bar>[1], " d/c/B/A/ [M:C] Gd BG B/c/d/B/ |", "Second bar is correct";
374 ok @( $match<bar>[1]<element> ).grep("[M:C]"), "Meter change got recognized";
375 # say $match<ABC::Grammar::line_of_music>.perl;
376 }
377
378 {
3b36da0 @colomon Add two new tests for with multiple things in brackets in one measure.
authored
379 my $line = "| [K:F] Gd BG [B/c/d/B/]|";
380 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
381 isa_ok $match, Match, 'Got a match';
382 ok $match, 'line of music recognized';
383 is $match, $line, "Entire line was matched";
384 is $match<bar>[0]<element>[1], "[K:F]", "Key signature change is correctly captured";
385 # is $match<bar>[1], " d/c/B/A/ [K:F] Gd BG B/c/d/B/ |", "Second bar is correct";
386 }
387
388 {
389 my $line = 'E2 CE GCEG|c4 B3 ^F|(A2 G2) =F2 D2|C4 {B,C}E2 D>E|[1 (D4 C2) z2:|[2 (D4 C2) z3/2 [G/2D/2]|';
390 my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
391 isa_ok $match, Match, 'Got a match';
392 ok $match, 'line of music recognized';
393 is $match, $line, "Entire line was matched";
394 is $match<bar>[5]<element>[0], "[2", "nth repeat works";
395 }
396
397 {
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
398 my $music = q«A/B/c/A/ +trill+c>d e>deg | GG +trill+B>c d/B/A/G/ B/c/d/B/ |
399 A/B/c/A/ c>d e>deg | dB/A/ gB +trill+A2 +trill+e2 ::
400 g>ecg ec e/f/g/e/ | d/c/B/A/ Gd BG B/c/d/B/ |
401 g/f/e/d/ c/d/e/f/ gc e/f/g/e/ | dB/A/ gB +trill+A2 +trill+e2 :|»;
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
402 my $match = ABC::Grammar.parse($music, :rule<music>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
403 isa_ok $match, Match, 'Got a match';
404 ok $match, 'music recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
405 is $match<line_of_music>.elems, 4, "Four lines matched";
406 }
407
408 {
dda7786 @colomon Add the ability to have complete line comments in either the header s…
authored
409 my $music = q«% Comment
410 X:64
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
411 T:Cuckold Come Out o' the Amrey
412 S:Northumbrian Minstrelsy
413 M:4/4
414 L:1/8
415 K:D
416 »;
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
417 my $match = ABC::Grammar.parse($music, :rule<header>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
418 isa_ok $match, Match, 'Got a match';
419 ok $match, 'header recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
420 is $match<header_field>.elems, 6, "Six fields matched";
421 is $match<header_field>.flat.map({ .<header_field_name> }), "X T S M L K", "Got the right field names";
422 }
423
424 {
425 my $music = q«X:64
426 T:Cuckold Come Out o' the Amrey
427 S:Northumbrian Minstrelsy
428 M:4/4
429 L:1/8
430 K:D
431 A/B/c/A/ +trill+c>d e>deg | GG +trill+B>c d/B/A/G/ B/c/d/B/ |
2d3cd68 @colomon Allow comments everywhere, though they aren't handled properly in the…
authored
432 A/B/c/A/ c>d e>deg | dB/A/ gB +trill+A2 +trill+e2 :: % test comment
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
433 g>ecg ec e/f/g/e/ | d/c/B/A/ Gd BG B/c/d/B/ |
434 g/f/e/d/ c/d/e/f/ gc e/f/g/e/ | dB/A/ gB +trill+A2 +trill+e2 :|
435 »;
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
436 my $match = ABC::Grammar.parse($music, :rule<tune>);
0b42b94 @colomon Patched tests now that I realize that parse returns a Match even on f…
authored
437 isa_ok $match, Match, 'Got a match';
438 ok $match, 'tune recognized';
42c4437 @colomon All tests in 01-regexes.t now pass.
authored
439 given $match<header>
440 {
441 is .<header_field>.elems, 6, "Six fields matched";
442 is .<header_field>.flat.map({ .<header_field_name> }), "X T S M L K", "Got the right field names";
443 }
444 is $match<music><line_of_music>.elems, 4, "Four lines matched";
445 }
97a6ca1 @LastOfTheCarelessMen Make <spacing> do horizontal spacing everywhere. Add <music>.
LastOfTheCarelessMen authored
446
e35d347 @colomon Tweaks to the grammar to support ABC coding mistakes I've gotten away…
authored
447 {
448 my $music = q«X:1
449 T:Are You Coming From The Races?
450 O:from the playing of Frank Maher
451 M:2/4
452 L:1/8
453 R:Single
454 K:D
455 DE|:F2 F2|AF ED|E2 EF|ED DE|F2 F2|AF ED|E2 D2|
acf9f41 @colomon Require [ before repeat number, as per spec. (Helps disambiguate fro…
authored
456 |[1 D2 DE:|[2 D2 dc|:B2 Bc|BA FG|AB AF|
457 AF dc|B2 Bc|BA FA|B2 A2|[1 A2 dc:|[2 A2
e35d347 @colomon Tweaks to the grammar to support ABC coding mistakes I've gotten away…
authored
458
459 X:2
460 T:Bride's Jig
461 O:from the playing of Frank Maher
462 M:2/4
463 L:1/8
464 R:Single
465 K:Edor
466 |:B E2 G|FE D2|E>F GA|Bc BA|B E2 G|FE D2|E>F GE|A2 A2:|
467 |:AB cd|e4|AB cB|BA FA|AB cd|e4|AB cB|A2 A2:|
468 »;
469 my $match = ABC::Grammar.parse($music, :rule<tune_file>);
470 isa_ok $match, Match, 'Got a match';
471 ok $match, 'tune_file recognized';
472
473 is $match<tune>.elems, 2, 'found two tunes';
474 is $match<tune>[0]<music><line_of_music>.elems, 3;
475 is $match<tune>[1]<music><line_of_music>.elems, 2;
476 }
477
363a3dc @colomon Improved handling of music action, additional tests.
authored
478 {
479 my $music = q«X:1
480 T:Are You Coming From The Races?
481 O:from the playing of Frank Maher
482 M:2/4
483 L:1/8
484 R:Single
485 K:D
486 DE|:F2 F2|AF ED|E2 EF|ED DE|F2 F2|AF ED|E2 D2|
487 |[1 D2 DE:|[2 D2 dc|:B2 Bc|BA FG|AB AF|
488 AF dc|B2 Bc|BA FA|B2 A2|[1 A2 dc:|[2 A2
489
490 X:2
491 T:Bride's Jig
492 O:from the playing of Frank Maher
493 M:2/4
494 L:1/8
495 R:Single
496 K:Edor
497 |:B E2 G|FE D2|E>F GA|Bc BA|B E2 G|FE D2|E>F GE|A2 A2:|
498 |:AB cd|e4|AB cB|BA FA|AB cd|e4|AB cB|A2 A2:|»;
499 my $match = ABC::Grammar.parse($music, :rule<tune_file>);
500 isa_ok $match, Match, 'Got a match';
501 ok $match, 'tune_file recognized';
502
503 is $match<tune>.elems, 2, 'found two tunes';
504 is $match<tune>[0]<music><line_of_music>.elems, 3;
505 is $match<tune>[1]<music><line_of_music>.elems, 2;
506 }
507
508 {
509 my $music = q«X:1
510 T:Canon in D
511 C:Pachelbel
512 M:2/2
513 L:1/8
514 K:D
515 "D" DFAd "A" CEAc|"Bm" B,DFB "F#m" A,CFA|"G" B,DGB "D" A,DFA|"G" B,DGB "A" CEAc|
516 "D" f4 "A" e4|"Bm" d4 "F#m" c4|"G" B4 "D" A4|"G" B4 "A" c4|
517 »;
518 my $match = ABC::Grammar.parse($music, :rule<tune_file>);
519 isa_ok $match, Match, 'Got a match';
520 ok $match, 'tune_file recognized';
521
522 is $match<tune>.elems, 1, 'found one tune';
523 is $match<tune>[0]<music><line_of_music>.elems, 2, "with two lines of music";
524 }
525
bda9626 @colomon Switch done_testing to done.
authored
526 done;
Something went wrong with that request. Please try again.