Sha256: 6c99078c39c6c6406c32aa5274227a16203527a4db020d4236b8a78132d03d5b

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'
module Sexpr::Parser
  describe Citrus, "parse" do

    let(:parser){ Citrus.new(bool_expr_parser) }

    it 'delegates the call to the Citrus parser' do
      parser.parse("true").should be_a(::Citrus::Match)
    end

    it 'is idempotent' do
      parser.parse(parser.parse("true")).should be_a(::Citrus::Match)
    end

    it 'raises a Citrus::ParserError when parsing fails' do
      lambda{
        parser.parse("bl and or")
      }.should raise_error(::Citrus::ParseError)
    end

    it 'recognizes the :root option' do
      parser.parse("true", :root => :bool_lit).should be_a(::Citrus::Match)
      parser.parse("x", :root => :var_ref).should be_a(::Citrus::Match)
      lambda{
        parser.parse("x", :root => :bool_lit)
      }.should raise_error(::Citrus::ParseError)
    end

    it 'recognizes the :consume option' do
      lambda{
        parser.parse("true or")
      }.should raise_error(::Citrus::ParseError)
      parser.parse("true or", :consume => false).should eq("true")
    end

    it 'can parse from a Path' do
      Path.tmpfile do |tmp|
        tmp.write "x and y"
        parser.parse(tmp).should be_a(::Citrus::Match)
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sexpr-1.1.0 spec/unit/parser/citrus/test_parse.rb
sexpr-1.0.0 spec/unit/parser/citrus/test_parse.rb
sexpr-0.6.0 spec/unit/parser/citrus/test_parse.rb
sexpr-0.5.1 spec/parser/citrus/test_parse.rb
sexpr-0.5.0 spec/parser/citrus/test_parse.rb
sexpr-0.4.0 spec/parser/citrus/test_parse.rb