summaryrefslogtreecommitdiff
path: root/test/irb
diff options
context:
space:
mode:
authorst0012 <stan001212@gmail.com>2022-11-13 11:19:40 +0000
committergit <svn-admin@ruby-lang.org>2022-11-15 10:07:32 +0000
commit1eae15142f0fd9e5285e3d685bb1448f0f441b1c (patch)
tree8d123773cd6dbf4ce160526d8961b7d99e75ff32 /test/irb
parent1a9e87fe3a0bb8a4a16e34997371b1823557202d (diff)
[ruby/irb] Remove duplicated TestInputMethod definitions
https://github.com/ruby/irb/commit/4b831d02e1
Diffstat (limited to 'test/irb')
-rw-r--r--test/irb/helper.rb26
-rw-r--r--test/irb/test_cmd.rb26
-rw-r--r--test/irb/test_context.rb26
-rw-r--r--test/irb/test_history.rb34
4 files changed, 29 insertions, 83 deletions
diff --git a/test/irb/helper.rb b/test/irb/helper.rb
index 15d5dafc57..a1dced0978 100644
--- a/test/irb/helper.rb
+++ b/test/irb/helper.rb
@@ -2,6 +2,32 @@ require "test/unit"
module TestIRB
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
@default_encoding = [Encoding.default_external, Encoding.default_internal]
@stdio_encodings = [STDIN, STDOUT, STDERR].map {|io| [io.external_encoding, io.internal_encoding] }
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index 3af4ccec98..c2e8cc1774 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -6,32 +6,6 @@ require_relative "helper"
module TestIRB
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
@pwd = Dir.pwd
@tmpdir = File.join(Dir.tmpdir, "test_reline_config_#{$$}")
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb
index e7cc0bab4f..e127ba7599 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -7,32 +7,6 @@ require_relative "helper"
module TestIRB
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
IRB.init_config(nil)
IRB.conf[:USE_SINGLELINE] = false
diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb
index b0a07ca29d..2ef4bb3373 100644
--- a/test/irb/test_history.rb
+++ b/test/irb/test_history.rb
@@ -15,38 +15,10 @@ module TestIRB
IRB.conf[:RC_NAME_GENERATOR] = nil
end
- class TestInputMethod < ::IRB::InputMethod
+ class TestInputMethodWithHistory < TestInputMethod
HISTORY = Array.new
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
def test_history_save_1
@@ -167,7 +139,7 @@ module TestIRB
IRB.conf[:SAVE_HISTORY] = 1
Dir.mktmpdir("test_irb_history_") do |tmpdir|
ENV["HOME"] = tmpdir
- io = TestInputMethod.new
+ io = TestInputMethodWithHistory.new
io.class::HISTORY.clear
io.load_history
io.class::HISTORY.concat(%w"line1 line2")
@@ -198,7 +170,7 @@ module TestIRB
f.write(initial_irb_history)
end
- io = TestInputMethod.new
+ io = TestInputMethodWithHistory.new
io.class::HISTORY.clear
io.load_history
if block_given?