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

Commits on Mar 22, 2015

  1. Copy the full SHA
    90727f7 View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    5ed9485 View commit details
  3. Merge pull request #769 from vais/string

    Get rid of most of the String#each_line and String#lines failures
    meh committed Mar 22, 2015
    Copy the full SHA
    3306b56 View commit details
Showing with 26 additions and 28 deletions.
  1. +20 −3 opal/corelib/string.rb
  2. +1 −24 spec/filters/bugs/string.rb
  3. +3 −0 spec/filters/unsupported/mutable_strings.rb
  4. +2 −1 spec/filters/unsupported/symbols.rb
23 changes: 20 additions & 3 deletions opal/corelib/string.rb
Original file line number Diff line number Diff line change
@@ -363,9 +363,25 @@ def each_char(&block)
end

def each_line(separator = $/)
return split(separator) unless block_given?
return enum_for :each_line, separator unless block_given?

%x{
if (separator === nil) {
#{yield self};
return self;
}
separator = #{Opal.coerce_to(`separator`, String, :to_str)}
if (separator.length === 0) {
for (var a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
if (a[i] || a[i + 1]) {
#{yield `(a[i] || "") + (a[i + 1] || "")`};
}
}
return self;
}
var chomped = #{chomp},
trailing = self.length != chomped.length,
splitted = chomped.split(separator);
@@ -526,8 +542,9 @@ def intern
self
end

def lines(separator = $/)
each_line(separator).to_a
def lines(separator = $/, &block)
e = each_line(separator, &block)
block ? self : e.to_a
end

def length
25 changes: 1 addition & 24 deletions spec/filters/bugs/string.rb
Original file line number Diff line number Diff line change
@@ -3,18 +3,8 @@

fails "String#dup does not copy constants defined in the singleton class"

fails "String#each_line accepts a string separator"
fails "String#each_line passes self as a whole to the block if the separator is nil"
fails "String#each_line yields paragraphs (broken by 2 or more successive newlines) when passed ''"
fails "String#each_line uses $/ as the separator when none is given"
fails "String#each_line yields subclass instances for subclasses"
fails "String#each_line tries to convert the separator to a string using to_str"
fails "String#each_line tries to convert the separator to a string using to_str"
fails "String#each_line does not care if the string is modified while substituting"
fails "String#each_line raises a TypeError when the separator can't be converted to a string"
fails "String#each_line accept string separator"
fails "String#each_line raises a TypeError when the separator is a symbol"
fails "String#each_line returns an enumerator when no block given"

fails "String#gsub with pattern and replacement inserts the replacement around every character when the pattern collapses"
fails "String#gsub with pattern and replacement respects $KCODE when the pattern collapses"
@@ -47,21 +37,8 @@
fails "String#gsub with pattern and block restores $~ after leaving the block"
fails "String#gsub with pattern and block sets $~ to MatchData of last match and nil when there's none for access from outside"

fails "String#lines accepts a string separator"
fails "String#lines should split on the default record separator and return enumerator if not block is given"
fails "String#lines splits using default newline separator when none is specified"
fails "String#lines splits self using the supplied record separator and passes each substring to the block"
fails "String#lines passes self as a whole to the block if the separator is nil"
fails "String#lines yields paragraphs (broken by 2 or more successive newlines) when passed ''"
fails "String#lines uses $/ as the separator when none is given"
fails "String#lines yields subclass instances for subclasses"
fails "String#lines returns self"
fails "String#lines tries to convert the separator to a string using to_str"
fails "String#lines tries to convert the separator to a string using to_str"
fails "String#lines does not care if the string is modified while substituting"
fails "String#lines raises a TypeError when the separator can't be converted to a string"
fails "String#lines accept string separator"
fails "String#lines raises a TypeError when the separator is a symbol"
fails "String#lines returns an array when no block given"

fails "String#rindex with object raises a TypeError if obj isn't a String, Fixnum or Regexp"
fails "String#rindex with object tries to convert obj to a string via to_str"
3 changes: 3 additions & 0 deletions spec/filters/unsupported/mutable_strings.rb
Original file line number Diff line number Diff line change
@@ -377,4 +377,7 @@
fails "String#concat when self is ASCII-8BIT and argument is US-ASCII uses ASCII-8BIT encoding"

fails "String#dup does not modify the original string when changing dupped string"

fails "String#each_line does not care if the string is modified while substituting"
fails "String#lines does not care if the string is modified while substituting"
end
3 changes: 2 additions & 1 deletion spec/filters/unsupported/symbols.rb
Original file line number Diff line number Diff line change
@@ -8,7 +8,8 @@
fails "A Symbol literal can contain null in the string"
fails "A Symbol literal can be an empty string"

fails "String#each_line raises a TypeError when the separator is a symbol"
fails "String#index raises a TypeError if passed a Symbol"

fails "String#lines raises a TypeError when the separator is a symbol"
fails "String#upto does not work with symbols"
end