Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -11272,12 +11272,9 @@ chomp_rs(int argc, const VALUE *argv)
}
}

VALUE
rb_str_chomp_string(VALUE str, VALUE rs)
static VALUE
str_shrink(VALUE str, long len)
{
long olen = RSTRING_LEN(str);
long len = chompped_length(str, rs);
if (len >= olen) return Qnil;
str_modify_keep_cr(str);
STR_SET_LEN(str, len);
TERM_FILL(&RSTRING_PTR(str)[len], TERM_LEN(str));
Expand All @@ -11287,6 +11284,15 @@ rb_str_chomp_string(VALUE str, VALUE rs)
return str;
}

VALUE
rb_str_chomp_string(VALUE str, VALUE rs)
{
long olen = RSTRING_LEN(str);
long len = chompped_length(str, rs);
if (len >= olen) return Qnil;
return str_shrink(str, len);
}

/*
* call-seq:
* chomp!(line_sep = $/) -> self or nil
Expand Down Expand Up @@ -12602,21 +12608,13 @@ deleted_suffix_length(VALUE str, VALUE suffix)
static VALUE
rb_str_delete_suffix_bang(VALUE str, VALUE suffix)
{
long olen, suffixlen, len;
long suffixlen;
str_modifiable(str);

suffixlen = deleted_suffix_length(str, suffix);
if (suffixlen <= 0) return Qnil;

olen = RSTRING_LEN(str);
str_modify_keep_cr(str);
len = olen - suffixlen;
STR_SET_LEN(str, len);
TERM_FILL(&RSTRING_PTR(str)[len], TERM_LEN(str));
if (ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) {
ENC_CODERANGE_CLEAR(str);
}
return str;
return str_shrink(str, RSTRING_LEN(str) - suffixlen);
}

/*
Expand Down
11 changes: 2 additions & 9 deletions test/io/console/test_io_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TestIO_Console < Test::Unit::TestCase
def test_console_namespace
assert_kind_of(Module, IO::Console)
end unless RUBY_ENGINE == "jruby" && RbConfig::CONFIG["host_os"] !~ /mswin|mingw/
end

HOST_OS = RbConfig::CONFIG['host_os']

Expand Down Expand Up @@ -74,7 +74,6 @@ def test_bad_keyword
end
end

TTY_ENHANCED = IO.instance_method(:tty?).arity != 0
TTY_MODE_STTY = IO.private_method_defined?(:_io_console_stty)

def test_stty_mode_arguments
Expand All @@ -88,8 +87,6 @@ def test_stty_mode_arguments
end if TTY_MODE_STTY

def test_tty?
pend "not supported" unless TTY_ENHANCED

tty = STDIN.tty?(:any)
assert_include([true, false], tty)
assert_equal(tty, STDIN.tty?(:any, :any))
Expand All @@ -98,8 +95,6 @@ def test_tty?
end

def test_tty_non_tty
pend "not supported" unless TTY_ENHANCED

File.open(IO::NULL) do |f|
assert_not_predicate(f, :tty?)
assert_not_operator(f, :tty?, :any)
Expand Down Expand Up @@ -347,8 +342,6 @@ def test_stty_redirect_stdout
end if TTY_MODE_STTY

def test_tty_on_pty
pend "not supported" unless TTY_ENHANCED

helper {|_, s|
assert_predicate(s, :tty?)
assert_operator(s, :tty?, :any)
Expand Down Expand Up @@ -535,7 +528,7 @@ def test_input_pending
assert_equal("b", read.getc)
assert_false(read.input_pending?)
end
end unless RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ || RUBY_ENGINE == "jruby"
end

def assert_ctrl(expect, cc, r, w)
sleep 0.1
Expand Down
5 changes: 4 additions & 1 deletion test/ruby/test_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,10 @@ def test_member?
end

def hash_hint hv
hv & 0xff
hint = hv & 0xff
# hash.c's ar_do_hash_hint() substitutes RHASH_AR_CLEARED_HINT (0x00)
# with RHASH_AR_SUBSTITUTION_HINT (0x01), so those two alias.
hint == 0 ? 1 : hint
end

def test_rehash
Expand Down