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: d11171e00faa
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: edbd1d5360f9
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Feb 2, 2017

  1. Implement String#casecmp? and Symbol#casecmp?

    * Adds implementation of `casecmp?` based on downcasing the string and comparing
    * Adds unit tests for `casecmp?` from MRI
    
    See #4293
    kcdragon committed Feb 2, 2017
    Copy the full SHA
    88f9f7e View commit details

Commits on Feb 11, 2017

  1. Copy the full SHA
    be4882f View commit details

Commits on Feb 13, 2017

  1. Merge pull request #4470 from kcdragon/md/feature/string-symbol-casec…

    …mp-p
    
    Implement `String#casecmp?` and `Symbol#casecmp?`
    headius authored Feb 13, 2017
    Copy the full SHA
    edbd1d5 View commit details
Showing with 38 additions and 0 deletions.
  1. +13 −0 core/src/main/java/org/jruby/RubyString.java
  2. +8 −0 core/src/main/java/org/jruby/RubySymbol.java
  3. +8 −0 test/mri/ruby/test_string.rb
  4. +9 −0 test/mri/ruby/test_symbol.rb
13 changes: 13 additions & 0 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -1594,6 +1594,19 @@ 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();

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

RubyString downcasedString = this.downcase19(context);
RubyString otherDowncasedString = otherStr.downcase19(context);
return downcasedString.equals(otherDowncasedString) ? context.runtime.getTrue() : context.runtime.getFalse();
}

/** rb_str_match
*
*/
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -406,6 +406,14 @@ public IRubyObject casecmp(ThreadContext context, IRubyObject other) {
newShared(runtime).casecmp19(context, ((RubySymbol) other).newShared(runtime));
}

@JRubyMethod(name = "casecmp?")
public IRubyObject casecmp_p(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;

return !(other instanceof RubySymbol) ? runtime.getNil() :
newShared(runtime).casecmp_p(context, ((RubySymbol) other).newShared(runtime));
}

@JRubyMethod(name = "=~")
@Override
public IRubyObject op_match(ThreadContext context, IRubyObject other) {
8 changes: 8 additions & 0 deletions test/mri/ruby/test_string.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
# frozen_string_literal: false
require 'test/unit'

@@ -2210,6 +2211,13 @@ def test_casecmp
assert_equal(1, "\u3042B".casecmp("\u3042a"))
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?('ÄÖÜ'))
end

def test_upcase2
assert_equal("\u3042AB", "\u3042aB".upcase)
end
9 changes: 9 additions & 0 deletions test/mri/ruby/test_symbol.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
# frozen_string_literal: false
require 'test/unit'

@@ -276,6 +277,14 @@ def test_casecmp
assert_nil(:foo.casecmp("foo"))
end

def test_casecmp?
assert_equal(true, :FoO.casecmp?(:fOO))
assert_equal(false, :FoO.casecmp?(:BaR))
assert_equal(false, :baR.casecmp?(:FoO))
assert_nil(:foo.casecmp?("foo"))
assert_equal(true, :äöü.casecmp?(:ÄÖÜ))
end

def test_length
assert_equal(3, :FoO.length)
assert_equal(3, :FoO.size)