Sha256: 6a6bef3b31b22943141eef3b1a6193e820125607485735b4f9ec5714b47de815

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

require 'helper'

class TestDiagnosticEngine < Minitest::Test
  def setup
    @buffer  = Parser::Source::Buffer.new('(source)')
    @buffer.source = 'foobar'

    @engine = Parser::Diagnostic::Engine.new

    @queue  = []
    @engine.consumer = lambda { |diag| @queue << diag }
  end

  def test_process_warnings
    warn = Parser::Diagnostic.new(:warning, 'foo', @buffer, 1..2)
    @engine.process(warn)

    assert_equal [warn], @queue
  end

  def test_ignore_warnings
    @engine.ignore_warnings = true

    warn = Parser::Diagnostic.new(:warning, 'foo', @buffer, 1..2)
    @engine.process(warn)

    assert_equal [], @queue
  end

  def test_all_errors_are_fatal
    @engine.all_errors_are_fatal = true

    error = Parser::Diagnostic.new(:error, 'foo', @buffer, 1..2)

    err = assert_raises Parser::SyntaxError, "foo" do
      @engine.process(error)
    end

    assert_equal error, err.diagnostic

    assert_equal [error], @queue
  end

  def test_all_errors_are_collected
    error = Parser::Diagnostic.new(:error, 'foo', @buffer, 1..2)
    @engine.process(error)

    assert_equal [error], @queue
  end

  def test_fatal_error
    fatal = Parser::Diagnostic.new(:fatal, 'foo', @buffer, 1..2)

    assert_raises Parser::SyntaxError do
      @engine.process(fatal)
    end

    assert_equal [fatal], @queue
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
parser-2.1.0.pre1 test/test_diagnostic_engine.rb
parser-2.0.0 test/test_diagnostic_engine.rb
parser-2.0.0.pre8 test/test_diagnostic_engine.rb
parser-2.0.0.pre7 test/test_diagnostic_engine.rb
parser-2.0.0.pre6 test/test_diagnostic_engine.rb
parser-2.0.0.pre5 test/test_diagnostic_engine.rb
parser-2.0.0.pre4 test/test_diagnostic_engine.rb
parser-2.0.0.pre3 test/test_diagnostic_engine.rb
parser-2.0.0.pre2 test/test_diagnostic_engine.rb