Sha256: 7cc752800e41661a78340432471c1c98544fef18069c9645e8acb6d16ac97d40

Contents?: true

Size: 1.89 KB

Versions: 16

Compression:

Stored size: 1.89 KB

Contents

require_relative '../../spec_helper'

require_relative '../../../lib/rley/parser/gfg_earley_parser'
require_relative '../../../lib/rley/syntax/grammar_builder'
require_relative '../support/grammar_helper'
require_relative '../support/grammar_abc_helper'
require_relative '../support/expectation_helper'

# Load the class under test
require_relative '../../../lib/rley/parser/parse_tree_factory'

module Rley # Open this namespace to avoid module qualifier prefixes
  module Parser
    describe ParseTreeFactory do
      include GrammarHelper     # Mix-in with token factory method
      include ExpectationHelper # Mix-in with expectation on parse entry sets
      include GrammarABCHelper  # Mix-in for a sample grammar

      let(:sample_grammar) do
        builder = grammar_abc_builder
        builder.grammar
      end

      let(:sample_tokens) do
        build_token_sequence(%w[a b c], sample_grammar)
      end

      let(:sample_result) do
        parser = Parser::GFGEarleyParser.new(sample_grammar)
        parser.parse(sample_tokens)
      end


      subject do
        ParseTreeFactory.new(sample_result)
      end

      # Emit a text representation of the current path.
      def path_to_s()
        text_parts = subject.curr_path.map do |path_element|
          path_element.to_string(0)
        end
        return text_parts.join('/')
      end


      context 'Initialization:' do
        it 'should be created with a GFGParsing' do
          expect { ParseTreeFactory.new(sample_result) }.not_to raise_error
        end

        it 'should know the parse result' do
          expect(subject.parsing).to eq(sample_result)
        end
      end

      context 'Parse tree construction' do
        it 'should build a parse tree' do
          forest = subject.create
          expect(forest).to be_kind_of(PTree::ParseTree)
        end
      end # context
    end # describe
  end # module
end # module
# End of file

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rley-0.5.14 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.13 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.12 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.11 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.10 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.09 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.08 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.07 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.06 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.05 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.04 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.03 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.02 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.01 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.5.00 spec/rley/parser/parse_tree_factory_spec.rb
rley-0.4.08 spec/rley/parser/parse_tree_factory_spec.rb