mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 23:16:42 +02:00
parent
1a9e87fe3a
commit
1eae15142f
4 changed files with 29 additions and 83 deletions
|
@ -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] }
|
||||||
|
|
|
@ -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_#{$$}")
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue