Skip to content

Commit 6644d04

Browse files
committed
[Truffle] Fixed some more String#{chomp, chomp\!} cases.
1 parent e249a18 commit 6644d04

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spec/truffle/tags/core/string/chomp_tags.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
fails:String#chomp when passed no argument removes one trailing carrige return, newline pair
22
fails:String#chomp when passed no argument taints the result if self is tainted
3-
fails:String#chomp when passed nil does not modify the String
4-
fails:String#chomp when passed nil returns a copy of the String
53
fails:String#chomp when passed nil taints the result if self is tainted
6-
fails:String#chomp when passed nil returns an empty String when self is empty
74
fails:String#chomp when passed '' removes a final newline
85
fails:String#chomp when passed '' removes a final carriage return, newline
96
fails:String#chomp when passed '' removes more than one trailing newlines
@@ -18,10 +15,7 @@ fails:String#chomp! raises a RuntimeError on a frozen instance when it would not
1815
fails:String#chomp! when passed no argument returns nil if self is not modified
1916
fails:String#chomp! when passed no argument removes one trailing newline
2017
fails:String#chomp! when passed no argument removes one trailing carrige return, newline pair
21-
fails:String#chomp! when passed no argument returns nil when self is empty
2218
fails:String#chomp! when passed no argument removes trailing characters that match $/ when it has been assigned a value
23-
fails:String#chomp! when passed nil returns nil
24-
fails:String#chomp! when passed nil returns nil when self is empty
2519
fails:String#chomp! when passed '' removes a final newline
2620
fails:String#chomp! when passed '' removes a final carriage return, newline
2721
fails:String#chomp! when passed '' does not remove a final carriage return

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,23 @@ public ChompBangNode(ChompBangNode prev) {
512512
}
513513

514514
@Specialization
515-
public RubyString chompBang(RubyString string, UndefinedPlaceholder undefined) {
515+
public Object chompBang(RubyString string, UndefinedPlaceholder undefined) {
516516
notDesignedForCompilation();
517517

518+
if (string.length() == 0) {
519+
return getContext().getCoreLibrary().getNilObject();
520+
}
521+
518522
string.set(StringNodesHelper.chomp(string));
519523
return string;
520524
}
521525

522-
@Specialization(guards = "!isUndefinedPlaceholder(arguments[1])")
526+
@Specialization
527+
public RubyNilClass chompBangWithNil(RubyString string, RubyNilClass stringToChomp) {
528+
return getContext().getCoreLibrary().getNilObject();
529+
}
530+
531+
@Specialization(guards = { "!isUndefinedPlaceholder(arguments[1])", "!isRubyNilClass(arguments[1])" })
523532
public RubyString chompBangWithString(VirtualFrame frame, RubyString string, Object stringToChomp) {
524533
notDesignedForCompilation();
525534

0 commit comments

Comments
 (0)