Sha256: 04750b5960abe813bd9cedccbe554c98af094ecc1385633bc2ffa1692787ba62

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'
module Sexpr
  class Processor
    describe SexprCoercions do

      let(:helper){
        SexprCoercions.new
      }
      let(:processor){
        Rewriter.new
      }

      it 'extends input sexprs' do
        sexpr = [:hello, "world"]
        seen = helper.call(processor, sexpr) do |_,n|
          n.should be_a(Sexpr)
          n
        end
        seen.should eq(sexpr)
      end

      it 'extends output sexprs' do
        sexpr = [:hello, "world"]
        seen = helper.call(processor, sexpr) do |_,n|
          n.should be_a(Sexpr)
          [:result]
        end
        seen.should eq([:result])
        seen.should be_a(Sexpr)
      end

      it 'does not require the output to be a sexpr' do
        sexpr = [:hello, "world"]
        seen = helper.call(processor, sexpr) do |_,n|
          n.should be_a(Sexpr)
          "blah"
        end
        seen.should eq("blah")
        seen.should_not be_a(Sexpr)
      end

      it 'fails with a string, unless the underlying grammar may parse' do
        lambda{
          helper.call(processor, "blah") do |_,n| end
        }.should raise_error(NoParserError)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sexpr-1.1.0 spec/unit/processor/test_sexpr_coercions.rb
sexpr-1.0.0 spec/unit/processor/test_sexpr_coercions.rb
sexpr-0.6.0 spec/unit/processor/test_sexpr_coercions.rb