Sha256: e47ef280dc729fe744d3ec375668372734ee0ec634c867433ee84957f8e51c90

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'test_helper')

class GrammarCompilerTest < Screw::Unit::TestCase
  
  def setup
    @compiler = Compiler::GrammarCompiler.new
    @source_path = File.join(File.dirname(__FILE__), 'test_grammar.treetop')
    @target_path = File.join(File.dirname(__FILE__), 'test_grammar.rb')
    @alternate_target_path = File.join(File.dirname(__FILE__), 'test_grammar_alt.rb')
    delete_target_files
  end
  
  def teardown
    delete_target_files
    Object.class_eval do
      remove_const(:Test) if const_defined?(:Test)
    end
  end
  
  test "compilation of a single file to a default file name" do
    assert !File.exists?(@target_path)
    @compiler.compile(@source_path)
    assert File.exists?(@target_path)
    require @target_path
    Test::GrammarParser.new.parse('foo').should be_success
  end
  
  test "compilation of a single file to an explicit file name" do
    assert !File.exists?(@alternate_target_path)
    @compiler.compile(@source_path, @alternate_target_path)
    assert File.exists?(@alternate_target_path)
    require @alternate_target_path
    Test::GrammarParser.new.parse('foo').should be_success
  end
  
  test "compilation of a single file without writing it to an output file" do
    @compiler.ruby_source(@source_path).should_not be_nil
  end

  test "load_grammar compiles and evaluates source grammar with extension" do    
    load_grammar @source_path
    Test::GrammarParser.new.parse('foo').should be_success
  end

  test "load_grammar compiles and evaluates source grammar with no extension" do
    path_without_extension = @source_path.gsub(/\.treetop\Z/, '')
    load_grammar path_without_extension
    Test::GrammarParser.new.parse('foo').should be_success
  end
  
  
  def delete_target_files
    File.delete(@target_path) if File.exists?(@target_path)
    File.delete(@alternate_target_path) if File.exists?(@alternate_target_path)
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
treetop-1.1.2 test/compiler/grammar_compiler_test.rb
treetop-1.0.2 test/compiler/grammar_compiler_test.rb
treetop-1.1.0 test/compiler/grammar_compiler_test.rb
treetop-1.1.1 test/compiler/grammar_compiler_test.rb
treetop-1.0.0 test/compiler/grammar_compiler_test.rb
treetop-1.0.1 test/compiler/grammar_compiler_test.rb