[ruby/irb] Remove duplicated TestInputMethod definitions

4b831d02e1
This commit is contained in:
st0012 2022-11-13 11:19:40 +00:00 committed by git
parent 1a9e87fe3a
commit 1eae15142f
4 changed files with 29 additions and 83 deletions

View file

@ -2,6 +2,32 @@ require "test/unit"
module TestIRB module TestIRB
class TestCase < Test::Unit::TestCase class TestCase < Test::Unit::TestCase
class TestInputMethod < ::IRB::InputMethod
attr_reader :list, :line_no
def initialize(list = [])
super("test")
@line_no = 0
@list = list
end
def gets
@list[@line_no]&.tap {@line_no += 1}
end
def eof?
@line_no >= @list.size
end
def encoding
Encoding.default_external
end
def reset
@line_no = 0
end
end
def save_encodings def save_encodings
@default_encoding = [Encoding.default_external, Encoding.default_internal] @default_encoding = [Encoding.default_external, Encoding.default_internal]
@stdio_encodings = [STDIN, STDOUT, STDERR].map {|io| [io.external_encoding, io.internal_encoding] } @stdio_encodings = [STDIN, STDOUT, STDERR].map {|io| [io.external_encoding, io.internal_encoding] }

View file

@ -6,32 +6,6 @@ require_relative "helper"
module TestIRB module TestIRB
class ExtendCommandTest < TestCase class ExtendCommandTest < TestCase
class TestInputMethod < ::IRB::InputMethod
attr_reader :list, :line_no
def initialize(list = [])
super("test")
@line_no = 0
@list = list
end
def gets
@list[@line_no]&.tap {@line_no += 1}
end
def eof?
@line_no >= @list.size
end
def encoding
Encoding.default_external
end
def reset
@line_no = 0
end
end
def setup def setup
@pwd = Dir.pwd @pwd = Dir.pwd
@tmpdir = File.join(Dir.tmpdir, "test_reline_config_#{$$}") @tmpdir = File.join(Dir.tmpdir, "test_reline_config_#{$$}")

View file

@ -7,32 +7,6 @@ require_relative "helper"
module TestIRB module TestIRB
class TestContext < TestCase class TestContext < TestCase
class TestInputMethod < ::IRB::InputMethod
attr_reader :list, :line_no
def initialize(list = [])
super("test")
@line_no = 0
@list = list
end
def gets
@list[@line_no]&.tap {@line_no += 1}
end
def eof?
@line_no >= @list.size
end
def encoding
Encoding.default_external
end
def reset
@line_no = 0
end
end
def setup def setup
IRB.init_config(nil) IRB.init_config(nil)
IRB.conf[:USE_SINGLELINE] = false IRB.conf[:USE_SINGLELINE] = false

View file

@ -15,38 +15,10 @@ module TestIRB
IRB.conf[:RC_NAME_GENERATOR] = nil IRB.conf[:RC_NAME_GENERATOR] = nil
end end
class TestInputMethod < ::IRB::InputMethod class TestInputMethodWithHistory < TestInputMethod
HISTORY = Array.new HISTORY = Array.new
include IRB::HistorySavingAbility include IRB::HistorySavingAbility
attr_reader :list, :line_no
def initialize(list = [])
super("test")
@line_no = 0
@list = list
end
def gets
@list[@line_no]&.tap {@line_no += 1}
end
def eof?
@line_no >= @list.size
end
def encoding
Encoding.default_external
end
def reset
@line_no = 0
end
def winsize
[10, 20]
end
end end
def test_history_save_1 def test_history_save_1
@ -167,7 +139,7 @@ module TestIRB
IRB.conf[:SAVE_HISTORY] = 1 IRB.conf[:SAVE_HISTORY] = 1
Dir.mktmpdir("test_irb_history_") do |tmpdir| Dir.mktmpdir("test_irb_history_") do |tmpdir|
ENV["HOME"] = tmpdir ENV["HOME"] = tmpdir
io = TestInputMethod.new io = TestInputMethodWithHistory.new
io.class::HISTORY.clear io.class::HISTORY.clear
io.load_history io.load_history
io.class::HISTORY.concat(%w"line1 line2") io.class::HISTORY.concat(%w"line1 line2")
@ -198,7 +170,7 @@ module TestIRB
f.write(initial_irb_history) f.write(initial_irb_history)
end end
io = TestInputMethod.new io = TestInputMethodWithHistory.new
io.class::HISTORY.clear io.class::HISTORY.clear
io.load_history io.load_history
if block_given? if block_given?