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

Commits on Feb 24, 2015

  1. Implement String#[] with a regexp argument

    pass "String#[] with Regexp returns the matching portion of self"
    pass "String#[] with Regexp returns nil if there is no match"
    pass "String#[] with Regexp sets $~ to MatchData when there is a match
    and nil when there's none"
    pass "String#[] with Regexp, index returns the capture for the given
    index"
    pass "String#[] with Regexp, index returns nil if there is no match"
    pass "String#[] with Regexp, index returns nil if there is no capture
    for the given index"
    pass "String#[] with Regexp, index calls to_int on the given index"
    pass "String#[] with Regexp, index raises a TypeError when the given
    index can't be converted to Integer"
    pass "String#[] with Regexp, index raises a TypeError when the given
    index is nil"
    pass "String#[] with Regexp, index sets $~ to MatchData when there is a
    match and nil when there's none"
    pass "String#[] with Regexp returns subclass instances"
    pass "String#[] with Regexp, index returns subclass instances"
    pass "String#slice with Regexp returns the matching portion of self"
    pass "String#slice with Regexp returns nil if there is no match"
    pass "String#slice with Regexp sets $~ to MatchData when there is a
    match and nil when there's none"
    pass "String#slice with Regexp, index returns the capture for the given
    index"
    pass "String#slice with Regexp, index returns nil if there is no match"
    pass "String#slice with Regexp, index returns nil if there is no
    capture for the given index"
    pass "String#slice with Regexp, index calls to_int on the given index"
    pass "String#slice with Regexp, index raises a TypeError when the given
    index can't be converted to Integer"
    pass "String#slice with Regexp, index raises a TypeError when the given
    index is nil"
    pass "String#slice with Regexp, index sets $~ to MatchData when there
    is a match and nil when there's none"
    pass "String#slice with Regexp, group"
    pass "String#slice with Regexp returns subclass instances"
    pass "String#slice with Regexp, index returns subclass instances"
    vais committed Feb 24, 2015
    Copy the full SHA
    248aef6 View commit details
  2. Merge pull request #706 from vais/string

    Implement String#[] with a regexp argument
    meh committed Feb 24, 2015
    Copy the full SHA
    1e5b6e6 View commit details
Showing with 27 additions and 29 deletions.
  1. +2 −0 CHANGELOG.md
  2. +25 −2 opal/corelib/string.rb
  3. +0 −27 spec/filters/bugs/string.rb
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@

* Now the CLI implicitly calls `Kernel#exit` at the end of the script, thus making `at_exit` blocks be respected.

* Support calling `String#[]` and `String#slice` with a regexp argument

## 0.7.0 2015-02-01

* Stop keyword-arg variable names leaking to global javascript scope
27 changes: 25 additions & 2 deletions opal/corelib/string.rb
Original file line number Diff line number Diff line change
@@ -150,12 +150,35 @@ def [](index, length = undefined)
if (index.$$is_string) {
return self.indexOf(index) !== -1 ? index : nil
return self.indexOf(index) !== -1 ? index : nil;
}
if (index.$$is_regexp) {
#{raise NotImplementedError}
var match = self.match(index);
if (match === null) {
#{$~ = nil}
return nil;
}
#{$~ = MatchData.new(`index`, `match`)}
if (length == null) {
return match[0];
}
length = #{Opal.coerce_to(`length`, Integer, :to_int)};
if (length < 0 && -length < match.length) {
return match[length += match.length];
}
if (length >= 0 && length < match.length) {
return match[length];
}
return nil;
}
}

27 changes: 0 additions & 27 deletions spec/filters/bugs/string.rb
Original file line number Diff line number Diff line change
@@ -19,19 +19,6 @@
fails "String#[] with Range calls to_int on range arguments"
fails "String#[] with Range calls to_int on range arguments"
fails "String#[] with Range handles repeated application"
fails "String#[] with Regexp returns the matching portion of self"
fails "String#[] with Regexp returns nil if there is no match"
fails "String#[] with Regexp sets $~ to MatchData when there is a match and nil when there's none"
fails "String#[] with Regexp, index returns the capture for the given index"
fails "String#[] with Regexp, index returns nil if there is no match"
fails "String#[] with Regexp, index returns nil if there is no capture for the given index"
fails "String#[] with Regexp, index calls to_int on the given index"
fails "String#[] with Regexp, index calls to_int on the given index"
fails "String#[] with Regexp, index raises a TypeError when the given index can't be converted to Integer"
fails "String#[] with Regexp, index raises a TypeError when the given index is nil"
fails "String#[] with Regexp, index sets $~ to MatchData when there is a match and nil when there's none"
fails "String#[] with Regexp returns subclass instances"
fails "String#[] with Regexp, index returns subclass instances"

fails "String#dup does not copy constants defined in the singleton class"
fails "String#dup does not modify the original string when changing dupped string"
@@ -147,20 +134,6 @@
fails "String#slice with Range calls to_int on range arguments"
fails "String#slice with Range calls to_int on range arguments"
fails "String#slice with Range handles repeated application"
fails "String#slice with Regexp returns the matching portion of self"
fails "String#slice with Regexp returns nil if there is no match"
fails "String#slice with Regexp sets $~ to MatchData when there is a match and nil when there's none"
fails "String#slice with Regexp, index returns the capture for the given index"
fails "String#slice with Regexp, index returns nil if there is no match"
fails "String#slice with Regexp, index returns nil if there is no capture for the given index"
fails "String#slice with Regexp, index calls to_int on the given index"
fails "String#slice with Regexp, index calls to_int on the given index"
fails "String#slice with Regexp, index raises a TypeError when the given index can't be converted to Integer"
fails "String#slice with Regexp, index raises a TypeError when the given index is nil"
fails "String#slice with Regexp, index sets $~ to MatchData when there is a match and nil when there's none"
fails "String#slice with Regexp, group"
fails "String#slice with Regexp returns subclass instances"
fails "String#slice with Regexp, index returns subclass instances"

fails "String#split with String returns subclass instances based on self"
fails "String#split with Regexp respects $KCODE when splitting between characters"