Skip to content

Commit

Permalink
Merge pull request #258 from aycabta/add-codepage-to-irb_info
Browse files Browse the repository at this point in the history
Show code page by irb_info on Windows
  • Loading branch information
aycabta committed Jul 15, 2021
2 parents 759be5a + 6160d74 commit b705aa7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/irb/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def inspect
str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
codepage = `chcp`.sub(/Active code page: (\d+)\n/, '\1')
str += "Code page: #{codepage}\n"
end
str
end
alias_method :to_s, :inspect
Expand Down
33 changes: 19 additions & 14 deletions test/irb/test_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def setup
@default_encoding = [Encoding.default_external, Encoding.default_internal]
@stdio_encodings = [STDIN, STDOUT, STDERR].map {|io| [io.external_encoding, io.internal_encoding] }
IRB.instance_variable_get(:@CONF).clear
@is_win = (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/)
end

def teardown
Expand Down Expand Up @@ -75,11 +76,12 @@ def test_irb_info_multiline
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
IRB.conf[:MAIN_CONTEXT] = irb.context
expected = %r{
Ruby\sversion: .+\n
IRB\sversion:\sirb .+\n
Ruby\sversion:\s.+\n
IRB\sversion:\sirb\s.+\n
InputMethod:\sAbstract\sInputMethod\n
\.irbrc\spath: .+\n
RUBY_PLATFORM: .+
\.irbrc\spath:\s.+\n
RUBY_PLATFORM:\s.+\n
#{@is_win ? 'Code\spage:\s\d+\n' : ''}
}x
assert_match expected, irb.context.main.irb_info.to_s
ensure
Expand All @@ -100,11 +102,12 @@ def test_irb_info_singleline
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
IRB.conf[:MAIN_CONTEXT] = irb.context
expected = %r{
Ruby\sversion: .+\n
IRB\sversion:\sirb .+\n
Ruby\sversion:\s.+\n
IRB\sversion:\sirb\s.+\n
InputMethod:\sAbstract\sInputMethod\n
\.irbrc\spath: .+\n
RUBY_PLATFORM: .+
\.irbrc\spath:\s.+\n
RUBY_PLATFORM:\s.+\n
#{@is_win ? 'Code\spage:\s\d+\n' : ''}
}x
assert_match expected, irb.context.main.irb_info.to_s
ensure
Expand All @@ -128,10 +131,11 @@ def test_irb_info_multiline_without_rc_files
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
IRB.conf[:MAIN_CONTEXT] = irb.context
expected = %r{
Ruby\sversion: .+\n
IRB\sversion:\sirb .+\n
Ruby\sversion:\s.+\n
IRB\sversion:\sirb\s.+\n
InputMethod:\sAbstract\sInputMethod\n
RUBY_PLATFORM: .+\n
RUBY_PLATFORM:\s.+\n
#{@is_win ? 'Code\spage:\s\d+\n' : ''}
\z
}x
assert_match expected, irb.context.main.irb_info.to_s
Expand Down Expand Up @@ -159,10 +163,11 @@ def test_irb_info_singleline_without_rc_files
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
IRB.conf[:MAIN_CONTEXT] = irb.context
expected = %r{
Ruby\sversion: .+\n
IRB\sversion:\sirb .+\n
Ruby\sversion:\s.+\n
IRB\sversion:\sirb\s.+\n
InputMethod:\sAbstract\sInputMethod\n
RUBY_PLATFORM: .+\n
RUBY_PLATFORM:\s.+\n
#{@is_win ? 'Code\spage:\s\d+\n' : ''}
\z
}x
assert_match expected, irb.context.main.irb_info.to_s
Expand Down

0 comments on commit b705aa7

Please sign in to comment.