opal 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -80,7 +80,7 @@ describe "The or operator" do
|
|
80
80
|
lambda { eval "break true or false" }.should raise_error(SyntaxError, /void value expression/)
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
it "has a lower precedence than 'next' in 'next true or false'" do
|
84
84
|
lambda { eval "next true or false" }.should raise_error(SyntaxError, /void value expression/)
|
85
85
|
end
|
86
86
|
|
@@ -27,7 +27,7 @@ describe "A method call" do
|
|
27
27
|
(obj = @obj).foo4(obj = nil, obj = nil, obj = nil, obj = nil).should == [nil, nil, nil, nil, nil]
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
it "evaluates arguments after receiver" do
|
31
31
|
a = 0
|
32
32
|
# (a += 1; @obj).foo1(a).should == [1, nil]
|
33
33
|
# (a += 1; @obj).foo2(a, a).should == [2, 2, nil]
|
@@ -45,9 +45,8 @@ describe "A method call" do
|
|
45
45
|
a.should == 10
|
46
46
|
end
|
47
47
|
|
48
|
-
pending do
|
49
48
|
ruby_bug "redmine #1034", "1.8" do
|
50
|
-
|
49
|
+
it "evaluates block pass after arguments" do
|
51
50
|
a = 0
|
52
51
|
p = proc {true}
|
53
52
|
# @obj.foo1(a += 1, &(a += 1; p)).should == [1, true]
|
@@ -57,7 +56,7 @@ describe "A method call" do
|
|
57
56
|
a.should == 14
|
58
57
|
end
|
59
58
|
|
60
|
-
|
59
|
+
it "evaluates block pass after receiver" do
|
61
60
|
p1 = proc {true}
|
62
61
|
p2 = proc {false}
|
63
62
|
p1.should_not == p2
|
@@ -75,5 +74,4 @@ describe "A method call" do
|
|
75
74
|
p = p1
|
76
75
|
end
|
77
76
|
end
|
78
|
-
end
|
79
77
|
end
|
@@ -127,7 +127,7 @@ describe "Operators" do
|
|
127
127
|
(--2).should == 2
|
128
128
|
end
|
129
129
|
|
130
|
-
|
130
|
+
it "unary minus has higher precedence than * / %" do
|
131
131
|
class UnaryMinusTest; def -@; 50; end; end
|
132
132
|
b = UnaryMinusTest.new
|
133
133
|
|
@@ -136,7 +136,7 @@ describe "Operators" do
|
|
136
136
|
(-b % 7).should == 1
|
137
137
|
end
|
138
138
|
|
139
|
-
|
139
|
+
it "* / % are left-associative" do
|
140
140
|
(2*1/2).should == (2*1)/2
|
141
141
|
# Guard against the Mathn library
|
142
142
|
# TODO: Make these specs not rely on specific behaviour / result values
|
@@ -165,7 +165,7 @@ describe "Operators" do
|
|
165
165
|
(10-10%4).should == 8
|
166
166
|
end
|
167
167
|
|
168
|
-
|
168
|
+
it "+ - are left-associative" do
|
169
169
|
(2-3-4).should == -5
|
170
170
|
(4-3+2).should == 3
|
171
171
|
|
@@ -176,7 +176,7 @@ describe "Operators" do
|
|
176
176
|
(s+s+s).should_not == s+(s+s)
|
177
177
|
end
|
178
178
|
|
179
|
-
|
179
|
+
it "+ - have higher precedence than >> <<" do
|
180
180
|
(2<<1+2).should == 16
|
181
181
|
(8>>1+2).should == 1
|
182
182
|
(4<<1-3).should == 1
|
@@ -194,7 +194,7 @@ describe "Operators" do
|
|
194
194
|
(2 & 4 >> 1).should == 2
|
195
195
|
end
|
196
196
|
|
197
|
-
|
197
|
+
it "& is left-associative" do
|
198
198
|
class BitwiseAndTest; def &(a); a+1; end; end
|
199
199
|
c = BitwiseAndTest.new
|
200
200
|
|
@@ -207,7 +207,7 @@ describe "Operators" do
|
|
207
207
|
(8 | 16 & 16).should == 24
|
208
208
|
end
|
209
209
|
|
210
|
-
|
210
|
+
it "^ | are left-associative" do
|
211
211
|
class OrAndXorTest; def ^(a); a+10; end; def |(a); a-10; end; end
|
212
212
|
d = OrAndXorTest.new
|
213
213
|
|
@@ -229,7 +229,7 @@ describe "Operators" do
|
|
229
229
|
(10 >= 7 | 7).should == true
|
230
230
|
end
|
231
231
|
|
232
|
-
|
232
|
+
it "<= < > >= are left-associative" do
|
233
233
|
class ComparisonTest
|
234
234
|
def <=(a); 0; end;
|
235
235
|
def <(a); 0; end;
|
@@ -295,7 +295,7 @@ describe "Operators" do
|
|
295
295
|
lambda { eval("1 !~ 2 !~ 3") }.should raise_error(SyntaxError)
|
296
296
|
end
|
297
297
|
|
298
|
-
|
298
|
+
it "<=> == === != =~ !~ have higher precedence than &&" do
|
299
299
|
(false && 2 <=> 3).should == false
|
300
300
|
(false && 3 == false).should == false
|
301
301
|
(false && 3 === false).should == false
|
@@ -311,14 +311,14 @@ describe "Operators" do
|
|
311
311
|
|
312
312
|
# XXX: figure out how to test it
|
313
313
|
# (a && b) && c equals to a && (b && c) for all a,b,c values I can imagine so far
|
314
|
-
|
314
|
+
it "&& is left-associative"
|
315
315
|
|
316
316
|
it "&& has higher precedence than ||" do
|
317
317
|
(true || false && false).should == true
|
318
318
|
end
|
319
319
|
|
320
320
|
# XXX: figure out how to test it
|
321
|
-
|
321
|
+
it "|| is left-associative"
|
322
322
|
|
323
323
|
it "|| has higher precedence than .. ..." do
|
324
324
|
(1..false||10).should == (1..10)
|
@@ -346,22 +346,22 @@ describe "Operators" do
|
|
346
346
|
|
347
347
|
def oops; raise end
|
348
348
|
|
349
|
-
|
349
|
+
it "? : has higher precedence than rescue" do
|
350
350
|
|
351
351
|
(true ? oops : 0 rescue 10).should == 10
|
352
352
|
end
|
353
353
|
|
354
354
|
# XXX: figure how to test it (problem similar to || associativity)
|
355
|
-
|
355
|
+
it "rescue is left-associative"
|
356
356
|
|
357
|
-
|
357
|
+
it "rescue has higher precedence than =" do
|
358
358
|
# a = oops rescue 10
|
359
359
|
a.should == 10
|
360
360
|
|
361
361
|
# rescue doesn't have the same sense for %= /= and friends
|
362
362
|
end
|
363
363
|
|
364
|
-
|
364
|
+
it "= %= /= -= += |= &= >>= <<= *= &&= ||= **= are right-associative" do
|
365
365
|
# a = b = 10
|
366
366
|
# a.should == 10
|
367
367
|
# b.should == 10
|
@@ -427,7 +427,7 @@ describe "Operators" do
|
|
427
427
|
# b.should == 9
|
428
428
|
end
|
429
429
|
|
430
|
-
|
430
|
+
it "= %= /= -= += |= &= >>= <<= *= &&= ||= **= have higher precedence than defined? operator" do
|
431
431
|
# (defined? a = 10).should == "assignment"
|
432
432
|
# (defined? a %= 10).should == "assignment"
|
433
433
|
# (defined? a /= 10).should == "assignment"
|
@@ -444,7 +444,7 @@ describe "Operators" do
|
|
444
444
|
end
|
445
445
|
|
446
446
|
# XXX: figure out how to test it
|
447
|
-
|
447
|
+
it "defined? is non-associative"
|
448
448
|
|
449
449
|
it "defined? has higher precedence than not" do
|
450
450
|
# does it have sense?
|
@@ -462,9 +462,9 @@ describe "Operators" do
|
|
462
462
|
end
|
463
463
|
|
464
464
|
# XXX: figure out how to test it
|
465
|
-
|
465
|
+
it "or/and are left-associative"
|
466
466
|
|
467
|
-
|
467
|
+
it "or/and have higher precedence than if unless while until modifiers" do
|
468
468
|
(1 if 2 and 3).should == 1
|
469
469
|
(1 if 2 or 3).should == 1
|
470
470
|
|
@@ -479,5 +479,5 @@ describe "Operators" do
|
|
479
479
|
end
|
480
480
|
|
481
481
|
# XXX: it seems to me they are right-associative
|
482
|
-
|
482
|
+
it "if unless while until are non-associative"
|
483
483
|
end
|
@@ -38,7 +38,7 @@ describe "A Proc" do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
ruby_version_is "1.9" do
|
41
|
-
|
41
|
+
it "raises an ArgumentErro if a value is passed" do
|
42
42
|
lambda { @l.call(0) }.should raise_error(ArgumentError)
|
43
43
|
end
|
44
44
|
end
|
@@ -53,7 +53,7 @@ describe "A Proc" do
|
|
53
53
|
@l.call.should == 1
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
it "raises an ArgumentError if a value is passed" do
|
57
57
|
lambda { @l.call(0) }.should raise_error(ArgumentError)
|
58
58
|
end
|
59
59
|
end
|
@@ -63,15 +63,15 @@ describe "A Proc" do
|
|
63
63
|
@l = lambda { |a| a }
|
64
64
|
end
|
65
65
|
|
66
|
-
|
66
|
+
it "assigns the value passed to the argument" do
|
67
67
|
@l.call(2).should == 2
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
it "does not destructure a single Array value" do
|
71
71
|
@l.call([1, 2]).should == [1, 2]
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
it "does not call #to_ary to convert a single passed object to an Array" do
|
75
75
|
obj = mock("block yield to_ary")
|
76
76
|
obj.should_not_receive(:to_ary)
|
77
77
|
|
@@ -89,7 +89,7 @@ describe "A Proc" do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
ruby_version_is "1.9" do
|
92
|
-
|
92
|
+
it "raises an ArgumentError if no value is passed" do
|
93
93
|
lambda { @l.call }.should raise_error(ArgumentError)
|
94
94
|
end
|
95
95
|
end
|
@@ -100,11 +100,11 @@ describe "A Proc" do
|
|
100
100
|
@l = lambda { |a, b| [a, b] }
|
101
101
|
end
|
102
102
|
|
103
|
-
|
103
|
+
it "raises an ArgumentError if passed no values" do
|
104
104
|
lambda { @l.call }.should raise_error(ArgumentError)
|
105
105
|
end
|
106
106
|
|
107
|
-
|
107
|
+
it "raises an ArgumentError if passed one value" do
|
108
108
|
lambda { @l.call(0) }.should raise_error(ArgumentError)
|
109
109
|
end
|
110
110
|
|
@@ -112,7 +112,7 @@ describe "A Proc" do
|
|
112
112
|
@l.call(1, 2).should == [1, 2]
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
it "does not call #to_ary to convert a single passed object to an Array" do
|
116
116
|
obj = mock("proc call to_ary")
|
117
117
|
obj.should_not_receive(:to_ary)
|
118
118
|
|
@@ -125,19 +125,19 @@ describe "A Proc" do
|
|
125
125
|
@l = lambda { |a, *b| [a, b] }
|
126
126
|
end
|
127
127
|
|
128
|
-
|
128
|
+
it "raises an ArgumentError if passed no values" do
|
129
129
|
lambda { @l.call }.should raise_error(ArgumentError)
|
130
130
|
end
|
131
131
|
|
132
|
-
|
132
|
+
it "does not destructure a single Array value yielded" do
|
133
133
|
@l.call([1, 2, 3]).should == [[1, 2, 3], []]
|
134
134
|
end
|
135
135
|
|
136
|
-
|
136
|
+
it "assigns all passed values after the first to the rest argument" do
|
137
137
|
@l.call(1, 2, 3).should == [1, [2, 3]]
|
138
138
|
end
|
139
139
|
|
140
|
-
|
140
|
+
it "does not call #to_ary to convert a single passed object to an Array" do
|
141
141
|
obj = mock("block yield to_ary")
|
142
142
|
obj.should_not_receive(:to_ary)
|
143
143
|
|
@@ -150,15 +150,15 @@ describe "A Proc" do
|
|
150
150
|
# @l = lambda { |*| 1 }
|
151
151
|
end
|
152
152
|
|
153
|
-
|
153
|
+
it "does not raise an exception when passed no values" do
|
154
154
|
@l.call.should == 1
|
155
155
|
end
|
156
156
|
|
157
|
-
|
157
|
+
it "does not raise an exception when passed multiple values" do
|
158
158
|
@l.call(2, 3, 4).should == 1
|
159
159
|
end
|
160
160
|
|
161
|
-
|
161
|
+
it "does not call #to_ary to convert a single passed object to an Array" do
|
162
162
|
obj = mock("block yield to_ary")
|
163
163
|
obj.should_not_receive(:to_ary)
|
164
164
|
|
@@ -171,19 +171,19 @@ describe "A Proc" do
|
|
171
171
|
@l = lambda { |*a| a }
|
172
172
|
end
|
173
173
|
|
174
|
-
|
174
|
+
it "assigns [] to the argument when passed no values" do
|
175
175
|
@l.call.should == []
|
176
176
|
end
|
177
177
|
|
178
|
-
|
178
|
+
it "assigns the argument an Array wrapping one passed value" do
|
179
179
|
@l.call(1).should == [1]
|
180
180
|
end
|
181
181
|
|
182
|
-
|
182
|
+
it "assigns the argument an Array wrapping all values passed" do
|
183
183
|
@l.call(1, 2, 3).should == [1, 2, 3]
|
184
184
|
end
|
185
185
|
|
186
|
-
|
186
|
+
it "does not call #to_ary to convert a single passed object to an Array" do
|
187
187
|
obj = mock("block yield to_ary")
|
188
188
|
obj.should_not_receive(:to_ary)
|
189
189
|
|
@@ -196,23 +196,23 @@ describe "A Proc" do
|
|
196
196
|
# @l = lambda { |a, | a }
|
197
197
|
end
|
198
198
|
|
199
|
-
|
199
|
+
it "raises an ArgumentError when passed no values" do
|
200
200
|
lambda { @l.call }.should raise_error(ArgumentError)
|
201
201
|
end
|
202
202
|
|
203
|
-
|
203
|
+
it "raises an ArgumentError when passed more than one value" do
|
204
204
|
lambda { @l.call(1, 2) }.should raise_error(ArgumentError)
|
205
205
|
end
|
206
206
|
|
207
|
-
|
207
|
+
it "assigns the argument the value passed" do
|
208
208
|
@l.call(1).should == 1
|
209
209
|
end
|
210
210
|
|
211
|
-
|
211
|
+
it "does not destructure when passed a single Array" do
|
212
212
|
@l.call([1,2]).should == [1, 2]
|
213
213
|
end
|
214
214
|
|
215
|
-
|
215
|
+
it "does not call #to_ary to convert a single passed object to an Array" do
|
216
216
|
obj = mock("block yield to_ary")
|
217
217
|
obj.should_not_receive(:to_ary)
|
218
218
|
|
@@ -225,7 +225,7 @@ describe "A Proc" do
|
|
225
225
|
# @l = lambda { |(a, b)| [a, b] }
|
226
226
|
end
|
227
227
|
|
228
|
-
|
228
|
+
it "raises an ArgumentError when passed no values" do
|
229
229
|
lambda { @l.call }.should raise_error(ArgumentError)
|
230
230
|
end
|
231
231
|
|
@@ -243,18 +243,18 @@ describe "A Proc" do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
ruby_version_is "1.9" do
|
246
|
-
|
246
|
+
it "destructures a single Array value yielded" do
|
247
247
|
@l.call([1, 2]).should == [1, 2]
|
248
248
|
end
|
249
249
|
|
250
|
-
|
250
|
+
it "calls #to_ary to convert a single passed object to an Array" do
|
251
251
|
obj = mock("block yield to_ary")
|
252
252
|
obj.should_receive(:to_ary).and_return([1, 2])
|
253
253
|
|
254
254
|
@l.call(obj).should == [1, 2]
|
255
255
|
end
|
256
256
|
|
257
|
-
|
257
|
+
it "raises an TypeError if #to_ary does not return an Array" do
|
258
258
|
obj = mock("block yield to_ary invalid")
|
259
259
|
obj.should_receive(:to_ary).and_return(1)
|
260
260
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
3
|
describe "The redo statement" do
|
4
|
-
|
4
|
+
it "restarts block execution if used within block" do
|
5
5
|
a = []
|
6
6
|
lambda {
|
7
7
|
a << 1
|
@@ -11,7 +11,7 @@ describe "The redo statement" do
|
|
11
11
|
a.should == [1, 1, 2]
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
it "re-executes the closest loop" do
|
15
15
|
exist = [2,3]
|
16
16
|
processed = []
|
17
17
|
order = []
|
@@ -32,7 +32,7 @@ describe "The redo statement" do
|
|
32
32
|
order.should == [1,2,2,3,3,4]
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
it "re-executes the last step in enumeration" do
|
36
36
|
list = []
|
37
37
|
[1,2,3].each do |x|
|
38
38
|
list << x
|
@@ -44,7 +44,6 @@ describe "The redo statement" do
|
|
44
44
|
|
45
45
|
# The #count method is on 1.9, but this causes SyntaxError,
|
46
46
|
# Invalid redo in 1.9
|
47
|
-
pending do
|
48
47
|
quarantine! do
|
49
48
|
it "triggers ensure block when re-executing a block" do
|
50
49
|
list = []
|
@@ -61,7 +60,6 @@ describe "The redo statement" do
|
|
61
60
|
list.should == [1,10,100,1,10,100,2,20,200,3,30,300]
|
62
61
|
end
|
63
62
|
end
|
64
|
-
end
|
65
63
|
end
|
66
64
|
|
67
65
|
# language_version __FILE__, "redo"
|
@@ -29,7 +29,7 @@ describe "The rescue keyword" do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "can rescue multiple raised exceptions with a single rescue block" do
|
33
33
|
lambda do
|
34
34
|
[lambda{1/0}, lambda{raise SpecificExampleException}].each do |block|
|
35
35
|
begin
|
@@ -40,7 +40,7 @@ describe "The rescue keyword" do
|
|
40
40
|
end.should_not raise_error
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
it "can rescue a splatted list of exceptions" do
|
44
44
|
caught_it = false
|
45
45
|
begin
|
46
46
|
raise SpecificExampleException, "not important"
|
@@ -64,7 +64,7 @@ describe "The rescue keyword" do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
it "will only rescue the specified exceptions when doing a splat rescue" do
|
68
68
|
lambda do
|
69
69
|
begin
|
70
70
|
raise OtherCustomException, "not rescued!"
|
@@ -73,7 +73,7 @@ describe "The rescue keyword" do
|
|
73
73
|
end.should raise_error(OtherCustomException)
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
it "will execute an else block only if no exceptions were raised" do
|
77
77
|
# begin
|
78
78
|
# ScratchPad << :one
|
79
79
|
# rescue
|
@@ -84,7 +84,7 @@ describe "The rescue keyword" do
|
|
84
84
|
# ScratchPad.recorded.should == [:one, :two]
|
85
85
|
end
|
86
86
|
|
87
|
-
|
87
|
+
it "will not execute an else block if an exception was raised" do
|
88
88
|
# begin
|
89
89
|
# ScratchPad << :one
|
90
90
|
# raise "an error occurred"
|
@@ -96,7 +96,7 @@ describe "The rescue keyword" do
|
|
96
96
|
# ScratchPad.recorded.should == [:one, :two]
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
it "will not rescue errors raised in an else block in the rescue block above it" do
|
100
100
|
# lambda do
|
101
101
|
# begin
|
102
102
|
# ScratchPad << :one
|
@@ -111,7 +111,7 @@ describe "The rescue keyword" do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
ruby_version_is "1.9" do
|
114
|
-
|
114
|
+
it "parses 'a += b rescue c' as 'a += (b rescue c)'" do
|
115
115
|
a = 'a'
|
116
116
|
c = 'c'
|
117
117
|
# a += b rescue c
|