Skip to content

Commit

Permalink
Enable shared groups from rubyspec
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Sep 21, 2013
1 parent 628394a commit 5905e6a
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 270 deletions.
17 changes: 16 additions & 1 deletion corelib/array.rb
Expand Up @@ -375,6 +375,8 @@ def clone
end

def collect(&block)
return enum_for :collect unless block_given?

%x{
var result = [];
Expand Down Expand Up @@ -500,6 +502,8 @@ def delete_at(index)
end

def delete_if(&block)
return enum_for :delete_if unless block_given?

%x{
for (var i = 0, length = #{self}.length, value; i < length; i++) {
if ((value = block(#{self}[i])) === $breaker) {
Expand Down Expand Up @@ -546,6 +550,8 @@ def each(&block)
end

def each_index(&block)
return enum_for :each_index unless block_given?

`for (var i = 0, length = #{self}.length; i < length; i++) {`
yield `i`
`}`
Expand Down Expand Up @@ -847,6 +853,8 @@ def rassoc(object)
end

def reject(&block)
return enum_for :reject unless block_given?

%x{
var result = [];
Expand All @@ -864,6 +872,8 @@ def reject(&block)
end

def reject!(&block)
return enum_for :reject! unless block_given?

%x{
var original = #{self}.length;
#{ delete_if &block };
Expand All @@ -888,8 +898,9 @@ def reverse!
end

def reverse_each(&block)
reverse.each &block
return enum_for :reverse_each unless block_given?

reverse.each &block
self
end

Expand Down Expand Up @@ -922,6 +933,8 @@ def rindex(object = undefined, &block)
end

def select(&block)
return enum_for :select unless block_given?

%x{
var result = [];
Expand All @@ -942,6 +955,8 @@ def select(&block)
end

def select!(&block)
return enum_for :select! unless block_given?

%x{
var original = #{self}.length;
#{ keep_if &block };
Expand Down
18 changes: 16 additions & 2 deletions corelib/kernel.rb
Expand Up @@ -106,7 +106,18 @@ def define_singleton_method(name, &body)
end

def dup
self.class.allocate
copy = self.class.allocate

%x{
for (var name in #{self}) {
if (name.charAt(0) !== '$') {
copy[name] = #{self}[name];
}
}
}

copy.initialize_copy self
copy
end

def enum_for(method = :each, *args)
Expand Down Expand Up @@ -260,6 +271,9 @@ def hash
`#{self}._id`
end

def initialize_copy(other)
end

def inspect
to_s
end
Expand Down Expand Up @@ -403,7 +417,7 @@ def rand(max = undefined)
}
end

def respond_to?(name)
def respond_to?(name, include_all = false)
%x{
var body = #{self}['$' + name];
return (!!body) && !body.rb_stub;
Expand Down
2 changes: 1 addition & 1 deletion corelib/runtime.js
Expand Up @@ -272,7 +272,7 @@

// Arity count error dispatcher
Opal.ac = function(actual, expected, object, meth) {
var inspect = ((typeof(object) !== 'function') ? object.constructor._name + '#' : object._name + '.') + meth;
var inspect = ((typeof(object) !== 'function') ? object._klass._name + '#' : object._name + '.') + meth;
var msg = '[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')';
throw Opal.ArgumentError.$new(msg);
};
Expand Down
56 changes: 56 additions & 0 deletions spec/filters/bugs/array.rb
Expand Up @@ -4,6 +4,21 @@

fails "Array#clone copies frozen status from the original"
fails "Array#clone copies singleton methods"
fails "Array#clone copies untrusted status from the original"
fails "Array#clone copies taint status from the original"
fails "Array#clone creates a new array containing all elements or the original"
fails "Array#clone returns an Array or a subclass instance"

fails "Array#collect! when frozen raises a RuntimeError when calling #each on the returned Enumerator when empty"
fails "Array#collect! when frozen raises a RuntimeError when calling #each on the returned Enumerator"
fails "Array#collect! when frozen raises a RuntimeError when empty"
fails "Array#collect! when frozen raises a RuntimeError"
fails "Array#collect! keeps untrusted status"
fails "Array#collect! keeps tainted status"
fails "Array#collect! returns an Enumerator when no block given, and the enumerator can modify the original array"

fails "Array#collect does not copy untrusted status"
fails "Array#collect does not copy tainted status"

fails "Array#combination generates from a defensive copy, ignoring mutations"
fails "Array#combination yields a partition consisting of only singletons"
Expand Down Expand Up @@ -50,6 +65,11 @@

fails "Array#drop raises an ArgumentError if the number of elements specified is negative"

fails "Array#dup copies untrusted status from the original"
fails "Array#dup copies taint status from the original"
fails "Array#dup creates a new array containing all elements or the original"
fails "Array#dup returns an Array or a subclass instance"

fails "Array#[]= does not call to_ary on rhs array subclasses for multi-element sets"
fails "Array#[]= calls to_ary on its rhs argument for multi-element sets"
fails "Array#[]= raises an IndexError when passed indexes out of bounds"
Expand All @@ -67,6 +87,12 @@
fails "Array#[]= does nothing if the section defined by range has negative width and the rhs is an empty array"

fails "Array#eql? returns false if any corresponding elements are not #eql?"
fails "Array#eql? ignores array class differences"
fails "Array#eql? does not call #to_ary on Array subclasses"
fails "Array#eql? does not call #to_ary on its argument"
fails "Array#eql? handles well recursive arrays"
fails "Array#eql? returns false immediately when sizes of the arrays differ"
fails "Array#eql? returns true if corresponding elements are #eql?"

fails "Array#fetch tries to convert the passed argument to an Integer using #to_int"
fails "Array#fetch raises a TypeError when the passed argument can't be coerced to Integer"
Expand Down Expand Up @@ -96,13 +122,34 @@
fails "Array#& tries to convert the passed argument to an Array using #to_ary"
fails "Array#& determines equivalence between elements in the sense of eql?"

fails "Array#index returns the index of the first element == to object"
fails "Array#index given no argument and no block produces an Enumerator"

fails "Array#join calls #to_str to convert the separator to a String"
fails "Array#join does not call #to_str on the separator if the array is empty"
fails "Array#join raises a TypeError if the separator cannot be coerced to a String by calling #to_str"
fails "Array#join raises a TypeError if passed false as the separator"

fails "Array#keep_if returns an enumerator if no block is given"
fails "Array#keep_if on frozen objects returns an Enumerator if no block is given"
fails "Array#keep_if on frozen objects with truthy block keeps elements after any exception"
fails "Array#keep_if on frozen objects with truthy block raises a RuntimeError"
fails "Array#keep_if on frozen objects with falsy block keeps elements after any exception"
fails "Array#keep_if on frozen objects with falsy block raises a RuntimeError"

fails "Array#last tries to convert the passed argument to an Integer usinig #to_int"

fails "Array#map! when frozen raises a RuntimeError when calling #each on the returned Enumerator when empty"
fails "Array#map! when frozen raises a RuntimeError when calling #each on the returned Enumerator"
fails "Array#map! when frozen raises a RuntimeError when empty"
fails "Array#map! when frozen raises a RuntimeError"
fails "Array#map! keeps untrusted status"
fails "Array#map! keeps tainted status"
fails "Array#map! returns an Enumerator when no block given, and the enumerator can modify the original array"

fails "Array#map does not copy untrusted status"
fails "Array#map does not copy tainted status"

fails "Array#- removes an identical item even when its #eql? isn't reflexive"
fails "Array#- doesn't remove an item with the same hash but not #eql?"
fails "Array#- removes an item identified as equivalent via #hash and #eql?"
Expand Down Expand Up @@ -135,10 +182,19 @@

fails "Array#reject! returns an Enumerator if no block given, and the array is frozen"

fails "Array#replace raises a RuntimeError on a frozen array"
fails "Array#replace does not call #to_ary on Array subclasses"
fails "Array#replace tries to convert the passed argument to an Array using #to_ary"

fails "Array#rindex rechecks the array size during iteration"
fails "Array#rindex returns the first index backwards from the end where element == to object"

fails "Array#select returns a new array of elements for which block is true"

fails "Array#select! on frozen objects with truthy block keeps elements after any exception"
fails "Array#select! on frozen objects with truthy block raises a RuntimeError"
fails "Array#select! on frozen objects with falsy block keeps elements after any exception"
fails "Array#select! on frozen objects with falsy block raises a RuntimeError"

fails "Array#shift passed a number n as an argument raises an ArgumentError if more arguments are passed"
fails "Array#shift passed a number n as an argument raises a TypeError when the passed n can be coerced to Integer"
Expand Down
45 changes: 45 additions & 0 deletions spec/filters/bugs/enumerable.rb
@@ -1,4 +1,8 @@
opal_filter "Enumerable" do
fails "Enumerable#detect passes the ifnone proc to the enumerator"
fails "Enumerable#detect returns an enumerator when no block given"
fails "Enumerable#detect passes through the values yielded by #each_with_index"

fails "Enumerable#drop passed a number n as an argument tries to convert n to an Integer using #to_int"
fails "Enumerable#drop passed a number n as an argument raises a TypeError when the passed n can be coerced to Integer"

Expand All @@ -16,15 +20,56 @@
fails "Enumerable#each_with_index binds splat arguments properly"
fails "Enumerable#each_with_index passes extra parameters to each"

fails "Enumerable#entries passes arguments to each"

fails "Enumerable#find passes through the values yielded by #each_with_index"
fails "Enumerable#find returns an enumerator when no block given"
fails "Enumerable#find passes the ifnone proc to the enumerator"

fails "Enumerable#find_all returns an enumerator when no block given"
fails "Enumerable#find_all passes through the values yielded by #each_with_index"

fails "Enumerable#find_index gathers initial args as elements when each yields multiple"

fails "Enumerable#first when passed an argument consumes only what is needed"
fails "Enumerable#first when passed an argument raises a TypeError if the passed argument is not numeric"
fails "Enumerable#first when passed an argument tries to convert the passed argument to an Integer using #to_int"
fails "Enumerable#first when passed an argument raises an ArgumentError when count is negative"

fails "Enumerable#grep can use $~ in the block when used with a Regexp"

fails "Enumerable#group_by returns a hash without default_proc"
fails "Enumerable#group_by gathers whole arrays as elements when each yields multiple"

fails "Enumerable#inject returns nil when fails(legacy rubycon)"
fails "Enumerable#inject without inject arguments(legacy rubycon)"
fails "Enumerable#inject gathers whole arrays as elements when each yields multiple"
fails "Enumerable#inject without argument takes a block with an accumulator (with first element as initial value) and the current element. Value of block becomes new accumulator"
fails "Enumerable#inject can take a symbol argument"
fails "Enumerable#inject ignores the block if two arguments"
fails "Enumerable#inject can take two argument"

fails "Enumerable#max raises an ArgumentError for incomparable elements"
fails "Enumerable#max gathers whole arrays as elements when each yields multiple"

fails "Enumerable#min raises an ArgumentError for incomparable elements"
fails "Enumerable#min gathers whole arrays as elements when each yields multiple"

fails "Enumerable#reduce returns nil when fails(legacy rubycon)"
fails "Enumerable#reduce without inject arguments(legacy rubycon)"
fails "Enumerable#reduce gathers whole arrays as elements when each yields multiple"
fails "Enumerable#reduce without argument takes a block with an accumulator (with first element as initial value) and the current element. Value of block becomes new accumulator"
fails "Enumerable#reduce can take a symbol argument"
fails "Enumerable#reduce ignores the block if two arguments"
fails "Enumerable#reduce can take two argument"

fails "Enumerable#select passes through the values yielded by #each_with_index"
fails "Enumerable#select returns an enumerator when no block given"

fails "Enumerable#take when passed an argument consumes only what is needed"
fails "Enumerable#take when passed an argument raises a TypeError if the passed argument is not numeric"
fails "Enumerable#take when passed an argument tries to convert the passed argument to an Integer using #to_int"
fails "Enumerable#take when passed an argument raises an ArgumentError when count is negative"

fails "Enumerable#to_a passes arguments to each"
end
45 changes: 45 additions & 0 deletions spec/filters/bugs/hash.rb
Expand Up @@ -30,6 +30,12 @@
fails "Hash#delete calls supplied block if the key is not found"
fails "Hash#delete raises a RuntimeError if called on a frozen instance"

fails "Hash#each properly expands (or not) child class's 'each'-yielded args"
fails "Hash#each yields the key only to a block expecting |key,|"

fails "Hash#each_pair properly expands (or not) child class's 'each'-yielded args"
fails "Hash#each_pair yields the key only to a block expecting |key,|"

fails "Hash#[] calls subclass implementations of default"
fails "Hash#[] does not create copies of the immediate default value"
fails "Hash#[] compares keys with eql? semantics"
Expand All @@ -38,18 +44,44 @@
fails "Hash#[] compares keys with the same #hash value via #eql?"
fails "Hash#[] finds a value via an identical key even when its #eql? isn't reflexive"

fails "Hash#[]= raises a RuntimeError if called on a frozen instance"
fails "Hash#[]= duplicates and freezes string keys"
fails "Hash#[]= stores unequal keys that hash to the same value"
fails "Hash#[]= associates the key with the value and return the value"

fails "Hash#fetch raises an ArgumentError when not passed one or two arguments"

fails "Hash#flatten recursively flattens Array values to the given depth"
fails "Hash#flatten raises an TypeError if given a non-Integer argument"

fails "Hash#has_key? compares keys with the same #hash value via #eql?"
fails "Hash#has_key? returns true if argument is a key"

fails "Hash#include? compares keys with the same #hash value via #eql?"
fails "Hash#include? returns true if argument is a key"

fails "Hash#index compares values using =="

fails "Hash#invert compares new keys with eql? semantics"

fails "Hash#keep_if raises an RuntimeError if called on a frozen instance"

fails "Hash#key? compares keys with the same #hash value via #eql?"
fails "Hash#key? returns true if argument is a key"

fails "Hash#key compares values using =="

fails "Hash#member? compares keys with the same #hash value via #eql?"
fails "Hash#member? returns true if argument is a key"

fails "Hash#merge tries to convert the passed argument to a hash using #to_hash"
fails "Hash#merge returns subclass instance for subclasses"

fails "Hash#merge! tries to convert the passed argument to a hash using #to_hash"
fails "Hash#merge! raises a RuntimeError on a frozen instance that is modified"
fails "Hash#merge! checks frozen status before coercing an object with #to_hash"
fails "Hash#merge! raises a RuntimeError on a frozen instance that would not be modified"

fails "Hash.new raises an ArgumentError if more than one argument is passed"
fails "Hash.new raises an ArgumentError if passed both default argument and default block"

Expand All @@ -64,11 +96,24 @@
fails "Hash#reject! processes entries with the same order as delete_if"
fails "Hash#reject! raises a RuntimeError if called on a frozen instance that is modified"
fails "Hash#reject! raises a RuntimeError if called on a frozen instance that would not be modified"
fails "Hash#reject! returns an Enumerator if called on a non-empty hash without a block"
fails "Hash#reject! returns an Enumerator if called on an empty hash without a block"
fails "Hash#reject! returns an Enumerator if called on a frozen instance"

fails "Hash#replace tries to convert the passed argument to a hash using #to_hash"
fails "Hash#replace does not transfer default values"
fails "Hash#replace raises a RuntimeError if called on a frozen instance that is modified"
fails "Hash#replace raises a RuntimeError if called on a frozen instance that would not be modified"

fails "Hash#select returns a Hash of entries for which block is true"
fails "Hash#select! raises a RuntimeError if called on an empty frozen instance"
fails "Hash#select! raises a RuntimeError if called on a frozen instance that would not be modified"

fails "Hash#shift returns (computed) default for empty hashes"
fails "Hash#shift raises a RuntimeError if called on a frozen instance"

fails "Hash#update raises a RuntimeError on a frozen instance that would not be modified"
fails "Hash#update checks frozen status before coercing an object with #to_hash"
fails "Hash#update raises a RuntimeError on a frozen instance that is modified"
fails "Hash#update tries to convert the passed argument to a hash using #to_hash"
end

0 comments on commit 5905e6a

Please sign in to comment.