Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 527b036babc8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fb7968794e55
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 14, 2018

  1. Copy the full SHA
    3df64a6 View commit details
  2. Copy the full SHA
    bdd7b2f View commit details

Commits on Jan 15, 2018

  1. Merge pull request #4975 from ChrisBr/feature/string-casecmp

    Feature/string casecmp
    enebo authored Jan 15, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fb79687 View commit details
Showing with 28 additions and 4 deletions.
  1. +10 −3 core/src/main/java/org/jruby/RubyString.java
  2. +18 −1 test/mri/ruby/test_string.rb
13 changes: 10 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -1504,7 +1504,7 @@ public RubyString reverse_bang19(ThreadContext context) {
}
value.setUnsafeBytes(obytes);
}

setCodeRange(cr);
}
return this;
@@ -1584,7 +1584,11 @@ public IRubyObject casecmp(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "casecmp")
public IRubyObject casecmp19(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
RubyString otherStr = other.convertToString();

IRubyObject tmp = other.checkStringType();
if (tmp.isNil()) return runtime.getNil();

RubyString otherStr = (RubyString) tmp;
Encoding enc = StringSupport.areCompatible(this, otherStr);
if (enc == null) return runtime.getNil();

@@ -1608,7 +1612,10 @@ public IRubyObject casecmp19(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "casecmp?")
public IRubyObject casecmp_p(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
RubyString otherStr = other.convertToString();

IRubyObject tmp = other.checkStringType();
if (tmp.isNil()) return runtime.getNil();
RubyString otherStr = (RubyString) tmp;

Encoding enc = StringSupport.areCompatible(this, otherStr);
if (enc == null) return runtime.getNil();
19 changes: 18 additions & 1 deletion test/mri/ruby/test_string.rb
Original file line number Diff line number Diff line change
@@ -2296,14 +2296,31 @@ def test_compare_different_encoding_string
=end

def test_casecmp
assert_equal(1, "\u3042B".casecmp("\u3042a"))
assert_equal(0, "FoO".casecmp("fOO"))
assert_equal(1, "FoO".casecmp("BaR"))
assert_equal(-1, "baR".casecmp("FoO"))
assert_equal(1, "\u3042B".casecmp("\u3042a"))

assert_nil("foo".casecmp(:foo))
assert_nil("foo".casecmp(Object.new))

o = Object.new
def o.to_str; "fOO"; end
assert_equal(0, "FoO".casecmp(o))
end

def test_casecmp?
assert_equal(true, 'FoO'.casecmp?('fOO'))
assert_equal(false, 'FoO'.casecmp?('BaR'))
assert_equal(false, 'baR'.casecmp?('FoO'))
assert_equal(true, 'äöü'.casecmp?('ÄÖÜ'))

assert_nil("foo".casecmp?(:foo))
assert_nil("foo".casecmp?(Object.new))

o = Object.new
def o.to_str; "fOO"; end
assert_equal(true, "FoO".casecmp?(o))
end

def test_upcase2