opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/parser/regexp_spec.rb
CHANGED
@@ -2,15 +2,15 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Regexps" do
|
4
4
|
it "parses a regexp as a s(:lit)" do
|
5
|
-
opal_parse("/lol/").should == [:
|
5
|
+
opal_parse("/lol/").should == [:regexp, /lol/]
|
6
6
|
end
|
7
7
|
|
8
8
|
it "parses regexp options" do
|
9
|
-
opal_parse("/lol/i").should == [:
|
9
|
+
opal_parse("/lol/i").should == [:regexp, /lol/i]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "can parse regexps using %r notation" do
|
13
|
-
opal_parse('%r(foo)').should == [:
|
14
|
-
opal_parse('%r(foo)i').should == [:
|
13
|
+
opal_parse('%r(foo)').should == [:regexp, /foo/]
|
14
|
+
opal_parse('%r(foo)i').should == [:regexp, /foo/i]
|
15
15
|
end
|
16
16
|
end
|
data/spec/parser/return_spec.rb
CHANGED
@@ -6,12 +6,12 @@ describe "The return keyword" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "returns s(:return) with the direct argument when given one argument" do
|
9
|
-
opal_parse("return 1").should == [:return, [:
|
10
|
-
opal_parse("return *2").should == [:return, [:splat, [:
|
9
|
+
opal_parse("return 1").should == [:return, [:int, 1]]
|
10
|
+
opal_parse("return *2").should == [:return, [:splat, [:int, 2]]]
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns s(:return) with an s(:array) when args size > 1" do
|
14
|
-
opal_parse("return 1, 2").should == [:return, [:array, [:
|
15
|
-
opal_parse("return 1, *2").should == [:return, [:array, [:
|
14
|
+
opal_parse("return 1, 2").should == [:return, [:array, [:int, 1], [:int, 2]]]
|
15
|
+
opal_parse("return 1, *2").should == [:return, [:array, [:int, 1], [:splat, [:int, 2]]]]
|
16
16
|
end
|
17
17
|
end
|
data/spec/parser/sclass_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Singleton classes" do
|
4
|
-
|
4
|
+
it "returns an empty s(:scope) when given an empty body" do
|
5
5
|
opal_parse('class << A; end')[2].should == [:scope]
|
6
6
|
end
|
7
7
|
|
8
8
|
it "does not place single expressions into an s(:block)" do
|
9
|
-
opal_parse('class << A; 1; end')[2].should == [:scope, [:
|
9
|
+
opal_parse('class << A; 1; end')[2].should == [:scope, [:int, 1]]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "adds multiple body expressions into a s(:block)" do
|
13
|
-
opal_parse('class << A; 1; 2; end')[2].should == [:scope, [:block, [:
|
13
|
+
opal_parse('class << A; 1; 2; end')[2].should == [:scope, [:block, [:int, 1], [:int, 2]]]
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it "should accept any expressions for singleton part" do
|
17
17
|
opal_parse('class << A; end').should == [:sclass, [:const, :A], [:scope]]
|
18
18
|
opal_parse('class << self; end').should == [:sclass, [:self], [:scope]]
|
19
19
|
end
|
data/spec/parser/str_spec.rb
CHANGED
@@ -55,7 +55,7 @@ describe "Strings" do
|
|
55
55
|
opal_parse('%Q{#@@foo}').should == [:dstr, "", [:evstr, [:cvar, :@@foo]]]
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
it "should match '{' and '}' pairs used to start string before ending match" do
|
59
59
|
opal_parse('%Q{{}}').should == [:str, "{}"]
|
60
60
|
opal_parse('%Q{foo{bar}baz}').should == [:str, "foo{bar}baz"]
|
61
61
|
opal_parse('%Q{{foo}bar}').should == [:str, "{foo}bar"]
|
@@ -65,7 +65,7 @@ describe "Strings" do
|
|
65
65
|
opal_parse('%Q{a{b{c}#{foo}d}e}').should == [:dstr, "a{b{c}", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d}e"]]
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
it "should match '(' and ')' pairs used to start string before ending match" do
|
69
69
|
opal_parse('%Q(())').should == [:str, "()"]
|
70
70
|
opal_parse('%Q(foo(bar)baz)').should == [:str, "foo(bar)baz"]
|
71
71
|
opal_parse('%Q((foo)bar)').should == [:str, "(foo)bar"]
|
@@ -75,7 +75,7 @@ describe "Strings" do
|
|
75
75
|
opal_parse('%Q(a(b(c)#{foo}d)e)').should == [:dstr, "a(b(c)", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d)e"]]
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
it "should match '[' and ']' pairs used to start string before ending match" do
|
79
79
|
opal_parse('%Q[[]]').should == [:str, "[]"]
|
80
80
|
opal_parse('%Q[foo[bar]baz]').should == [:str, "foo[bar]baz"]
|
81
81
|
opal_parse('%Q[[foo]bar]').should == [:str, "[foo]bar"]
|
data/spec/parser/super_spec.rb
CHANGED
@@ -6,15 +6,15 @@ describe "The super keyword" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return s(:super) for any arguments" do
|
9
|
-
opal_parse("super 1").should == [:super, [:
|
10
|
-
opal_parse("super 1, 2").should == [:super, [:
|
11
|
-
opal_parse("super 1, *2").should == [:super, [:
|
9
|
+
opal_parse("super 1").should == [:super, [:int, 1]]
|
10
|
+
opal_parse("super 1, 2").should == [:super, [:int, 1], [:int, 2]]
|
11
|
+
opal_parse("super 1, *2").should == [:super, [:int, 1], [:splat, [:int, 2]]]
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should always return s(:super) when parans are used" do
|
15
15
|
opal_parse("super()").should == [:super]
|
16
|
-
opal_parse("super(1)").should == [:super, [:
|
17
|
-
opal_parse("super(1, 2)").should == [:super, [:
|
18
|
-
opal_parse("super(1, *2)").should == [:super, [:
|
16
|
+
opal_parse("super(1)").should == [:super, [:int, 1]]
|
17
|
+
opal_parse("super(1, 2)").should == [:super, [:int, 1], [:int, 2]]
|
18
|
+
opal_parse("super(1, *2)").should == [:super, [:int, 1], [:splat, [:int, 2]]]
|
19
19
|
end
|
20
20
|
end
|
data/spec/parser/undef_spec.rb
CHANGED
@@ -2,14 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The undef keyword" do
|
4
4
|
it "returns s(:undef) with the argument as an s(:lit)" do
|
5
|
-
opal_parse("undef a").should == [:undef, [:
|
5
|
+
opal_parse("undef a").should == [:undef, [:sym, :a]]
|
6
6
|
end
|
7
7
|
|
8
8
|
it "appends multiple parts onto end of list" do
|
9
|
-
opal_parse("undef a, b").should == [:undef, [:
|
9
|
+
opal_parse("undef a, b").should == [:undef, [:sym, :a], [:sym, :b]]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "can take symbols or fitems" do
|
13
|
-
opal_parse("undef :foo").should == [:undef, [:
|
13
|
+
opal_parse("undef :foo").should == [:undef, [:sym, :foo]]
|
14
14
|
end
|
15
15
|
end
|
data/spec/parser/unless_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The unless keyword" do
|
4
4
|
it "returns s(:if) with reversed true and false bodies" do
|
5
|
-
opal_parse("unless 10; 20; end").should == [:if, [:
|
6
|
-
opal_parse("unless 10; 20; 30; end").should == [:if, [:
|
7
|
-
opal_parse("unless 10; 20; else; 30; end").should == [:if, [:
|
5
|
+
opal_parse("unless 10; 20; end").should == [:if, [:int, 10], nil, [:int, 20]]
|
6
|
+
opal_parse("unless 10; 20; 30; end").should == [:if, [:int, 10], nil, [:block, [:int, 20], [:int, 30]]]
|
7
|
+
opal_parse("unless 10; 20; else; 30; end").should == [:if, [:int, 10], [:int, 30], [:int, 20]]
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns s(:if) with reversed true and false bodies for prefix unless" do
|
11
|
-
opal_parse("20 unless 10").should == [:if, [:
|
11
|
+
opal_parse("20 unless 10").should == [:if, [:int, 10], nil, [:int, 20]]
|
12
12
|
end
|
13
13
|
end
|
data/spec/parser/while_spec.rb
CHANGED
@@ -2,14 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The while keyword" do
|
4
4
|
it "returns an s(:while) with the given expr, body and true for head" do
|
5
|
-
opal_parse("while 1; 2; end").should == [:while, [:
|
5
|
+
opal_parse("while 1; 2; end").should == [:while, [:int, 1], [:int, 2], true]
|
6
6
|
end
|
7
7
|
|
8
8
|
it "uses an s(:block) if body has more than one statement" do
|
9
|
-
opal_parse("while 1; 2; 3; end").should == [:while, [:
|
9
|
+
opal_parse("while 1; 2; 3; end").should == [:while, [:int, 1], [:block, [:int, 2], [:int, 3]], true]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "treats the prefix while statement just like a regular while statement" do
|
13
|
-
opal_parse("1 while 2").should == [:while, [:
|
13
|
+
opal_parse("1 while 2").should == [:while, [:int, 2], [:int, 1], true]
|
14
14
|
end
|
15
15
|
end
|
data/spec/parser/xstr_spec.rb
CHANGED
@@ -65,7 +65,7 @@ describe "x-strings" do
|
|
65
65
|
opal_parse('%x{#@@foo}').should == [:dxstr, "", [:evstr, [:cvar, :@@foo]]]
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
it "should match '{' and '}' pairs used to start string before ending match" do
|
69
69
|
opal_parse('%x{{}}').should == [:xstr, "{}"]
|
70
70
|
opal_parse('%x{foo{bar}baz}').should == [:xstr, "foo{bar}baz"]
|
71
71
|
opal_parse('%x{{foo}bar}').should == [:xstr, "{foo}bar"]
|
@@ -75,7 +75,7 @@ describe "x-strings" do
|
|
75
75
|
opal_parse('%x{a{b{c}#{foo}d}e}').should == [:dxstr, "a{b{c}", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d}e"]]
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
it "should match '(' and ')' pairs used to start string before ending match" do
|
79
79
|
opal_parse('%x(())').should == [:xstr, "()"]
|
80
80
|
opal_parse('%x(foo(bar)baz)').should == [:xstr, "foo(bar)baz"]
|
81
81
|
opal_parse('%x((foo)bar)').should == [:xstr, "(foo)bar"]
|
@@ -85,7 +85,7 @@ describe "x-strings" do
|
|
85
85
|
opal_parse('%x(a(b(c)#{foo}d)e)').should == [:dxstr, "a(b(c)", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d)e"]]
|
86
86
|
end
|
87
87
|
|
88
|
-
|
88
|
+
it "should match '[' and ']' pairs used to start string before ending match" do
|
89
89
|
opal_parse('%x[[]]').should == [:xstr, "[]"]
|
90
90
|
opal_parse('%x[foo[bar]baz]').should == [:xstr, "foo[bar]baz"]
|
91
91
|
opal_parse('%x[[foo]bar]').should == [:xstr, "[foo]bar"]
|
data/spec/parser/yield_spec.rb
CHANGED
@@ -6,15 +6,15 @@ describe "The yield keyword" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "appends arguments onto end of s(:yield) without an arglist" do
|
9
|
-
opal_parse("yield 1").should == [:yield, [:
|
10
|
-
opal_parse("yield 1, 2").should == [:yield, [:
|
11
|
-
opal_parse("yield 1, *2").should == [:yield, [:
|
9
|
+
opal_parse("yield 1").should == [:yield, [:int, 1]]
|
10
|
+
opal_parse("yield 1, 2").should == [:yield, [:int, 1], [:int, 2]]
|
11
|
+
opal_parse("yield 1, *2").should == [:yield, [:int, 1], [:splat, [:int, 2]]]
|
12
12
|
end
|
13
13
|
|
14
14
|
it "accepts parans for any number of arguments" do
|
15
15
|
opal_parse("yield()").should == [:yield]
|
16
|
-
opal_parse("yield(1)").should == [:yield, [:
|
17
|
-
opal_parse("yield(1, 2)").should == [:yield, [:
|
18
|
-
opal_parse("yield(1, *2)").should == [:yield, [:
|
16
|
+
opal_parse("yield(1)").should == [:yield, [:int, 1]]
|
17
|
+
opal_parse("yield(1, 2)").should == [:yield, [:int, 1], [:int, 2]]
|
18
|
+
opal_parse("yield(1, *2)").should == [:yield, [:int, 1], [:splat, [:int, 2]]]
|
19
19
|
end
|
20
20
|
end
|
@@ -7,7 +7,7 @@ ruby_version_is "1.9" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "raises an ArgumentError if the number of elements specified is negative" do
|
10
|
-
|
10
|
+
lambda { [1, 2].drop(-3) }.should raise_error(ArgumentError)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns an empty Array if all elements are dropped" do
|
@@ -3,13 +3,9 @@ require File.expand_path('../fixtures/classes', __FILE__)
|
|
3
3
|
require File.expand_path('../shared/collect', __FILE__)
|
4
4
|
|
5
5
|
describe "Array#map" do
|
6
|
-
|
7
|
-
it_behaves_like(:array_collect, :map)
|
8
|
-
end
|
6
|
+
it_behaves_like(:array_collect, :map)
|
9
7
|
end
|
10
8
|
|
11
9
|
describe "Array#map!" do
|
12
|
-
|
13
|
-
it_behaves_like(:array_collect_b, :map!)
|
14
|
-
end
|
10
|
+
it_behaves_like(:array_collect_b, :map!)
|
15
11
|
end
|
@@ -47,7 +47,7 @@ describe "Array#-" do
|
|
47
47
|
([5, 6, 7] - ArraySpecs::ToAryArray[7]).should == [5, 6]
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
it "removes an item identified as equivalent via #hash and #eql?" do
|
51
51
|
obj1 = mock('1')
|
52
52
|
obj2 = mock('2')
|
53
53
|
obj1.should_receive(:hash).and_return(0)
|
@@ -57,7 +57,7 @@ describe "Array#-" do
|
|
57
57
|
([obj1] - [obj2]).should == []
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
it "doesn't remove an item with the same hash but not #eql?" do
|
61
61
|
obj1 = mock('1')
|
62
62
|
obj2 = mock('2')
|
63
63
|
obj1.should_receive(:hash).and_return(0)
|
@@ -67,7 +67,7 @@ describe "Array#-" do
|
|
67
67
|
([obj1] - [obj2]).should == [obj1]
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
it "removes an identical item even when its #eql? isn't reflexive" do
|
71
71
|
x = mock('x')
|
72
72
|
x.should_receive(:hash).any_number_of_times.and_return(42)
|
73
73
|
x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
|
@@ -3,31 +3,31 @@ require File.expand_path('../fixtures/classes', __FILE__)
|
|
3
3
|
require File.expand_path('../shared/join', __FILE__)
|
4
4
|
|
5
5
|
describe "Array#*" do
|
6
|
-
|
6
|
+
it "tries to convert the passed argument to a String using #to_str" do
|
7
7
|
obj = mock('separator')
|
8
8
|
obj.should_receive(:to_str).and_return('::')
|
9
9
|
([1, 2, 3, 4] * obj).should == '1::2::3::4'
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
it "tires to convert the passed argument to an Integer using #to_int" do
|
13
13
|
obj = mock('count')
|
14
14
|
obj.should_receive(:to_int).and_return(2)
|
15
15
|
([1, 2, 3, 4] * obj).should == [1, 2, 3, 4, 1, 2, 3, 4]
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it "raises a TypeError if the argument can neither be converted to a string nor an integer" do
|
19
19
|
obj = mock('not a string or integer')
|
20
20
|
lambda{ [1,2] * obj }.should raise_error(TypeError)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it "converts the passed argument to a String rather than an Integer" do
|
24
24
|
obj = mock('2')
|
25
25
|
def obj.to_int() 2 end
|
26
26
|
def obj.to_str() "2" end
|
27
27
|
([:a, :b, :c] * obj).should == "a2b2c"
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
it "raises a TypeError is the passed argument is nil" do
|
31
31
|
lambda{ [1,2] * nil }.should raise_error(TypeError)
|
32
32
|
end
|
33
33
|
|
@@ -64,7 +64,7 @@ describe "Array#* with an integer" do
|
|
64
64
|
(array * 1).should == array
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
it "raises an ArgumentError when passed a negative integer" do
|
68
68
|
lambda { [ 1, 2, 3 ] * -1 }.should raise_error(ArgumentError)
|
69
69
|
lambda { [] * -1 }.should raise_error(ArgumentError)
|
70
70
|
end
|
@@ -76,7 +76,7 @@ describe "Array#* with an integer" do
|
|
76
76
|
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
it "returns a subclass instance" do
|
80
80
|
(@array * 0).should be_an_instance_of(ArraySpecs::MyArray)
|
81
81
|
(@array * 1).should be_an_instance_of(ArraySpecs::MyArray)
|
82
82
|
(@array * 2).should be_an_instance_of(ArraySpecs::MyArray)
|
@@ -96,20 +96,20 @@ describe "Array#* with an integer" do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
ruby_version_is '1.9' do
|
99
|
-
|
99
|
+
it "copies the taint status of the original array even if the passed count is 0" do
|
100
100
|
ary = [1, 2, 3]
|
101
101
|
ary.taint
|
102
102
|
(ary * 0).tainted?.should == true
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
|
106
|
+
it "copies the taint status of the original array even if the array is empty" do
|
107
107
|
ary = []
|
108
108
|
ary.taint
|
109
109
|
(ary * 3).tainted?.should == true
|
110
110
|
end
|
111
111
|
|
112
|
-
|
112
|
+
it "copies the taint status of the original array if the passed count is not 0" do
|
113
113
|
ary = [1, 2, 3]
|
114
114
|
ary.taint
|
115
115
|
(ary * 1).tainted?.should == true
|
@@ -117,19 +117,19 @@ describe "Array#* with an integer" do
|
|
117
117
|
end
|
118
118
|
|
119
119
|
ruby_version_is '1.9' do
|
120
|
-
|
120
|
+
it "copies the untrusted status of the original array even if the passed count is 0" do
|
121
121
|
ary = [1, 2, 3]
|
122
122
|
ary.untrust
|
123
123
|
(ary * 0).untrusted?.should == true
|
124
124
|
end
|
125
125
|
|
126
|
-
|
126
|
+
it "copies the untrusted status of the original array even if the array is empty" do
|
127
127
|
ary = []
|
128
128
|
ary.untrust
|
129
129
|
(ary * 3).untrusted?.should == true
|
130
130
|
end
|
131
131
|
|
132
|
-
|
132
|
+
it "copies the untrusted status of the original array if the passed count is not 0" do
|
133
133
|
ary = [1, 2, 3]
|
134
134
|
ary.untrust
|
135
135
|
(ary * 1).untrusted?.should == true
|
@@ -139,7 +139,5 @@ describe "Array#* with an integer" do
|
|
139
139
|
end
|
140
140
|
|
141
141
|
describe "Array#* with a string" do
|
142
|
-
|
143
|
-
it_behaves_like :array_join_with_string_separator, :*
|
144
|
-
end
|
142
|
+
it_behaves_like :array_join_with_string_separator, :*
|
145
143
|
end
|
@@ -6,7 +6,7 @@ describe "Array.new" do
|
|
6
6
|
Array.new.should be_kind_of(Array)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
it "returns an instance of a subclass" do
|
10
10
|
ArraySpecs::MyArray.new(1, 2).should be_an_instance_of(ArraySpecs::MyArray)
|
11
11
|
end
|
12
12
|
|
@@ -66,7 +66,7 @@ describe "Array.new with (size, object=nil)" do
|
|
66
66
|
a[1].should equal(obj)
|
67
67
|
end
|
68
68
|
|
69
|
-
it "returns an array of size filled with nil when object is omitted" do
|
69
|
+
it "returns an array of size filled with nil when object is omitted" do
|
70
70
|
Array.new(3).should == [nil, nil, nil]
|
71
71
|
end
|
72
72
|
|
@@ -75,7 +75,6 @@ describe "Array.new with (size, object=nil)" do
|
|
75
75
|
lambda { Array.new(-1) }.should raise_error(ArgumentError)
|
76
76
|
end
|
77
77
|
|
78
|
-
pending do
|
79
78
|
platform_is :wordsize => 32 do
|
80
79
|
it "raises an ArgumentError if size is too large" do
|
81
80
|
max_size = ArraySpecs.max_32bit_size
|
@@ -89,7 +88,6 @@ describe "Array.new with (size, object=nil)" do
|
|
89
88
|
lambda { Array.new(max_size + 1) }.should raise_error(ArgumentError)
|
90
89
|
end
|
91
90
|
end
|
92
|
-
end
|
93
91
|
|
94
92
|
it "calls #to_int to convert the size argument to an Integer when object is given" do
|
95
93
|
obj = mock('1')
|
@@ -111,7 +109,7 @@ describe "Array.new with (size, object=nil)" do
|
|
111
109
|
obj2 = mock('nonnumeric')
|
112
110
|
def obj2.to_int; "123"; end
|
113
111
|
lambda{ Array.new(obj2, :a) }.should raise_error(TypeError)
|
114
|
-
|
112
|
+
|
115
113
|
obj3 = mock('nonnumeric')
|
116
114
|
def obj3.to_int; 1.2; end
|
117
115
|
lambda{ Array.new(obj3, :a) }.should raise_error(TypeError)
|