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
@@ -14,7 +14,7 @@ describe "Array literals" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "The unpacking splat operator (*)" do
|
17
|
-
|
17
|
+
it "when applied to a non-Array value attempts to coerce it to Array if the object respond_to?(:to_a)" do
|
18
18
|
obj = mock("pseudo-array")
|
19
19
|
obj.should_receive(:to_a).and_return([2, 3, 4])
|
20
20
|
[1, *obj].should == [1, 2, 3, 4]
|
File without changes
|
File without changes
|
@@ -34,7 +34,7 @@ describe "->(){}" do
|
|
34
34
|
"1+2=#{->{ 1 + 2}.call}".should == "1+2=3"
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
it "can be be used as a Hash key" do
|
38
38
|
h = new_hash
|
39
39
|
# h[->(one=1){ one + 2}.call] = :value
|
40
40
|
h.key?(3).should be_true
|
@@ -71,51 +71,51 @@ describe "->(){}" do
|
|
71
71
|
->(a,b) {[a, b]}.call(:sym, :bol).should == [:sym, :bol]
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
it "accepts parameters with default parameters between the parenthesis" do
|
75
75
|
# lambda { ->(a=1) {} }.should_not raise_error(SyntaxError)
|
76
76
|
# lambda { ->(x=1, b=[]) {} }.should_not raise_error(SyntaxError)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
it "aliases each argument with a default value to the corresponding parameter" do
|
80
80
|
# ->(a=:cymbal) {a}.call(:sym).should == :sym
|
81
81
|
# ->(a,b=:cymbal) {[a, b]}.call(:sym, :bol).should == [:sym, :bol]
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
it "sets arguments to their default value if one wasn't supplied" do
|
85
85
|
# ->(a=:cymbal) {a}.call.should == :cymbal
|
86
86
|
# ->(a,b=:cymbal) {[a, b]}.call(:sym).should == [:sym, :cymbal]
|
87
87
|
end
|
88
88
|
|
89
|
-
|
89
|
+
it "accepts a parameter prefixed with an asterisk between the parenthesis" do
|
90
90
|
# lambda { ->(*a) {} }.should_not raise_error(SyntaxError)
|
91
91
|
# lambda { ->(x, *a) {} }.should_not raise_error(SyntaxError)
|
92
92
|
end
|
93
93
|
|
94
|
-
|
94
|
+
it "assigns all remaining arguments to the variable in the parameter list prefixed with an asterisk, if one exists" do
|
95
95
|
# ->(*a) {a}.call(:per, :cus, :si, :on).should == [:per, :cus, :si, :on]
|
96
96
|
# ->(a,*b) {b}.call(:per, :cus, :si, :on).should == [:cus, :si, :on]
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
it "accepts a parameter prefixed with an ampersand between the parenthesis" do
|
100
100
|
# lambda { ->(&a) {} }.should_not raise_error(SyntaxError)
|
101
101
|
# lambda { ->(x, &a) {} }.should_not raise_error(SyntaxError)
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
it "assigns the given block to the parameter prefixed with an ampersand if such a parameter exists" do
|
105
105
|
# l = ->(&a) { a }.call { :foo }
|
106
106
|
l.call.should == :foo
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
it "assigns nil to the parameter prefixed with an ampersand unless a block was supplied" do
|
110
110
|
# ->(&a) { a }.call.should be_nil
|
111
111
|
end
|
112
112
|
|
113
|
-
|
113
|
+
it "accepts a combination of argument types between the parenthesis" do
|
114
114
|
# lambda { ->(x, y={}, z = Object.new, *a, &b) {} }.
|
115
115
|
should_not raise_error(SyntaxError)
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
it "sets parameters appropriately when a combination of parameter types is given between the parenthesis" do
|
119
119
|
# l = ->(x, y={}, z = Object.new, *a, &b) { [x,y,z,a,b]}
|
120
120
|
l.call(1, [], [], 30, 40).should == [1, [], [], [30, 40], nil]
|
121
121
|
block = lambda { :lamb }
|
@@ -124,7 +124,7 @@ describe "->(){}" do
|
|
124
124
|
l2.call(:x).should == [:x, {}, []]
|
125
125
|
end
|
126
126
|
|
127
|
-
|
127
|
+
it "uses lambda's 'rigid' argument handling" do
|
128
128
|
->(a, b){}.parameters.first.first.should == :req
|
129
129
|
->(a, b){}.parameters.last.first.should == :req
|
130
130
|
lambda { ->(a, b){}.call 1 }.should raise_error(ArgumentError)
|
@@ -7,7 +7,7 @@ specs = LangSendSpecs
|
|
7
7
|
|
8
8
|
describe "Invoking a method" do
|
9
9
|
describe "with required args after the rest arguments" do
|
10
|
-
|
10
|
+
it "binds the required arguments first" do
|
11
11
|
specs.fooM0RQ1(1).should == [[], 1]
|
12
12
|
specs.fooM0RQ1(1,2).should == [[1], 2]
|
13
13
|
specs.fooM0RQ1(1,2,3).should == [[1,2], 3]
|
@@ -27,7 +27,7 @@ describe "Invoking a method" do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "with manditory arguments after optional arguments" do
|
30
|
-
|
30
|
+
it "binds the required arguments first" do
|
31
31
|
specs.fooO1Q1(0,1).should == [0,1]
|
32
32
|
specs.fooO1Q1(2).should == [1,2]
|
33
33
|
|
@@ -54,7 +54,7 @@ describe "Invoking a method" do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
it "with .() invokes #call" do
|
58
58
|
q = proc { |z| z }
|
59
59
|
q.(1).should == 1
|
60
60
|
|
@@ -63,11 +63,11 @@ describe "Invoking a method" do
|
|
63
63
|
obj.().should == :called
|
64
64
|
end
|
65
65
|
|
66
|
-
|
66
|
+
it "allows a vestigial trailing ',' in the arguments" do
|
67
67
|
# specs.fooM1(1,).should == [1]
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
it "with splat operator attempts to coerce it to an Array if the object respond_to?(:to_a)" do
|
71
71
|
ary = [2,3,4]
|
72
72
|
obj = mock("to_a")
|
73
73
|
obj.should_receive(:to_a).and_return(ary).twice
|
@@ -75,7 +75,7 @@ describe "Invoking a method" do
|
|
75
75
|
specs.fooM1R(1,*obj).should == [1, ary]
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
it "with splat operator * and non-Array value uses value unchanged if it does not respond_to?(:to_ary)" do
|
79
79
|
obj = Object.new
|
80
80
|
obj.should_not respond_to(:to_a)
|
81
81
|
|
@@ -89,44 +89,44 @@ describe "Invoking a method" do
|
|
89
89
|
specs.fooM4(0,*a,3).should == [0,1,2,3]
|
90
90
|
end
|
91
91
|
|
92
|
-
|
92
|
+
it "accepts final explicit literal Hash arguments after the splat" do
|
93
93
|
a = [1, 2]
|
94
94
|
specs.fooM0RQ1(*a, { :a => 1 }).should == [[1, 2], { :a => 1 }]
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
it "accepts final implicit literal Hash arguments after the splat" do
|
98
98
|
a = [1, 2]
|
99
99
|
specs.fooM0RQ1(*a, :a => 1).should == [[1, 2], { :a => 1 }]
|
100
100
|
end
|
101
101
|
|
102
|
-
|
102
|
+
it "accepts final Hash arguments after the splat" do
|
103
103
|
a = [1, 2]
|
104
104
|
b = { :a => 1 }
|
105
105
|
specs.fooM0RQ1(*a, b).should == [[1, 2], { :a => 1 }]
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
it "accepts mandatory and explicit literal Hash arguments after the splat" do
|
109
109
|
a = [1, 2]
|
110
110
|
specs.fooM0RQ2(*a, 3, { :a => 1 }).should == [[1, 2], 3, { :a => 1 }]
|
111
111
|
end
|
112
112
|
|
113
|
-
|
113
|
+
it "accepts mandatory and implicit literal Hash arguments after the splat" do
|
114
114
|
a = [1, 2]
|
115
115
|
specs.fooM0RQ2(*a, 3, :a => 1).should == [[1, 2], 3, { :a => 1 }]
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
it "accepts mandatory and Hash arguments after the splat" do
|
119
119
|
a = [1, 2]
|
120
120
|
b = { :a => 1 }
|
121
121
|
specs.fooM0RQ2(*a, 3, b).should == [[1, 2], 3, { :a => 1 }]
|
122
122
|
end
|
123
123
|
|
124
|
-
|
124
|
+
it "converts a final splatted explicit Hash to an Array" do
|
125
125
|
a = [1, 2]
|
126
126
|
specs.fooR(*a, 3, *{ :a => 1 }).should == [1, 2, 3, [:a, 1]]
|
127
127
|
end
|
128
128
|
|
129
|
-
|
129
|
+
it "calls #to_a to convert a final splatted Hash object to an Array" do
|
130
130
|
a = [1, 2]
|
131
131
|
b = { :a => 1 }
|
132
132
|
b.should_receive(:to_a).and_return([:a, 1])
|
@@ -134,7 +134,7 @@ describe "Invoking a method" do
|
|
134
134
|
specs.fooR(*a, 3, *b).should == [1, 2, 3, :a, 1]
|
135
135
|
end
|
136
136
|
|
137
|
-
|
137
|
+
it "accepts multiple splat expansions in the same argument list" do
|
138
138
|
a = [1,2,3]
|
139
139
|
b = 7
|
140
140
|
c = mock("pseudo-array")
|
@@ -146,19 +146,19 @@ describe "Invoking a method" do
|
|
146
146
|
specs.rest_len(0,*a,4,*5,6,7,*c,-1).should == 11
|
147
147
|
end
|
148
148
|
|
149
|
-
|
149
|
+
it "expands an array to arguments grouped in parentheses" do
|
150
150
|
specs.destructure2([40,2]).should == 42
|
151
151
|
end
|
152
152
|
|
153
|
-
|
153
|
+
it "expands an array to arguments grouped in parentheses and ignores any rest arguments in the array" do
|
154
154
|
specs.destructure2([40,2,84]).should == 42
|
155
155
|
end
|
156
156
|
|
157
|
-
|
157
|
+
it "expands an array to arguments grouped in parentheses and sets not specified arguments to nil" do
|
158
158
|
specs.destructure2b([42]).should == [42, nil]
|
159
159
|
end
|
160
160
|
|
161
|
-
|
161
|
+
it "expands an array to arguments grouped in parentheses which in turn takes rest arguments" do
|
162
162
|
specs.destructure4r([1, 2, 3]).should == [1, 2, [], 3, nil]
|
163
163
|
specs.destructure4r([1, 2, 3, 4]).should == [1, 2, [], 3, 4]
|
164
164
|
specs.destructure4r([1, 2, 3, 4, 5]).should == [1, 2, [3], 4, 5]
|
@@ -176,7 +176,7 @@ describe "Invoking a method" do
|
|
176
176
|
[{ :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
177
177
|
end
|
178
178
|
|
179
|
-
|
179
|
+
it "handles a hanging comma without curly braces" do
|
180
180
|
# specs.fooM1(abc: 123,).should == [{:abc => 123}]
|
181
181
|
# specs.fooM1(rbx: 'cool', specs: :fail_sometimes, non_sym: 1234,).should ==
|
182
182
|
# [{ :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
@@ -194,7 +194,7 @@ describe "Invoking a method" do
|
|
194
194
|
['abc', 123, { :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
195
195
|
end
|
196
196
|
|
197
|
-
|
197
|
+
it "handles a hanging comma without curly braces" do
|
198
198
|
# specs.fooM3('abc', 123, abc: 123,).should == ['abc', 123, {:abc => 123}]
|
199
199
|
# specs.fooM3('abc', 123, rbx: 'cool', specs: :fail_sometimes, non_sym: 1234,).should ==
|
200
200
|
# ['abc', 123, { :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
@@ -214,7 +214,7 @@ describe "Invoking a method" do
|
|
214
214
|
[{ :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
215
215
|
end
|
216
216
|
|
217
|
-
|
217
|
+
it "handles a hanging comma without curly braces" do
|
218
218
|
# specs.fooM1(rbx: 'cool', specs: :fail_sometimes, :non_sym => 1234,).should ==
|
219
219
|
# [{ :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
220
220
|
end
|
@@ -231,7 +231,7 @@ describe "Invoking a method" do
|
|
231
231
|
['abc', 123, { :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
232
232
|
end
|
233
233
|
|
234
|
-
|
234
|
+
it "handles a hanging comma without curly braces" do
|
235
235
|
# specs.fooM3('abc', 123, rbx: 'cool', specs: :fail_sometimes, :non_sym => 1234,).should ==
|
236
236
|
# ['abc', 123, { :rbx => 'cool', :specs => :fail_sometimes, :non_sym => 1234 }]
|
237
237
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
describe "A Symbol literal" do
|
2
|
-
|
2
|
+
it "can be an empty string" do
|
3
3
|
c = :''
|
4
4
|
c.should be_kind_of(Symbol)
|
5
5
|
c.inspect.should == ':""'
|
6
6
|
end
|
7
7
|
|
8
8
|
# These weren't allowed on 1.8
|
9
|
-
|
9
|
+
it "can be :!, :!=, or :!~" do
|
10
10
|
%w{'!', '!=', '!~'}.each do |sym|
|
11
11
|
lambda { sym.to_sym }.should_not raise_error(SyntaxError)
|
12
12
|
sym.to_sym.to_s.should == sym
|
@@ -196,7 +196,7 @@ describe "The while modifier with begin .. end block" do
|
|
196
196
|
(begin; break; end while true).should == nil
|
197
197
|
end
|
198
198
|
|
199
|
-
|
199
|
+
it "runs block at least once (even if the expression is false)" do
|
200
200
|
i = 0
|
201
201
|
begin
|
202
202
|
i += 1
|
@@ -205,7 +205,7 @@ describe "The while modifier with begin .. end block" do
|
|
205
205
|
i.should == 1
|
206
206
|
end
|
207
207
|
|
208
|
-
|
208
|
+
it "evaluates condition after block execution" do
|
209
209
|
a = []
|
210
210
|
i = 0
|
211
211
|
begin
|
@@ -214,7 +214,7 @@ describe "The while modifier with begin .. end block" do
|
|
214
214
|
a.should == [0, 1, 2, 3, 4]
|
215
215
|
end
|
216
216
|
|
217
|
-
|
217
|
+
it "skips to end of body with next" do
|
218
218
|
a = []
|
219
219
|
i = 0
|
220
220
|
begin
|
@@ -224,7 +224,7 @@ describe "The while modifier with begin .. end block" do
|
|
224
224
|
a.should == [0, 1, 2, 4]
|
225
225
|
end
|
226
226
|
|
227
|
-
|
227
|
+
it "restarts the current iteration without reevaluting condition with redo" do
|
228
228
|
a = []
|
229
229
|
i = 0
|
230
230
|
j = 0
|
@@ -16,7 +16,7 @@ describe "The yield call" do
|
|
16
16
|
lambda { @y.z }.should raise_error(LocalJumpError)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
it "ignores assignment to the explicit block argument and calls the passed block" do
|
20
20
|
@y.ze { 42 }.should == 42
|
21
21
|
end
|
22
22
|
end
|
@@ -87,7 +87,7 @@ describe "The yield call" do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
ruby_version_is "1.9" do
|
90
|
-
|
90
|
+
it "passes no values when give nil as an argument" do
|
91
91
|
@y.r(nil) { |*a| a }.should == []
|
92
92
|
end
|
93
93
|
end
|
@@ -120,7 +120,7 @@ describe "The yield call" do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
ruby_version_is "1.9" do
|
123
|
-
|
123
|
+
it "does not pass an argument value if the splatted argument is nil" do
|
124
124
|
@y.rs(1, 2, nil) { |*a| a }.should == [1, 2]
|
125
125
|
end
|
126
126
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
3
|
+
|
4
|
+
describe "ERB::Util.html_escape" do
|
5
|
+
it "escape (& < > \" ') to (& < > " ')" do
|
6
|
+
input = '& < > " \''
|
7
|
+
expected = '& < > " ''
|
8
|
+
ERB::Util.html_escape(input).should == expected
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Singleton#clone" do
|
5
|
+
it "is prevented" do
|
6
|
+
lambda { SingletonSpecs::MyClass.instance.clone }.should raise_error(TypeError)
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module SingletonSpecs
|
4
|
+
class MyClass
|
5
|
+
attr_accessor :data
|
6
|
+
include Singleton
|
7
|
+
end
|
8
|
+
|
9
|
+
class NewSpec
|
10
|
+
include Singleton
|
11
|
+
end
|
12
|
+
|
13
|
+
class MyClassChild < MyClass
|
14
|
+
end
|
15
|
+
|
16
|
+
class NotInstantiated < MyClass
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Singleton.instance" do
|
5
|
+
it "returns an instance of the singleton class" do
|
6
|
+
SingletonSpecs::MyClass.instance.should be_kind_of(SingletonSpecs::MyClass)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the same instance for multiple calls to instance" do
|
10
|
+
SingletonSpecs::MyClass.instance.should equal(SingletonSpecs::MyClass.instance)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns an instance of the singleton's subclasses" do
|
14
|
+
SingletonSpecs::MyClassChild.instance.should be_kind_of(SingletonSpecs::MyClassChild)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns the same instance for multiple class to instance on subclasses" do
|
18
|
+
SingletonSpecs::MyClassChild.instance.should equal(SingletonSpecs::MyClassChild.instance)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns an instance of the singleton's clone" do
|
22
|
+
klone = SingletonSpecs::MyClassChild.clone
|
23
|
+
klone.instance.should be_kind_of(klone)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the same instance for multiple class to instance on clones" do
|
27
|
+
klone = SingletonSpecs::MyClassChild.clone
|
28
|
+
klone.instance.should equal(klone.instance)
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'opal'
|
2
|
+
require 'opal-parser'
|
3
|
+
require 'mspec'
|
4
|
+
|
5
|
+
ENV['MSPEC_RUNNER'] = true
|
6
|
+
|
7
|
+
class OSpecFilter
|
8
|
+
def self.main
|
9
|
+
@main ||= self.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@filters = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def register
|
17
|
+
MSpec.register :exclude, self
|
18
|
+
end
|
19
|
+
|
20
|
+
def ===(description)
|
21
|
+
@filters.has_key? description
|
22
|
+
end
|
23
|
+
|
24
|
+
def register_filters(description, block)
|
25
|
+
instance_eval(&block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fails(description)
|
29
|
+
@filters[description] = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Object
|
34
|
+
def opal_filter(description, &block)
|
35
|
+
OSpecFilter.main.register_filters(description, block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class PhantomFormatter
|
40
|
+
def initialize(out=nil)
|
41
|
+
@exception = @failure = false
|
42
|
+
@exceptions = []
|
43
|
+
@count = 0
|
44
|
+
@examples = 0
|
45
|
+
|
46
|
+
@current_state = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def register
|
50
|
+
MSpec.register :exception, self
|
51
|
+
MSpec.register :before, self
|
52
|
+
MSpec.register :after, self
|
53
|
+
MSpec.register :start, self
|
54
|
+
MSpec.register :finish, self
|
55
|
+
MSpec.register :abort, self
|
56
|
+
MSpec.register :enter, self
|
57
|
+
end
|
58
|
+
|
59
|
+
def green(str)
|
60
|
+
`console.log('\\033[32m' + str + '\\033[0m')`
|
61
|
+
end
|
62
|
+
|
63
|
+
def red(str)
|
64
|
+
`console.log('\\033[31m' + str + '\\033[0m')`
|
65
|
+
end
|
66
|
+
|
67
|
+
def log(str)
|
68
|
+
`console.log(str)`
|
69
|
+
end
|
70
|
+
|
71
|
+
def exception?
|
72
|
+
@exception
|
73
|
+
end
|
74
|
+
|
75
|
+
def failure?
|
76
|
+
@failure
|
77
|
+
end
|
78
|
+
|
79
|
+
def enter(describe); end
|
80
|
+
|
81
|
+
def before(state=nil)
|
82
|
+
@current_state = nil
|
83
|
+
@failure = @exception = false
|
84
|
+
end
|
85
|
+
|
86
|
+
def exception(exception)
|
87
|
+
@count += 1
|
88
|
+
@failure = @exception ? @failure && exception.failure? : exception.failure?
|
89
|
+
@exception = true
|
90
|
+
@exceptions << exception
|
91
|
+
end
|
92
|
+
|
93
|
+
def after(state = nil)
|
94
|
+
@current_state = nil
|
95
|
+
@examples += 1
|
96
|
+
end
|
97
|
+
|
98
|
+
def start
|
99
|
+
@start_time = Time.now.to_f
|
100
|
+
end
|
101
|
+
|
102
|
+
def finish
|
103
|
+
time = Time.now.to_f - @start_time
|
104
|
+
|
105
|
+
if @exceptions.empty?
|
106
|
+
log "\nFinished"
|
107
|
+
green "#{@examples} examples, #{@count} failures (time taken: #{time})"
|
108
|
+
|
109
|
+
finish_with_code 0
|
110
|
+
else
|
111
|
+
log "\nFailures:"
|
112
|
+
|
113
|
+
@exceptions.each_with_index do |exception, idx|
|
114
|
+
log "\n #{idx + 1}. #{exception.description}"
|
115
|
+
red "\n #{exception.message}"
|
116
|
+
end
|
117
|
+
|
118
|
+
log "\nFinished"
|
119
|
+
red "#{@examples} examples, #{@count} failures (time taken: #{time})"
|
120
|
+
|
121
|
+
finish_with_code(1)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def finish_with_code(code)
|
126
|
+
%x{
|
127
|
+
if (typeof(phantom) !== 'undefined') {
|
128
|
+
return phantom.exit(code);
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
window.OPAL_SPEC_CODE = code;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class File
|
138
|
+
def self.expand_path(*a); nil; end
|
139
|
+
end
|
140
|
+
|
141
|
+
class ExceptionState
|
142
|
+
def initialize(state, location, exception)
|
143
|
+
@exception = exception
|
144
|
+
|
145
|
+
@description = location ? ["An exception occurred during: #{location}"] : []
|
146
|
+
if state
|
147
|
+
@description << "\n" unless @description.empty?
|
148
|
+
@description << state.description
|
149
|
+
@describe = state.describe
|
150
|
+
@it = state.it
|
151
|
+
@description = @description.join ""
|
152
|
+
else
|
153
|
+
@describe = @it = ""
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
module Kernel
|
159
|
+
def opal_parse(str, file='(string)')
|
160
|
+
Opal::Grammar.new.parse str, file
|
161
|
+
end
|
162
|
+
|
163
|
+
def opal_eval_compiled(javascript)
|
164
|
+
`eval(javascript)`
|
165
|
+
end
|
166
|
+
|
167
|
+
def eval(str)
|
168
|
+
code = Opal::Parser.new.parse str
|
169
|
+
`eval(#{code})`
|
170
|
+
end
|
171
|
+
|
172
|
+
alias_method :opal_eval, :eval
|
173
|
+
end
|
174
|
+
|
175
|
+
module MSpec
|
176
|
+
def self.opal_runner
|
177
|
+
@env = Object.new
|
178
|
+
@env.extend MSpec
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class OSpecRunner
|
183
|
+
def self.main
|
184
|
+
@main ||= self.new
|
185
|
+
end
|
186
|
+
|
187
|
+
def initialize
|
188
|
+
register
|
189
|
+
run
|
190
|
+
end
|
191
|
+
|
192
|
+
def register
|
193
|
+
formatter = PhantomFormatter.new
|
194
|
+
formatter.register
|
195
|
+
|
196
|
+
OSpecFilter.main.register
|
197
|
+
end
|
198
|
+
|
199
|
+
def run
|
200
|
+
MSpec.opal_runner
|
201
|
+
end
|
202
|
+
|
203
|
+
def will_start
|
204
|
+
MSpec.actions :start
|
205
|
+
end
|
206
|
+
|
207
|
+
def did_finish
|
208
|
+
MSpec.actions :finish
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# As soon as this file loads, tell the runner the specs are starting
|
213
|
+
OSpecRunner.main.will_start
|
214
|
+
|