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

Commits on Feb 6, 2015

  1. Copy the full SHA
    f814a30 View commit details
  2. Copy the full SHA
    bf2e6e2 View commit details
  3. Copy the full SHA
    e249a18 View commit details
13 changes: 0 additions & 13 deletions spec/truffle/tags/core/string/chomp_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
fails:String#chomp when passed no argument removes one trailing newline
fails:String#chomp when passed no argument removes one trailing carrige return, newline pair
fails:String#chomp when passed no argument taints the result if self is tainted
fails:String#chomp when passed no argument returns subclass instances when called on a subclass
fails:String#chomp when passed no argument removes trailing characters that match $/ when it has been assigned a value
fails:String#chomp when passed nil does not modify the String
fails:String#chomp when passed nil returns a copy of the String
fails:String#chomp when passed nil taints the result if self is tainted
@@ -15,10 +12,7 @@ fails:String#chomp when passed '' taints the result if self is tainted
fails:String#chomp when passed '\n' removes one trailing carriage return
fails:String#chomp when passed '\n' removes one trailing carrige return, newline pair
fails:String#chomp when passed '\n' taints the result if self is tainted
fails:String#chomp when passed an Object calls #to_str to convert to a String
fails:String#chomp when passed an Object raises a TypeError if #to_str does not return a String
fails:String#chomp when passed a String taints the result if self is tainted
fails:String#chomp when passed a String does not taint the result when the argument is tainted
fails:String#chomp! raises a RuntimeError on a frozen instance when it is modified
fails:String#chomp! raises a RuntimeError on a frozen instance when it would not be modified
fails:String#chomp! when passed no argument returns nil if self is not modified
@@ -33,19 +27,12 @@ fails:String#chomp! when passed '' removes a final carriage return, newline
fails:String#chomp! when passed '' does not remove a final carriage return
fails:String#chomp! when passed '' removes more than one trailing newlines
fails:String#chomp! when passed '' removes more than one trailing carriage return, newline pairs
fails:String#chomp! when passed '' taints the result if self is tainted
fails:String#chomp! when passed '' returns nil when self is empty
fails:String#chomp! when passed '\n' removes one trailing newline
fails:String#chomp! when passed '\n' removes one trailing carriage return
fails:String#chomp! when passed '\n' removes one trailing carrige return, newline pair
fails:String#chomp! when passed '\n' taints the result if self is tainted
fails:String#chomp! when passed '\n' returns nil when self is empty
fails:String#chomp! when passed an Object calls #to_str to convert to a String
fails:String#chomp! when passed an Object raises a TypeError if #to_str does not return a String
fails:String#chomp! when passed a String removes the trailing characters if they match the argument
fails:String#chomp! when passed a String returns nil if the argument does not match the trailing characters
fails:String#chomp! when passed a String returns nil when self is empty
fails:String#chomp! when passed a String taints the result if self is tainted
fails:String#chomp! when passed a String does not taint the result when the argument is tainted
fails:String#chomp removes the final carriage return, newline from a non-ASCII String
fails:String#chomp! returns nil when the String is not modified
38 changes: 10 additions & 28 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -498,34 +498,11 @@ public Object byteSlice(RubyString string, int index, int length) {

}

@CoreMethod(names = "chomp", optional=1)
public abstract static class ChompNode extends CoreMethodNode {

public ChompNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public ChompNode(ChompNode prev) {
super(prev);
}

@Specialization
public RubyString chomp(RubyString string, UndefinedPlaceholder undefined) {
notDesignedForCompilation();
return string.getContext().makeString(StringNodesHelper.chomp(string));
}

@Specialization
public RubyString chompWithString(RubyString string, RubyString stringToChomp) {
notDesignedForCompilation();
return getContext().makeString(StringNodesHelper.chompWithString(string, stringToChomp));
}

}

@CoreMethod(names = "chomp!", optional = 1)
public abstract static class ChompBangNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;

public ChompBangNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -542,11 +519,16 @@ public RubyString chompBang(RubyString string, UndefinedPlaceholder undefined) {
return string;
}

@Specialization
public RubyString chompBangWithString(RubyString string, RubyString stringToChomp) {
@Specialization(guards = "!isUndefinedPlaceholder(arguments[1])")
public RubyString chompBangWithString(VirtualFrame frame, RubyString string, Object stringToChomp) {
notDesignedForCompilation();

string.set(StringNodesHelper.chompWithString(string, stringToChomp));
if (toStrNode == null) {
CompilerDirectives.transferToInterpreter();
toStrNode = insert(ToStrNodeFactory.create(getContext(), getSourceSection(), null));
}

string.set(StringNodesHelper.chompWithString(string, toStrNode.executeRubyString(frame, stringToChomp)));
return string;
}
}
Original file line number Diff line number Diff line change
@@ -296,13 +296,19 @@ public void initialize() {

// Create the globals object

final RubyString defaultRecordSeparator = context.makeString(Options.CLI_RECORD_SEPARATOR.load());
defaultRecordSeparator.freeze();

globalVariablesObject = new RubyBasicObject(objectClass);
globalVariablesObject.getOperations().setInstanceVariable(globalVariablesObject, "$LOAD_PATH", new RubyArray(arrayClass));
globalVariablesObject.getOperations().setInstanceVariable(globalVariablesObject, "$LOADED_FEATURES", new RubyArray(arrayClass));
globalVariablesObject.getOperations().setInstanceVariable(globalVariablesObject, "$:", globalVariablesObject.getInstanceVariable("$LOAD_PATH"));
globalVariablesObject.getOperations().setInstanceVariable(globalVariablesObject, "$\"", globalVariablesObject.getInstanceVariable("$LOADED_FEATURES"));
globalVariablesObject.getOperations().setInstanceVariable(globalVariablesObject, "$,", nilObject);

// TODO (nirvdrum 05-Feb-15) We need to support the $-0 alias as well.
globalVariablesObject.getOperations().setInstanceVariable(globalVariablesObject, "$/", defaultRecordSeparator);

initializeEncodingConstants();

arrayMinBlock = new ArrayNodes.MinBlock(context);
Original file line number Diff line number Diff line change
@@ -42,4 +42,9 @@ def chars
end
end

def chomp(separator=$/)
str = dup
str.chomp!(separator) || str
end

end