Sha256: 93e5d56a7904917287469e98db809eb639f6a7bdc53659324a3d8d41032a0d37

Contents?: true

Size: 1.01 KB

Versions: 82

Compression:

Stored size: 1.01 KB

Contents

require 'helper'

class TestSourceRewriterAction < Minitest::Test
  def setup
    @buf = Parser::Source::Buffer.new('(rewriter_action)')
    @buf.source = 'foo bar baz'
  end

  def range(from, len)
    Parser::Source::Range.new(@buf, from, from + len)
  end

  def action(range, replacement)
    Parser::Source::Rewriter::Action.new(range, replacement)
  end

  def test_accessors
    action = action(range(1, 10), 'foo')

    assert action.frozen?
    assert_equal range(1, 10), action.range
    assert_equal 'foo',        action.replacement
  end

  def test_to_s_replace
    action = action(range(3, 1), 'foo')
    assert_equal "replace 1 character(s) with \"foo\"", action.to_s
  end

  def test_to_s_insert
    action = action(range(3, 0), 'foo')
    assert_equal "insert \"foo\"", action.to_s
  end

  def test_to_s_remove
    action = action(range(3, 2), '')
    assert_equal 'remove 2 character(s)', action.to_s
  end

  def test_to_s_nop
    action = action(range(3, 0), '')
    assert_equal 'do nothing', action.to_s
  end
end

Version data entries

82 entries across 82 versions & 5 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/parser-2.4.0.2/test/test_source_rewriter_action.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/parser-2.4.0.2/test/test_source_rewriter_action.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/test/test_source_rewriter_action.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/test/test_source_rewriter_action.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/test/test_source_rewriter_action.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/test/test_source_rewriter_action.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.0/test/test_source_rewriter_action.rb
parser-2.4.0.2 test/test_source_rewriter_action.rb
parser-2.4.0.1 test/test_source_rewriter_action.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/parser-2.4.0.0/test/test_source_rewriter_action.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/parser-2.4.0.0/test/test_source_rewriter_action.rb
parser-2.4.0.0 test/test_source_rewriter_action.rb
parser-2.3.3.1 test/test_source_rewriter_action.rb
parser-2.3.3.0 test/test_source_rewriter_action.rb
parser-2.3.2.0 test/test_source_rewriter_action.rb
parser-2.3.1.4 test/test_source_rewriter_action.rb
parser-2.3.1.3 test/test_source_rewriter_action.rb
erruby_parser-2.3.1.2 test/test_source_rewriter_action.rb
parser-2.3.1.2 test/test_source_rewriter_action.rb
parser-2.3.1.1 test/test_source_rewriter_action.rb