File: test_source_rewriter_action.rb

package info (click to toggle)
ruby-whitequark-parser 3.3.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,828 kB
  • sloc: yacc: 40,699; ruby: 20,395; makefile: 12; sh: 8
file content (46 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'helper'

class TestSourceRewriterAction < Minitest::Test
  def setup
    @buf = Parser::Source::Buffer.new('(rewriter_action)',
      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