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

Commits on Apr 2, 2015

  1. Copy the full SHA
    78831c4 View commit details
  2. Merge pull request #787 from vais/string

    String#oct fully compliant with rubyspec
    meh committed Apr 2, 2015
    Copy the full SHA
    4a41f77 View commit details
Showing with 28 additions and 18 deletions.
  1. +28 −0 opal/corelib/string.rb
  2. +0 −18 spec/filters/bugs/string.rb
28 changes: 28 additions & 0 deletions opal/corelib/string.rb
Original file line number Diff line number Diff line change
@@ -722,6 +722,34 @@ def next

alias next! <<

def oct
%x{
var radix = 8;
var string = self.replace(/^\s*([+-]?)(0[bodx])?/, function (match, sign, base) {
switch (base) {
case '0b': radix = 2; break;
case '0o': radix = 8; break;
case '0d': radix = 10; break;
case '0x': radix = 16; break;
}
return sign;
});
if (string.charAt(0) === '_') {
return 0;
}
var result = parseInt(string.replace(/_(?!_)/g, ''), radix);
if (isNaN(result)) {
return 0;
}
return result;
}
end

def ord
`self.charCodeAt(0)`
end
18 changes: 0 additions & 18 deletions spec/filters/bugs/string.rb
Original file line number Diff line number Diff line change
@@ -66,24 +66,6 @@
fails "String#match with [pattern, position] when given a positive position matches the pattern against self starting at an optional index"
fails "String#match with [pattern, position] when given a negative position matches the pattern against self starting at an optional index"

fails "String#oct treats numeric digits as base-8 digits by default"
fails "String#oct accepts numbers formatted as binary"
fails "String#oct accepts numbers formatted as hexadecimal"
fails "String#oct accepts numbers formatted as decimal"
fails "String#oct accepts a single underscore separating digits"
fails "String#oct does not accept a sequence of underscores as part of a number"
fails "String#oct ignores characters that are incorrect for the base-8 digits"
fails "String#oct returns 0 if no characters can be interpreted as a base-8 number"
fails "String#oct returns 0 for strings with leading underscores"
fails "String#oct with a leading minus sign treats numeric digits as base-8 digits by default"
fails "String#oct with a leading minus sign accepts numbers formatted as binary"
fails "String#oct with a leading minus sign accepts numbers formatted as hexadecimal"
fails "String#oct with a leading minus sign accepts numbers formatted as decimal"
fails "String#oct with a leading plus sign treats numeric digits as base-8 digits by default"
fails "String#oct with a leading plus sign accepts numbers formatted as binary"
fails "String#oct with a leading plus sign accepts numbers formatted as hexadecimal"
fails "String#oct with a leading plus sign accepts numbers formatted as decimal"

fails "String.try_convert sends #to_str to the argument and raises TypeError if it's not a kind of String"
fails "String.try_convert does not rescue exceptions raised by #to_str"