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: 3e30534abaf4
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1459f0460fc0
Choose a head ref
  • 4 commits
  • 37 files changed
  • 1 contributor

Commits on Nov 22, 2013

  1. Compliancy fixes for String#chars

    meh committed Nov 22, 2013
    Copy the full SHA
    fbef221 View commit details
  2. Compliancy fixes for String#to_f

    meh committed Nov 22, 2013
    Copy the full SHA
    b7efafc View commit details
  3. Add proper String cloning

    meh committed Nov 22, 2013
    Copy the full SHA
    9d7864f View commit details
  4. Copy the full SHA
    1459f04 View commit details
Showing with 492 additions and 796 deletions.
  1. +24 −5 opal/core/string.rb
  2. +0 −10 spec/opal/core/string/chop_spec.rb
  3. +0 −13 spec/opal/core/string/chr_spec.rb
  4. +0 −8 spec/opal/core/string/clone_spec.rb
  5. +0 −13 spec/opal/core/string/comparison_spec.rb
  6. +0 −8 spec/opal/core/string/dup_spec.rb
  7. +0 −96 spec/opal/core/string/element_reference_spec.rb
  8. +0 −49 spec/opal/core/string/fixtures/classes.rb
  9. +0 −9 spec/opal/core/string/format_spec.rb
  10. +0 −15 spec/opal/core/string/freeze_spec.rb
  11. +0 −31 spec/opal/core/string/gsub_spec.rb
  12. +0 −9 spec/opal/core/string/lines_spec.rb
  13. +0 −32 spec/opal/core/string/ljust_spec.rb
  14. +0 −7 spec/opal/core/string/lstrip_spec.rb
  15. +0 −49 spec/opal/core/string/match_spec.rb
  16. +0 −10 spec/opal/core/string/next_spec.rb
  17. +0 −9 spec/opal/core/string/ord_spec.rb
  18. +0 −10 spec/opal/core/string/partition_spec.rb
  19. +0 −50 spec/opal/core/string/rindex_spec.rb
  20. +0 −32 spec/opal/core/string/rjust_spec.rb
  21. +0 −7 spec/opal/core/string/rstrip_spec.rb
  22. +0 −66 spec/opal/core/string/scan_spec.rb
  23. +0 −74 spec/opal/core/string/slice_spec.rb
  24. +0 −5 spec/opal/core/string/split_spec.rb
  25. +0 −6 spec/opal/core/string/strip_spec.rb
  26. +0 −38 spec/opal/core/string/sub_spec.rb
  27. +0 −10 spec/opal/core/string/succ_spec.rb
  28. +0 −5 spec/opal/core/string/sum_spec.rb
  29. +0 −14 spec/opal/core/string/to_f_spec.rb
  30. +0 −25 spec/opal/core/string/to_i_spec.rb
  31. +0 −31 spec/opal/core/string/tr_s_spec.rb
  32. +0 −31 spec/opal/core/string/tr_spec.rb
  33. +251 −14 spec/opal/filters/bugs/string.rb
  34. +24 −4 spec/opal/filters/unsupported/encoding.rb
  35. +144 −0 spec/opal/filters/unsupported/immutable_strings.rb
  36. +10 −0 spec/opal/filters/unsupported/tainted.rb
  37. +39 −1 spec/opal/rubyspecs
29 changes: 24 additions & 5 deletions opal/core/string.rb
Original file line number Diff line number Diff line change
@@ -166,8 +166,10 @@ def center(width, padstr = ' ')
}
end

def chars
each_char.to_a
def chars(&block)
return each_char.to_a unless block

each_char(&block)
end

def chomp(separator = $/)
@@ -216,7 +218,15 @@ def chr
end

def clone
`self.slice()`
copy = `self.slice()`
copy.initialize_clone(self)
copy
end

def dup
copy = `self.slice()`
copy.initialize_dup(self)
copy
end

def count(str)
@@ -703,9 +713,18 @@ def to_a

def to_f
%x{
var result = parseFloat(#{self});
if (self.charAt(0) === '_') {
return 0;
}
return isNaN(result) ? 0 : result;
var result = parseFloat(self.replace(/_/g, ''));
if (isNaN(result) || result == Infinity || result == -Infinity) {
return 0;
}
else {
return result;
}
}
end

10 changes: 0 additions & 10 deletions spec/opal/core/string/chop_spec.rb

This file was deleted.

13 changes: 0 additions & 13 deletions spec/opal/core/string/chr_spec.rb

This file was deleted.

8 changes: 0 additions & 8 deletions spec/opal/core/string/clone_spec.rb

This file was deleted.

13 changes: 0 additions & 13 deletions spec/opal/core/string/comparison_spec.rb

This file was deleted.

8 changes: 0 additions & 8 deletions spec/opal/core/string/dup_spec.rb

This file was deleted.

96 changes: 0 additions & 96 deletions spec/opal/core/string/element_reference_spec.rb

This file was deleted.

49 changes: 0 additions & 49 deletions spec/opal/core/string/fixtures/classes.rb

This file was deleted.

9 changes: 0 additions & 9 deletions spec/opal/core/string/format_spec.rb

This file was deleted.

15 changes: 0 additions & 15 deletions spec/opal/core/string/freeze_spec.rb

This file was deleted.

31 changes: 0 additions & 31 deletions spec/opal/core/string/gsub_spec.rb

This file was deleted.

9 changes: 0 additions & 9 deletions spec/opal/core/string/lines_spec.rb

This file was deleted.

32 changes: 0 additions & 32 deletions spec/opal/core/string/ljust_spec.rb

This file was deleted.

7 changes: 0 additions & 7 deletions spec/opal/core/string/lstrip_spec.rb

This file was deleted.

49 changes: 0 additions & 49 deletions spec/opal/core/string/match_spec.rb

This file was deleted.

10 changes: 0 additions & 10 deletions spec/opal/core/string/next_spec.rb

This file was deleted.

9 changes: 0 additions & 9 deletions spec/opal/core/string/ord_spec.rb

This file was deleted.

10 changes: 0 additions & 10 deletions spec/opal/core/string/partition_spec.rb

This file was deleted.

50 changes: 0 additions & 50 deletions spec/opal/core/string/rindex_spec.rb

This file was deleted.

32 changes: 0 additions & 32 deletions spec/opal/core/string/rjust_spec.rb

This file was deleted.

7 changes: 0 additions & 7 deletions spec/opal/core/string/rstrip_spec.rb

This file was deleted.

66 changes: 0 additions & 66 deletions spec/opal/core/string/scan_spec.rb

This file was deleted.

74 changes: 0 additions & 74 deletions spec/opal/core/string/slice_spec.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/opal/core/string/split_spec.rb

This file was deleted.

6 changes: 0 additions & 6 deletions spec/opal/core/string/strip_spec.rb

This file was deleted.

38 changes: 0 additions & 38 deletions spec/opal/core/string/sub_spec.rb

This file was deleted.

10 changes: 0 additions & 10 deletions spec/opal/core/string/succ_spec.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/opal/core/string/sum_spec.rb

This file was deleted.

14 changes: 0 additions & 14 deletions spec/opal/core/string/to_f_spec.rb

This file was deleted.

25 changes: 0 additions & 25 deletions spec/opal/core/string/to_i_spec.rb

This file was deleted.

31 changes: 0 additions & 31 deletions spec/opal/core/string/tr_s_spec.rb

This file was deleted.

31 changes: 0 additions & 31 deletions spec/opal/core/string/tr_spec.rb

This file was deleted.

265 changes: 251 additions & 14 deletions spec/opal/filters/bugs/string.rb

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions spec/opal/filters/unsupported/encoding.rb
Original file line number Diff line number Diff line change
@@ -3,12 +3,32 @@
fails "Array#inspect use US-ASCII encoding if the default external encoding is not ascii compatible"
fails "Array#inspect use the default external encoding if it is ascii compatible"
fails "Array#inspect returns a US-ASCII string for an empty Array"
fails "Array#to_s raises if inspected result is not default external encoding"
fails "Array#to_s use US-ASCII encoding if the default external encoding is not ascii compatible"
fails "Array#to_s use the default external encoding if it is ascii compatible"
fails "Array#to_s returns a US-ASCII string for an empty Array"

fails "Array#join fails for arrays with incompatibly-encoded strings"
fails "Array#join uses the widest common encoding when other strings are incompatible"
fails "Array#join uses the first encoding when other strings are compatible"
fails "Array#join returns a US-ASCII string for an empty Array"

fails "Array#to_s raises if inspected result is not default external encoding"
fails "Array#to_s use US-ASCII encoding if the default external encoding is not ascii compatible"
fails "Array#to_s use the default external encoding if it is ascii compatible"
fails "Array#to_s returns a US-ASCII string for an empty Array"

fails "String#<=> with String returns -1 if self is bytewise less than other"
fails "String#<=> with String returns 1 if self is bytewise greater than other"
fails "String#<=> with String returns 0 if self and other contain identical ASCII-compatible bytes in different encodings"
fails "String#<=> with String does not return 0 if self and other contain identical non-ASCII-compatible bytes in different encodings"

fails "String.allocate returns a fully-formed String"
fails "String.allocate returns a binary String"

fails "String#capitalize is locale insensitive (only upcases a-z and only downcases A-Z)"

fails "String#chars is unicode aware"

fails "String#downcase is locale insensitive (only replaces A-Z)"

fails "String#each_char is unicode aware"

fails "String#upcase is locale insensitive (only replaces a-z)"
end
144 changes: 144 additions & 0 deletions spec/opal/filters/unsupported/immutable_strings.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,34 @@
fails "Time#strftime with %z formats a local time with positive UTC offset as '+HHMM'"
fails "Time#strftime with %z formats a local time with negative UTC offset as '-HHMM'"

fails "String#<< concatenates the given argument to self and returns self"
fails "String#<< converts the given argument to a String using to_str"
fails "String#<< converts the given argument to a String using to_str"
fails "String#<< raises a TypeError if the given argument can't be converted to a String"
fails "String#<< raises a RuntimeError when self is frozen"
fails "String#<< works when given a subclass instance"
fails "String#<< taints self if other is tainted"
fails "String#<< untrusts self if other is untrusted"
fails "String#<< with Integer concatencates the argument interpreted as a codepoint"
fails "String#<< with Integer returns a ASCII-8BIT string if self is US-ASCII and the argument is between 128-255 (inclusive)"
fails "String#<< with Integer raises RangeError if the argument is an invalid codepoint for self's encoding"
fails "String#<< with Integer raises RangeError if the argument is negative"
fails "String#<< with Integer doesn't call to_int on its argument"
fails "String#<< with Integer raises a RuntimeError when self is frozen"
fails "String#<< when self is in an ASCII-incompatible encoding incompatible with the argument's encoding uses self's encoding if both are empty"
fails "String#<< when self is in an ASCII-incompatible encoding incompatible with the argument's encoding uses self's encoding if the argument is empty"
fails "String#<< when self is in an ASCII-incompatible encoding incompatible with the argument's encoding uses the argument's encoding if self is empty"
fails "String#<< when self is in an ASCII-incompatible encoding incompatible with the argument's encoding raises Encoding::CompatibilityError if neither are empty"
fails "String#<< when the argument is in an ASCII-incompatible encoding incompatible with self's encoding uses self's encoding if both are empty"
fails "String#<< when the argument is in an ASCII-incompatible encoding incompatible with self's encoding uses self's encoding if the argument is empty"
fails "String#<< when the argument is in an ASCII-incompatible encoding incompatible with self's encoding uses the argument's encoding if self is empty"
fails "String#<< when the argument is in an ASCII-incompatible encoding incompatible with self's encoding raises Encoding::CompatibilityError if neither are empty"
fails "String#<< when self and the argument are in different ASCII-compatible encodings uses self's encoding if both are ASCII-only"
fails "String#<< when self and the argument are in different ASCII-compatible encodings uses self's encoding if the argument is ASCII-only"
fails "String#<< when self and the argument are in different ASCII-compatible encodings uses the argument's encoding if self is ASCII-only"
fails "String#<< when self and the argument are in different ASCII-compatible encodings raises Encoding::CompatibilityError if neither are ASCII-only"
fails "String#<< when self is ASCII-8BIT and argument is US-ASCII uses ASCII-8BIT encoding"

fails "String#chomp when passed no argument returns a copy of the String when it is not modified"

fails "String#chop returns a new string when applied to an empty string"
@@ -21,4 +49,120 @@
fails "String#chop! returns nil when called on an empty string"
fails "String#chop! raises a RuntimeError on a frozen instance that is modified"
fails "String#chop! raises a RuntimeError on a frozen instance that would not be modified"

fails "String#gsub! with pattern and Hash returns self with all occurrences of pattern replaced with the value of the corresponding hash key"
fails "String#gsub! with pattern and Hash ignores keys that don't correspond to matches"
fails "String#gsub! with pattern and Hash replaces self with an empty string if the pattern matches but the hash specifies no replacements"
fails "String#gsub! with pattern and Hash ignores non-String keys"
fails "String#gsub! with pattern and Hash uses a key's value as many times as needed"
fails "String#gsub! with pattern and Hash uses the hash's default value for missing keys"
fails "String#gsub! with pattern and Hash coerces the hash values with #to_s"
fails "String#gsub! with pattern and Hash coerces the hash values with #to_s"
fails "String#gsub! with pattern and Hash uses the hash's value set from default_proc for missing keys"
fails "String#gsub! with pattern and Hash sets $~ to MatchData of last match and nil when there's none for access from outside"
fails "String#gsub! with pattern and Hash doesn't interpolate special sequences like \\1 for the block's return value"
fails "String#gsub! with pattern and Hash keeps untrusted state"
fails "String#gsub! with pattern and Hash untrusts self if a hash value is untrusted"
fails "String#gsub! with pattern and Hash keeps tainted state"
fails "String#gsub! with pattern and Hash taints self if a hash value is tainted"
fails "String#gsub! with pattern and replacement modifies self in place and returns self"
fails "String#gsub! with pattern and replacement taints self if replacement is tainted"
fails "String#gsub! with pattern and replacement untrusts self if replacement is untrusted"
fails "String#gsub! with pattern and replacement returns nil if no modifications were made"
fails "String#gsub! with pattern and replacement raises a RuntimeError when self is frozen"
fails "String#gsub! with pattern and block modifies self in place and returns self"
fails "String#gsub! with pattern and block taints self if block's result is tainted"
fails "String#gsub! with pattern and block untrusts self if block's result is untrusted"
fails "String#gsub! with pattern and block returns nil if no modifications were made"
fails "String#gsub! with pattern and block raises a RuntimeError when self is frozen"
fails "String#gsub! with pattern and block uses the compatible encoding if they are compatible"
fails "String#gsub! with pattern and block raises an Encoding::CompatibilityError if the encodings are not compatible"
fails "String#gsub! with pattern and block replaces the incompatible part properly even if the encodings are not compatible"

fails "String#lstrip! modifies self in place and returns self"
fails "String#lstrip! returns nil if no modifications were made"
fails "String#lstrip! raises a RuntimeError on a frozen instance that is modified"
fails "String#lstrip! raises a RuntimeError on a frozen instance that would not be modified"

fails "String#next! is equivalent to succ, but modifies self in place (still returns self)"
fails "String#next! raises a RuntimeError if self is frozen"

fails "String#rstrip! modifies self in place and returns self"
fails "String#rstrip! modifies self removing trailing NULL bytes and whitespace"
fails "String#rstrip! returns nil if no modifications were made"
fails "String#rstrip! raises a RuntimeError on a frozen instance that is modified"
fails "String#rstrip! raises a RuntimeError on a frozen instance that would not be modified"

fails "String#slice! with index deletes and return the char at the given position"
fails "String#slice! with index returns nil if idx is outside of self"
fails "String#slice! with index raises a RuntimeError if self is frozen"
fails "String#slice! with index calls to_int on index"
fails "String#slice! with index, length deletes and returns the substring at idx and the given length"
fails "String#slice! with index, length always taints resulting strings when self is tainted"
fails "String#slice! with index, length returns nil if the length is negative"
fails "String#slice! with index, length raises a RuntimeError if self is frozen"
fails "String#slice! with index, length calls to_int on idx and length"
fails "String#slice! with index, length returns subclass instances"
fails "String#slice! Range deletes and return the substring given by the offsets of the range"
fails "String#slice! Range returns nil if the given range is out of self"
fails "String#slice! Range always taints resulting strings when self is tainted"
fails "String#slice! Range returns subclass instances"
fails "String#slice! Range calls to_int on range arguments"
fails "String#slice! Range works with Range subclasses"
fails "String#slice! Range raises a RuntimeError on a frozen instance that is modified"
fails "String#slice! Range raises a RuntimeError on a frozen instance that would not be modified"
fails "String#slice! with Regexp deletes and returns the first match from self"
fails "String#slice! with Regexp returns nil if there was no match"
fails "String#slice! with Regexp always taints resulting strings when self or regexp is tainted"
fails "String#slice! with Regexp doesn't taint self when regexp is tainted"
fails "String#slice! with Regexp returns subclass instances"
fails "String#slice! with Regexp sets $~ to MatchData when there is a match and nil when there's none"
fails "String#slice! with Regexp raises a RuntimeError on a frozen instance that is modified"
fails "String#slice! with Regexp raises a RuntimeError on a frozen instance that would not be modified"
fails "String#slice! with Regexp, index deletes and returns the capture for idx from self"
fails "String#slice! with Regexp, index always taints resulting strings when self or regexp is tainted"
fails "String#slice! with Regexp, index doesn't taint self when regexp is tainted"
fails "String#slice! with Regexp, index returns nil if there was no match"
fails "String#slice! with Regexp, index returns nil if there is no capture for idx"
fails "String#slice! with Regexp, index calls to_int on idx"
fails "String#slice! with Regexp, index returns subclass instances"
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, index raises a RuntimeError if self is frozen"
fails "String#slice! with String removes and returns the first occurrence of other_str from self"
fails "String#slice! with String taints resulting strings when other is tainted"
fails "String#slice! with String doesn't set $~"
fails "String#slice! with String returns nil if self does not contain other"
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 String raises a RuntimeError if self is frozen"

fails "String#strip! modifies self in place and returns self"
fails "String#strip! returns nil if no modifications where made"
fails "String#strip! modifies self removing trailing NULL bytes and whitespace"
fails "String#strip! raises a RuntimeError on a frozen instance that is modified"
fails "String#strip! raises a RuntimeError on a frozen instance that would not be modified"

fails "String#sub! with pattern, replacement modifies self in place and returns self"
fails "String#sub! with pattern, replacement taints self if replacement is tainted"
fails "String#sub! with pattern, replacement returns nil if no modifications were made"
fails "String#sub! with pattern, replacement raises a RuntimeError when self is frozen"
fails "String#sub! with pattern and block modifies self in place and returns self"
fails "String#sub! with pattern and block sets $~ for access from the block"
fails "String#sub! with pattern and block taints self if block's result is tainted"
fails "String#sub! with pattern and block returns nil if no modifications were made"
fails "String#sub! with pattern and block raises a RuntimeError if the string is modified while substituting"
fails "String#sub! with pattern and block raises a RuntimeError when self is frozen"

fails "String#succ! is equivalent to succ, but modifies self in place (still returns self)"
fails "String#succ! raises a RuntimeError if self is frozen"

fails "String#tr! modifies self in place"
fails "String#tr! returns nil if no modification was made"
fails "String#tr! does not modify self if from_str is empty"
fails "String#tr! raises a RuntimeError if self is frozen"

fails "String#tr_s! modifies self in place"
fails "String#tr_s! returns nil if no modification was made"
fails "String#tr_s! does not modify self if from_str is empty"
fails "String#tr_s! raises a RuntimeError if self is frozen"
end
10 changes: 10 additions & 0 deletions spec/opal/filters/unsupported/tainted.rb
Original file line number Diff line number Diff line change
@@ -77,14 +77,24 @@

fails "String#chop taints result when self is tainted"

fails "String#ljust with length, padding taints result when self or padstr is tainted"
fails "String#ljust with length, padding when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self"

fails "String#reverse taints the result if self is tainted"

fails "String#rjust with length, padding taints result when self or padstr is tainted"
fails "String#rjust with length, padding when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self"

fails "String#swapcase taints resulting string when self is tainted"

fails "String#to_s taints the result when self is tainted"

fails "String#to_str taints the result when self is tainted"

fails "String#tr taints the result when self is tainted"

fails "String#tr_s taints the result when self is tainted"

fails "String#upcase taints result when self is tainted"

fails "Pathname.new is tainted if path is tainted"
40 changes: 39 additions & 1 deletion spec/opal/rubyspecs
Original file line number Diff line number Diff line change
@@ -225,25 +225,61 @@ core/matchdata/to_a_spec
core/range/begin_spec
core/range/end_spec

core/string/allocate_spec
core/string/append_spec
core/string/ascii_only_spec
core/string/capitalize_spec
core/string/casecmp_spec
core/string/case_compare_spec
core/string/center_spec
core/string/chars_spec
core/string/chomp_spec
core/string/chop_spec
core/string/chr_spec
core/string/clear_spec
core/string/codepoints_spec
core/string/comparison_spec
core/string/downcase_spec
core/string/dup_spec
core/string/each_char_spec
core/string/each_line_spec
#core/string/element_reference_spec - fails to find a shared thing
core/string/empty_spec
core/string/end_with_spec
core/string/gsub_spec
core/string/include_spec
core/string/index_spec
core/string/intern_spec
core/string/length_spec
core/string/size_spec
core/string/lines_spec
core/string/ljust_spec
core/string/lstrip_spec
#core/string/match_spec - fails to find a shared thing
core/string/next_spec
core/string/ord_spec
core/string/partition_spec
core/string/reverse_spec
core/string/rindex_spec
core/string/rjust_spec
core/string/rstrip_spec
#core/string/scan_spec - infinite loop
core/string/size_spec
#core/string/slice_spec - fails to find a shared thing
core/string/split_spec
core/string/start_with_spec
core/string/strip_spec
core/string/sub_spec
core/string/succ_spec
core/string/sum_spec
core/string/swapcase_spec
core/string/to_a_spec
core/string/to_f_spec
#core/string/to_i_spec
core/string/to_str_spec
core/string/to_sym_spec
core/string/to_s_spec
core/string/tr_spec
core/string/tr_s_spec
core/string/upcase_spec

core/symbol/to_proc_spec
@@ -266,7 +302,9 @@ core/time/friday_spec
core/time/saturday_spec
core/time/strftime_spec

#core/regexp/escape_spec
core/regexp/match_spec
#core/regexp/quote_spec

language/alias_spec
language/and_spec