Sha256: 4d0858cc42afa9cdf7c02c6316a27509fdf3dacf88c0c10821dd9b31cb641257

Contents?: true

Size: 1.25 KB

Versions: 13

Compression:

Stored size: 1.25 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, :escape_eof, @range1)
    end
  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

13 entries across 13 versions & 1 rubygems

Version Path
parser-2.2.0.pre.2 test/test_diagnostic.rb
parser-2.2.0.pre.1 test/test_diagnostic.rb
parser-2.1.9 test/test_diagnostic.rb
parser-2.1.8 test/test_diagnostic.rb
parser-2.1.7 test/test_diagnostic.rb
parser-2.1.6 test/test_diagnostic.rb
parser-2.1.5 test/test_diagnostic.rb
parser-2.1.4 test/test_diagnostic.rb
parser-2.1.3 test/test_diagnostic.rb
parser-2.1.2 test/test_diagnostic.rb
parser-2.1.1 test/test_diagnostic.rb
parser-2.1.0 test/test_diagnostic.rb
parser-2.1.0.pre2 test/test_diagnostic.rb