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

Commits on Feb 23, 2015

  1. Implement String#[] with a string argument

    DONE:
    pass "String#[] with String returns other_str if it occurs in self"
    pass "String#[] with String returns nil if there is no match"
    
    TODO:
    still fails "String#[] with String doesn't call to_str on its argument"
    still fails "String#[] with String returns a subclass instance when
    given a subclass instance”
    vais committed Feb 23, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    84e8e78 View commit details
  2. Change implementation of String#[] with a string argument

    DONE:
    pass "String#[] with String returns other_str if it occurs in self"
    pass "String#[] with String returns nil if there is no match"
    pass "String#[] with String doesn't call to_str on its argument"
    pass "String#[] with String returns a subclass instance when
    given a subclass instance”
    vais committed Feb 23, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    7110423 View commit details
  3. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    91a3da3 View commit details
  4. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    10f3962 View commit details
  5. Unverified

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

    Implement String#[] with a string argument
    meh committed Feb 23, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    6ddeb03 View commit details
Showing with 32 additions and 19 deletions.
  1. +24 −9 opal/corelib/string.rb
  2. +2 −0 opal/corelib/string/inheritance.rb
  3. +4 −8 spec/filters/bugs/string.rb
  4. +2 −2 spec/rubyspecs
33 changes: 24 additions & 9 deletions opal/corelib/string.rb
Original file line number Diff line number Diff line change
@@ -127,24 +127,39 @@ def [](index, length = undefined)
return self.substr(index, length);
}
if (index < 0) {
index += self.length;
}
if (length == null) {
if (index >= self.length || index < 0) {
if (index.$$is_number) {
if (index < 0) {
index += size;
}
if (length == null) {
if (index >= size || index < 0) {
return nil;
}
return self.substr(index, 1);
}
if (index > size || index < 0) {
return nil;
}
return self.substr(index, 1);
return self.substr(index, length);
}
if (index > self.length || index < 0) {
return nil;
if (index.$$is_string) {
return self.indexOf(index) !== -1 ? index : nil
}
return self.substr(index, length);
if (index.$$is_regexp) {
#{raise NotImplementedError}
}
}

raise TypeError, "type mismatch: #{index.class} given"
end

def capitalize
2 changes: 2 additions & 0 deletions opal/corelib/string/inheritance.rb
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ def self.inherited(klass)
end

class String::Wrapper
`def.$$is_string = true`

def self.allocate(string = "")
obj = super()
`obj.literal = string`
12 changes: 4 additions & 8 deletions spec/filters/bugs/string.rb
Original file line number Diff line number Diff line change
@@ -30,10 +30,8 @@
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 String returns other_str if it occurs in self"
fails "String#[] with String returns nil if there is no match"
fails "String#[] with String doesn't call to_str on its argument"
fails "String#[] with String returns a subclass instance when given a subclass instance"
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"
@@ -160,11 +158,9 @@
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 String returns other_str if it occurs in self"
fails "String#slice with String returns nil if there is no match"
fails "String#slice with String doesn't call to_str on its argument"
fails "String#slice with String returns a subclass instance when given a subclass instance"
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"
4 changes: 2 additions & 2 deletions spec/rubyspecs
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ corelib/core/string/each_byte_spec
corelib/core/string/each_char_spec
corelib/core/string/each_codepoint_spec
corelib/core/string/each_line_spec
# corelib/core/string/element_reference_spec - fails to find a shared group - "String#[] with Regexp"
corelib/core/string/element_reference_spec
corelib/core/string/element_set_spec
corelib/core/string/empty_spec
corelib/core/string/encode_spec
@@ -149,7 +149,7 @@ corelib/core/string/rstrip_spec
# corelib/core/string/scan_spec - infinite loop on parsing
corelib/core/string/setbyte_spec
corelib/core/string/size_spec
# corelib/core/string/slice_spec - fails to find a shared thing (same as element_reference_spec)
corelib/core/string/slice_spec
corelib/core/string/split_spec
corelib/core/string/squeeze_spec
corelib/core/string/start_with_spec