Skip to content

Commit

Permalink
[ruby/irb] Show code page by irb_info on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta authored and matzbot committed Jul 15, 2021
1 parent 456d001 commit f103524
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/irb/cmd/info.rb
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
5 changes: 5 additions & 0 deletions test/irb/test_cmd.rb
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 @@ -80,6 +81,7 @@ def test_irb_info_multiline
InputMethod:\sAbstract\sInputMethod\n
\.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 @@ -105,6 +107,7 @@ def test_irb_info_singleline
InputMethod:\sAbstract\sInputMethod\n
\.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 Down Expand Up @@ -132,6 +135,7 @@ def test_irb_info_multiline_without_rc_files
IRB\sversion:\sirb\s.+\n
InputMethod:\sAbstract\sInputMethod\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 @@ -163,6 +167,7 @@ def test_irb_info_singleline_without_rc_files
IRB\sversion:\sirb\s.+\n
InputMethod:\sAbstract\sInputMethod\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 f103524

Please sign in to comment.