spec/eseq_spec.rb in raabro-1.0.5 vs spec/eseq_spec.rb in raabro-1.1.0

- old
+ new

@@ -47,15 +47,30 @@ ] ] ) expect(i.offset).to eq(5) end + it 'parses <>' do + + i = Raabro::Input.new('<>', :prune => true) + + t = Raabro.eseq(:list, i, :lt, :cha, :com, :gt) + + expect(t.to_a(:leaves => true)).to eq( + [ :list, 1, 0, 2, nil, :eseq, [ + [ nil, 1, 0, 1, nil, :str, '<' ], + [ nil, 1, 1, 1, nil, :str, '>' ] + ] ] + ) + expect(i.offset).to eq(2) + end + context 'no start parser' do it 'parses successfully' do - i = Raabro::Input.new('a,b>') + i = Raabro::Input.new('a,b>', prune: false) t = Raabro.eseq(:list, i, nil, :cha, :com, :gt) expect(t.to_a(:leaves => true)).to eq( [ :list, 1, 0, 4, nil, :eseq, [ @@ -82,11 +97,11 @@ [ :list, 1, 0, 4, nil, :eseq, [ [ nil, 1, 0, 1, nil, :str, '<' ], [ nil, 1, 1, 1, nil, :rex, 'a' ], [ nil, 1, 2, 1, nil, :str, ',' ], [ nil, 1, 3, 1, nil, :rex, 'b' ], - [ nil, 0, 4, 0, nil, :str, [] ], + [ nil, 0, 4, 0, nil, :str, [] ] ] ] ) expect(i.offset).to eq(4) end @@ -103,9 +118,48 @@ [ nil, 1, 2, 1, nil, :str, ',' ], [ nil, 1, 3, 1, nil, :rex, 'b' ] ] ] ) expect(i.offset).to eq(4) + end + end + + context 'no progress' do + + it 'parses <>' do + + i = Raabro::Input.new('<>', :prune => true) + + t = arr(i) + + expect(t.to_a(:leaves => true)).to eq( + [ nil, 1, 0, 2, nil, :eseq, [ + [ nil, 1, 0, 1, nil, :str, '<' ], + [ nil, 1, 1, 0, nil, :rex, '' ], + [ nil, 1, 1, 1, nil, :str, '>' ] + ] ] + ) + expect(i.offset).to eq(2) + end + + it 'parses <a,,a>' do + + i = Raabro::Input.new('<a,,a>', :prune => true) + + t = arr(i) + + expect(t.to_a(:leaves => true)).to eq( + [ nil, 1, 0, 6, nil, :eseq, [ + [ nil, 1, 0, 1, nil, :str, '<' ], + [ nil, 1, 1, 1, nil, :rex, 'a' ], + [ nil, 1, 2, 1, nil, :rex, ',' ], + [ nil, 1, 3, 0, nil, :rex, '' ], + [ nil, 1, 3, 1, nil, :rex, ',' ], + [ nil, 1, 4, 1, nil, :rex, 'a' ], + [ nil, 1, 5, 1, nil, :str, '>' ] + ] ] + ) + expect(i.offset).to eq(6) end end end end