Skip to content

Commit e7ccf31

Browse files
committed
Add all remaining Struct specs from rubyspec
1 parent bd10abe commit e7ccf31

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

opal/corelib/struct.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,6 @@ def inspect
136136

137137
result
138138
end
139+
140+
alias to_s inspect
139141
end

spec/opal/filters/bugs/struct.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,28 @@
22
fails "Struct#[] fails when it does not know about the requested attribute"
33
fails "Struct#[] fails if not passed a string, symbol, or integer"
44

5+
fails "Struct#[]= fails when trying to assign attributes which don't exist"
6+
7+
fails "Struct#== returns true if the other has all the same fields"
8+
fails "Struct#== handles recursive structures by returning false if a difference can be found "
9+
10+
fails "Struct#eql? returns false if any corresponding elements are not #eql?"
11+
fails "Struct#eql? handles recursive structures by returning false if a difference can be found "
12+
13+
fails "Struct#hash returns the same fixnum for structs with the same content"
14+
fails "Struct#hash returns the same value if structs are #eql?"
15+
fails "Struct#hash returns the same hash for recursive structs"
16+
17+
fails "Struct#to_h returns a Hash with members as keys"
18+
fails "Struct#to_h returns a Hash that is independent from the struct"
19+
520
fails "Struct#initialize can be overriden"
621

22+
fails "Struct#inspect returns a string representation of some kind"
23+
24+
fails "Struct#instance_variables returns an array with one name if an instance variable is added"
25+
fails "Struct#instance_variables returns an empty array if only attributes are defined"
26+
727
fails "Struct.new fails with too many arguments"
828
fails "Struct.new creates a constant in subclass' namespace"
929
fails "Struct.new raises a TypeError if object is not a Symbol"
@@ -12,4 +32,9 @@
1232
fails "Struct.new does not create a constant with symbol as first argument"
1333
fails "Struct.new creates a new anonymous class with nil first argument"
1434
fails "Struct.new calls to_str on its first argument (constant name)"
35+
36+
fails "Struct#values_at fails when passed unsupported types"
37+
fails "Struct#values_at returns an array of values"
38+
39+
fails "Struct anonymous class instance methods Enumerable methods should work"
1540
end

spec/opal/rubyspecs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,25 @@ core/symbol/to_proc_spec
320320
core/struct/each_pair_spec
321321
core/struct/each_spec
322322
core/struct/element_reference_spec
323+
core/struct/element_set_spec
324+
core/struct/eql_spec
325+
core/struct/equal_value_spec
326+
core/struct/hash_spec
327+
core/struct/initialize_copy_spec
323328
core/struct/initialize_spec
329+
core/struct/inspect_spec
330+
core/struct/instance_variables_spec
331+
core/struct/length_spec
332+
core/struct/members_spec
324333
core/struct/new_spec
334+
core/struct/select_spec
335+
core/struct/size_spec
336+
core/struct/struct_spec
337+
core/struct/to_a_spec
338+
core/struct/to_h_spec
339+
core/struct/to_s_spec
340+
core/struct/values_at_spec
341+
core/struct/values_spec
325342

326343
core/class/new_spec
327344

0 commit comments

Comments
 (0)