Sha256: 04bfdf4f8b1c323c4a1c5783cd3e886ea2d1250e25a7c9d072014d768a181525

Contents?: true

Size: 1.22 KB

Versions: 14

Compression:

Stored size: 1.22 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
    assert_raises ArgumentError, /level/ do
      Parser::Diagnostic.new(:foobar, 'foo', @range1)
    end
  end

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

    diag = Parser::Diagnostic.new(:error, string, @range1, highlights)
    assert diag.frozen?
    assert diag.message.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, 'code far too bad',
                                   location, highlights)
    assert_equal([
      '(string):1:27: error: code far too bad',
      'if (this is some bad code + bugs)',
      '                     ~~~~ ^ ~~~~ '
    ], diag.render)
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
parser-2.1.0.pre1 test/test_diagnostic.rb
parser-2.0.0 test/test_diagnostic.rb
parser-2.0.0.pre8 test/test_diagnostic.rb
parser-2.0.0.pre7 test/test_diagnostic.rb
parser-2.0.0.pre6 test/test_diagnostic.rb
parser-2.0.0.pre5 test/test_diagnostic.rb
parser-2.0.0.pre4 test/test_diagnostic.rb
parser-2.0.0.pre3 test/test_diagnostic.rb
parser-2.0.0.pre2 test/test_diagnostic.rb
parser-2.0.0.pre1 test/test_diagnostic.rb
parser-2.0.0.beta10 test/test_diagnostic.rb
parser-2.0.0.beta9 test/test_diagnostic.rb
parser-2.0.0.beta8 test/test_diagnostic.rb
parser-2.0.0.beta7 test/test_diagnostic.rb