Sha256: 0dcab65686267f346c4ffc53335a360966cb2dcca811192079877f8754c18962

Contents?: true

Size: 1.29 KB

Versions: 24

Compression:

Stored size: 1.29 KB

Contents

require 'helper'

class TestDiagnostic < Minitest::Test
  def setup
    @buffer = Parser::Source::Buffer.new('(string)')
    @buffer.source = 'if (this is some bad code + bugs)'

    @range1 = Parser::Source::Range.new(@buffer, 0, 2) # if
    @range2 = Parser::Source::Range.new(@buffer, 4, 8) # this
  end

  def test_verifies_levels
    error = assert_raises ArgumentError do
      Parser::Diagnostic.new(:foobar, :escape_eof, {}, @range1)
    end

    assert_match /level/, error.message
  end

  def test_freezes
    string     = 'foo'
    highlights = [@range2]

    diag = Parser::Diagnostic.new(:error, :escape_eof, @range1, highlights)
    assert diag.frozen?
    assert diag.arguments.frozen?
    assert diag.highlights.frozen?

    refute string.frozen?
    refute highlights.frozen?
  end

  def test_render
    location = Parser::Source::Range.new(@buffer, 26, 27)

    highlights = [
      Parser::Source::Range.new(@buffer, 21, 25),
      Parser::Source::Range.new(@buffer, 28, 32)
    ]

    diag  = Parser::Diagnostic.new(:error, :unexpected, { :character => '+' },
                                   location, highlights)
    assert_equal([
      "(string):1:27: error: unexpected `+'",
      'if (this is some bad code + bugs)',
      '                     ~~~~ ^ ~~~~ '
    ], diag.render)
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
parser-2.3.0.pre.4 test/test_diagnostic.rb
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/parser-2.2.0.pre.4/test/test_diagnostic.rb
parser-2.3.0.pre.3 test/test_diagnostic.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/parser-2.2.0.pre.4/test/test_diagnostic.rb
parser-2.2.3.0 test/test_diagnostic.rb
parser-2.2.2.6 test/test_diagnostic.rb
parser-2.3.0.pre.2 test/test_diagnostic.rb
parser-2.3.0.pre.1 test/test_diagnostic.rb
parser-2.2.2.5 test/test_diagnostic.rb
parser-2.2.2.3 test/test_diagnostic.rb
parser-2.2.2.2 test/test_diagnostic.rb
parser-2.2.2.1 test/test_diagnostic.rb
parser-2.2.2.0 test/test_diagnostic.rb
parser-2.2.0.4 test/test_diagnostic.rb
parser-2.2.0.3 test/test_diagnostic.rb
parser-2.2.0.2 test/test_diagnostic.rb
parser-2.2.0.1 test/test_diagnostic.rb
parser-2.2.0 test/test_diagnostic.rb
parser-2.2.0.pre.8 test/test_diagnostic.rb
parser-2.2.0.pre.7 test/test_diagnostic.rb