Sha256: af4bacd4ce220e7e1a9608c032cf60e3e38e09a74005a59087bed943eded3c43

Contents?: true

Size: 1.61 KB

Versions: 6

Compression:

Stored size: 1.61 KB

Contents

require 'helper'

class TestSourceRange < MiniTest::Unit::TestCase
  def setup
    @sfile = Parser::Source::Buffer.new('(string)')
    @sfile.source = "foobar\nbaz"
  end

  def test_initialize
    sr = Parser::Source::Range.new(@sfile, 1, 2)
    assert_equal 1, sr.begin_pos
    assert_equal 2, sr.end_pos
    assert sr.frozen?
  end

  def test_size
    sr = Parser::Source::Range.new(@sfile, 1, 3)
    assert_equal 2, sr.size
  end

  def test_join
    sr1 = Parser::Source::Range.new(@sfile, 1, 2)
    sr2 = Parser::Source::Range.new(@sfile, 5, 8)
    sr = sr1.join(sr2)

    assert_equal 1, sr.begin_pos
    assert_equal 8, sr.end_pos
  end

  def test_line
    sr = Parser::Source::Range.new(@sfile, 7, 8)
    assert_equal 2, sr.line
  end

  def test_source_line
    sr = Parser::Source::Range.new(@sfile, 7, 8)
    assert_equal "baz", sr.source_line
  end

  def test_columns
    sr = Parser::Source::Range.new(@sfile, 7, 8)
    assert_equal 0, sr.begin.column
    assert_equal 1, sr.end.column
    assert_equal 0...1, sr.column_range
  end

  def test_begin_end
    sr = Parser::Source::Range.new(@sfile, 1, 5)

    sr_beg = sr.begin
    assert_equal 1, sr_beg.begin_pos
    assert_equal 1, sr_beg.end_pos

    sr_end = sr.end
    assert_equal 5, sr_end.begin_pos
    assert_equal 5, sr_end.end_pos
  end

  def test_to_source
    sr = Parser::Source::Range.new(@sfile, 0, 3)
    assert_equal "foo", sr.to_source

    sr_multi = Parser::Source::Range.new(@sfile, 0, 10)
    assert_equal "foobar\nbaz", sr_multi.to_source
  end

  def test_to_s
    sr = Parser::Source::Range.new(@sfile, 8, 9)
    assert_equal "(string):2:2", sr.to_s
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
parser-1.4.2 test/test_source_range.rb
parser-1.4.1 test/test_source_range.rb
parser-1.4.0 test/test_source_range.rb
parser-1.3.4 test/test_source_range.rb
parser-1.3.3 test/test_source_range.rb
parser-1.3.2 test/test_source_range.rb