Sha256: 244ea6a9c86eee04cb7980e86a1fae058c6a45634dd05baf91f12b9cf0be1760

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 KB

Contents

#
# specifying raabro
#
# Mon Sep 21 06:55:35 JST 2015
#

require 'spec_helper'


describe Raabro do

  describe '.jseq' do

    it 'parses elts joined by a separator' do

      i = Raabro::Input.new('a,b,c')

      t = Raabro.jseq(:j, i, :cha, :com)

      expect(t.to_a(:leaves => true)).to eq(
        [ :j, 1, 0, 5, nil, :jseq, [
          [ nil, 1, 0, 1, nil, :rex, 'a' ],
          [ nil, 1, 1, 1, nil, :str, ',' ],
          [ nil, 1, 2, 1, nil, :rex, 'b' ],
          [ nil, 1, 3, 1, nil, :str, ',' ],
          [ nil, 1, 4, 1, nil, :rex, 'c' ],
          [ nil, 0, 5, 0, nil, :str, [] ]
        ] ]
      )
      expect(i.offset).to eq(5)
    end

    it 'prunes' do

      i = Raabro::Input.new('a,b,c', :prune => true)

      t = Raabro.jseq(:j, i, :cha, :com)

      expect(t.to_a(:leaves => true)).to eq(
        [ :j, 1, 0, 5, nil, :jseq, [
          [ nil, 1, 0, 1, nil, :rex, 'a' ],
          [ nil, 1, 1, 1, nil, :str, ',' ],
          [ nil, 1, 2, 1, nil, :rex, 'b' ],
          [ nil, 1, 3, 1, nil, :str, ',' ],
          [ nil, 1, 4, 1, nil, :rex, 'c' ]
        ] ]
      )
      expect(i.offset).to eq(5)
    end

    it 'fails when zero elements' do

      i = Raabro::Input.new('')

      t = Raabro.jseq(:j, i, :cha, :com)

      expect(t.to_a(:leaves => true)).to eq(
        [ :j, 0, 0, 0, nil, :jseq, [
          [ nil, 0, 0, 0, nil, :rex, [] ]
        ] ]
      )
      expect(i.offset).to eq(0)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
raabro-1.1.1 spec/jseq_spec.rb
raabro-1.1.0 spec/jseq_spec.rb
raabro-1.0.5 spec/jseq_spec.rb
raabro-1.0.4 spec/jseq_spec.rb
raabro-1.0.3 spec/jseq_spec.rb
raabro-1.0.2 spec/jseq_spec.rb
raabro-1.0.1 spec/jseq_spec.rb
raabro-1.0.0 spec/jseq_spec.rb