diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 7cf3dce..f1bfe50 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -176,7 +176,7 @@ def parsed_value(input) durations += ['thirtysecond','thirty-second','sixtyfourth','sixty-fourth'] for base_duration in durations do for multiplier in -2..2 do - for modifier in [nil, 't', '.', '.t', 't.', '..', '...'] do + for modifier in [nil, 't', '.', '.t', 't.', '..', '...', 't.t.t'] do duration = Duration.new(multiplier, base_duration, modifier) @parser.parse("#{multiplier}#{base_duration}#{modifier}").value.should == duration if multiplier == 1 then @@ -187,7 +187,7 @@ def parsed_value(input) end end end - end + end it 'should parse numerical durations' do for duration in [0, 50, 100, 5000, -25] do @@ -347,7 +347,7 @@ def parsed_value(input) describe 'Chains' do - it 'should parse bare chains' do + it 'should parse simple chains' do tree = @parser.parse '0:1:2:3' tree.class.should == ChainNode tree.children.length.should == 4 @@ -355,6 +355,53 @@ def parsed_value(input) item.value.should == index end end + + it 'should parse heterogenous chains' do + @parser.parse '4:5:C4' + @parser.parse 'C4:mf:q.' + @parser.parse '[C4 E4]:fff' + @parser.parse '(4 5):(6 7)' + end + end + + describe 'Other Constructs' do + + it 'should parse choices' do + @parser.parse '4|5 | C4' + @parser.parse 'C4|mf|q.' + @parser.parse '[C4 E4]|fff' + @parser.parse '(4 5)|(6 7)' + end + + it 'should parse simple foreach loops' do + @parser.parse '(1 2)@(3 4)' + @parser.parse '(1 $ 2)@(3 4)' + end + + it 'should parse chained foreach loops' do + @parser.parse '(1 2)@(3 4)@(5 6)' + end + + it 'should parse nested foreach loops' do + @parser.parse '((1 2)@(3 4))@(5 6)' + @parser.parse '((1 $ 2 $$)@(3 4 $))@(5 6)' + end + + it 'should parse variable assignments and usages' do + @parser.parse '$X=1 2 3 4; $X' + @parser.parse '$X=1 2 3 4; $Y=5; $X $Y' + end + + it 'should parse labels' do # DEPRECATED + @parser.parse '#label:5' + @parser.parse '#1:c:mf' + @parser.parse '#env:[1 250 1 500 0 250]' + end + + it 'should parse parallel sequences' do + @parser.parse 'a == b' + @parser.parse 'a b c == c d e' + end end diff --git a/test/test_parser.rb b/test/test_parser.rb deleted file mode 100644 index ddd3a64..0000000 --- a/test/test_parser.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'test/unit' -$:.unshift File.dirname(__FILE__)+'/../lib' -require 'cosy' - -# These tests check that the grammar and parser accept -# the input that they was designed to accept. - -class TestParser < Test::Unit::TestCase - include Cosy - PARSER = SequenceParser.new - - def parse input - output = PARSER.parse(input) - assert_not_nil(output, - "Failed to parse: #{input}\n" + - "(#{PARSER.failure_line},#{PARSER.failure_column}): #{PARSER.failure_reason}") - return output - end - - def assert_failure invalid_syntax - assert_raises(RuntimeError) { PARSER.parse(invalid_syntax) } - end - - - - - def test_negative_duration_multiplier - DURATION.keys.each_with_index do |dur,index| - parse "-#{index}#{dur}" - parse "-#{index}#{dur.upcase}" if dur.length == 1 - end - end - - def test_negative_duration - DURATION.keys.each_with_index do |dur,index| - parse '-' + dur - parse '-' + dur.upcase if dur.length == 1 - end - end - - def test_multiplier_triplet_dotted_durations - %w{ .t t. ..t .t. t.. tt. t.t .tt ..t.tt...t.t }.each_with_index do |mod,index| - DURATION.keys.each do |dur| - parse index.to_s + dur + 't' + mod - parse index.to_s + dur.upcase + 't' + mod if dur.upcase == 1 - end - end - end - - - - def test_element_chain - parse '4:5:C4' - parse 'C4:mf:q.' - parse '[C4 E4]:fff' - parse '(4 5):(6 7)' - end - - def test_element_choice - parse '4|5 | C4' - parse 'C4|mf|q.' - parse '[C4 E4]|fff' - parse '(4 5)|(6 7)' - end - - def test_foreach - parse '(1 2)@(3 4)' - parse '(1 $ 2)@(3 4)' - end - - def test_multi_foreach - parse '(1 2)@(3 4)@(5 6)' - end - - def test_nested_foreach - parse '((1 2)@(3 4))@(5 6)' - parse '((1 $ 2 $$)@(3 4 $))@(5 6)' - end - - def test_assign_variable - parse '$X=1 2 3 4; $X' - parse '$X=1 2 3 4; $Y=5; $X $Y' - end - - def test_label - parse '#label:5' - parse '#1:c:mf' - parse '#env:[1 250 1 500 0 250]' - end - - def test_parallel - parse 'a == b' - end - -end \ No newline at end of file