1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/reline/test_kill_ring.rb
aycabta 17350c7e55 Add Reline as a fallback library for Readline
* lib/reine.rb, lib/reline/*: Reline is a readline stdlib compatible
  library.
* lib/readline.rb: Readline uses a fallback to Reline when ext/readline
  doesn't exist.
* tool/sync_default_gems.rb: add ruby/reline as a default gem.
* appveyor.yml: add "set RELINE_TEST_ENCODING=Windows-31J" for test suit
  of Reline, and add "--exclude readline" to "nmake test-all" on Visual
  Studio builds because of strange behavior.
* spec/ruby/library/readline/spec_helper.rb: skip Reline as with
  RbReadline.
2019-04-30 11:44:20 +09:00

256 lines
14 KiB
Ruby

require_relative 'helper'
class Reline::KillRing::Test < Reline::TestCase
def setup
@prompt = '> '
@kill_ring = Reline::KillRing.new
end
def test_append_one
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('a', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('a', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['a', 'a'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['a', 'a'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_two
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('b', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('b', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['a', 'b'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['b', 'a'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_three
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('c')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('c', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('c', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['b', 'c'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['a', 'b'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['c', 'a'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_three_with_max_two
@kill_ring = Reline::KillRing.new(2)
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('c')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('c', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('c', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['b', 'c'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['c', 'b'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['b', 'c'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_four_with_max_two
@kill_ring = Reline::KillRing.new(2)
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('c')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('d')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('d', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('d', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['c', 'd'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['d', 'c'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['c', 'd'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_after
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('ab', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('ab', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['ab', 'ab'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['ab', 'ab'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_before
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b', true)
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('ba', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('ba', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['ba', 'ba'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['ba', 'ba'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_chain_two
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('c')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('d')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('cd', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('cd', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['ab', 'cd'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['cd', 'ab'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
def test_append_complex_chain
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('c')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('d')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('b', true)
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('e')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('a', true)
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::FRESH, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('A')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
@kill_ring.append('B')
assert_equal(Reline::KillRing::State::CONTINUED, @kill_ring.instance_variable_get(:@state))
@kill_ring.process
assert_equal(Reline::KillRing::State::PROCESSED, @kill_ring.instance_variable_get(:@state))
assert_equal('AB', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal('AB', @kill_ring.yank)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['abcde', 'AB'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
assert_equal(['AB', 'abcde'], @kill_ring.yank_pop)
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
end
end