Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix failing rubyspecs for Encoding#compatible? #708

Merged
merged 2 commits into from

2 participants

@tychobrailleur
Collaborator

This patch implements support for symbols in Encoding#compatible?, and deletes a line absent from MRI.

tychobrailleur added some commits
@tychobrailleur tychobrailleur Fix Encoding#compatible? failing rubyspecs. 4d6f4a9
@tychobrailleur tychobrailleur Improved code formatting:
- Removed unused import,
- Added some whitespaces where missing,
- Removed a pair of curly braces for a simple if.
806f4cd
@headius headius merged commit 9caad5d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 6, 2013
  1. @tychobrailleur
  2. @tychobrailleur

    Improved code formatting:

    tychobrailleur authored
    - Removed unused import,
    - Added some whitespaces where missing,
    - Removed a pair of curly braces for a simple if.
This page is out of date. Refresh to see the latest.
View
12 spec/tags/1.9/ruby/core/encoding/compatible_tags.txt
@@ -1,12 +0,0 @@
-fails:Encoding.compatible? String, String when the first's Encoding is ASCII compatible and ASCII only returns the first's Encoding if the second is ASCII compatible and ASCII only
-fails:Encoding.compatible? String, Symbol returns US-ASCII if both are ASCII only
-fails:Encoding.compatible? String, Symbol returns the String's Encoding if it is not US-ASCII but both are ASCII only
-fails:Encoding.compatible? String, Symbol returns the String's Encoding if the String is not ASCII only
-fails:Encoding.compatible? Regexp, Symbol returns US-ASCII if both are US-ASCII
-fails:Encoding.compatible? Symbol, String returns US-ASCII if both are ASCII only
-fails:Encoding.compatible? Symbol, Regexp returns US-ASCII if both are US-ASCII
-fails:Encoding.compatible? Symbol, Regexp returns the Regexp's Encoding if it is not US-ASCII and not ASCII only
-fails:Encoding.compatible? Symbol, Symbol returns US-ASCII if both are US-ASCII
-fails:Encoding.compatible? Symbol, Symbol returns the first's Encoding if it is not ASCII only
-fails:Encoding.compatible? Encoding, Encoding returns the first if the second is US-ASCII
-fails:Encoding.compatible? Encoding, Encoding returns the Encoding if both are the same
View
26 src/org/jruby/RubyEncoding.java
@@ -35,7 +35,6 @@
import org.jcodings.Encoding;
import org.jcodings.EncodingDB.Entry;
-import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.util.CaseInsensitiveBytesHash;
import org.jcodings.util.Hash.HashEntryIterator;
@@ -80,7 +79,7 @@ public boolean isKindOf(IRubyObject obj, RubyModule type) {
private final ByteList name;
private final boolean isDummy;
- private RubyEncoding(Ruby runtime, byte[]name, int p, int end, boolean isDummy) {
+ private RubyEncoding(Ruby runtime, byte[] name, int p, int end, boolean isDummy) {
super(runtime, runtime.getEncoding());
this.name = new ByteList(name, p, end);
this.isDummy = isDummy;
@@ -97,11 +96,11 @@ private RubyEncoding(Ruby runtime, Encoding encoding) {
this.encoding = encoding;
}
- public static RubyEncoding newEncoding(Ruby runtime, byte[]name, int p, int end, boolean isDummy) {
+ public static RubyEncoding newEncoding(Ruby runtime, byte[] name, int p, int end, boolean isDummy) {
return new RubyEncoding(runtime, name, p, end, isDummy);
}
- public static RubyEncoding newEncoding(Ruby runtime, byte[]name, boolean isDummy) {
+ public static RubyEncoding newEncoding(Ruby runtime, byte[] name, boolean isDummy) {
return new RubyEncoding(runtime, name, isDummy);
}
@@ -120,15 +119,19 @@ public static Encoding areCompatible(IRubyObject obj1, IRubyObject obj2) {
Encoding enc2 = null;
if (obj1 instanceof RubyEncoding) {
- enc1 = ((RubyEncoding)obj1).getEncoding();
+ enc1 = ((RubyEncoding)obj1).getEncoding();
+ } else if (obj1 instanceof RubySymbol) {
+ enc1 = ((RubySymbol)obj1).asString().getEncoding();
} else if (obj1 instanceof EncodingCapable) {
- enc1 = ((EncodingCapable)obj1).getEncoding();
+ enc1 = ((EncodingCapable)obj1).getEncoding();
}
if (obj2 instanceof RubyEncoding) {
- enc2 = ((RubyEncoding)obj2).getEncoding();
+ enc2 = ((RubyEncoding)obj2).getEncoding();
+ } else if (obj2 instanceof RubySymbol) {
+ enc2 = ((RubySymbol)obj2).asString().getEncoding();
} else if (obj2 instanceof EncodingCapable) {
- enc2 = ((EncodingCapable)obj2).getEncoding();
+ enc2 = ((EncodingCapable)obj2).getEncoding();
}
if (enc1 != null && enc2 != null) {
@@ -142,7 +145,7 @@ public static Encoding areCompatible(IRubyObject obj1, IRubyObject obj2) {
if (!(obj2 instanceof RubyString) && enc2 instanceof USASCIIEncoding) return enc1;
if (!(obj1 instanceof RubyString) && enc1 instanceof USASCIIEncoding) return enc2;
- if(!(obj1 instanceof RubyString)) {
+ if (!(obj1 instanceof RubyString)) {
IRubyObject objTmp = obj1;
obj1 = obj2;
obj1 = objTmp;
@@ -170,10 +173,7 @@ static Encoding areCompatible(Encoding enc1, int cr1, Encoding enc2, int cr2) {
if (cr1 == StringSupport.CR_7BIT) return enc2;
if (cr2 == StringSupport.CR_7BIT) return enc1;
}
- if (cr2 == StringSupport.CR_7BIT) {
- if (enc1 instanceof ASCIIEncoding) return enc2;
- return enc1;
- }
+ if (cr2 == StringSupport.CR_7BIT) return enc1;
if (cr1 == StringSupport.CR_7BIT) return enc2;
return null;
}
Something went wrong with that request. Please try again.