Sha256: 951af5a6de59536c57a9c9bd86e2354d5c71464fa9087fcb1ab8d6d994596665

Contents?: true

Size: 1.37 KB

Versions: 56

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

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, :invalid_escape, @buffer, 1..2)
    @engine.process(warn)

    assert_equal [warn], @queue
  end

  def test_ignore_warnings
    @engine.ignore_warnings = true

    warn = Parser::Diagnostic.new(:warning, :invalid_escape, @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, :invalid_escape, @buffer, 1..2)

    err = assert_raises Parser::SyntaxError 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, :invalid_escape, @buffer, 1..2)
    @engine.process(error)

    assert_equal [error], @queue
  end

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

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

    assert_equal [fatal], @queue
  end
end

Version data entries

56 entries across 43 versions & 8 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/parser-2.7.0.2/test/test_diagnostic_engine.rb
parser-2.7.1.2 test/test_diagnostic_engine.rb
parser-2.7.1.1 test/test_diagnostic_engine.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/parser-2.7.1.0/test/test_diagnostic_engine.rb
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.0/test/test_diagnostic_engine.rb
parser-2.7.1.0 test/test_diagnostic_engine.rb
parser-2.7.0.5 test/test_diagnostic_engine.rb
parser-2.7.0.4 test/test_diagnostic_engine.rb
parser-2.7.0.3 test/test_diagnostic_engine.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/parser-2.7.0.2/test/test_diagnostic_engine.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/parser-2.7.0.2/test/test_diagnostic_engine.rb
parser-2.7.0.2 test/test_diagnostic_engine.rb
parser-2.7.0.1 test/test_diagnostic_engine.rb
parser-2.7.0.0 test/test_diagnostic_engine.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/parser-2.6.3.0/test/test_diagnostic_engine.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/parser-2.6.4.1/test/test_diagnostic_engine.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/parser-2.6.5.0/test/test_diagnostic_engine.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/parser-2.6.3.0/test/test_diagnostic_engine.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/parser-2.6.4.1/test/test_diagnostic_engine.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/parser-2.6.5.0/test/test_diagnostic_engine.rb