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/class_spec.rb
CHANGED
@@ -6,11 +6,11 @@ describe "The class keyword" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "does not place single expressions into a s(:block)" do
|
9
|
-
opal_parse('class A; 1; end').should == [:class, :A, nil, [:scope, [:
|
9
|
+
opal_parse('class A; 1; end').should == [:class, :A, nil, [: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').should == [:class, :A, nil, [:scope, [:block, [:
|
13
|
+
opal_parse('class A; 1; 2; end').should == [:class, :A, nil, [:scope, [:block, [:int, 1], [:int, 2]]]]
|
14
14
|
end
|
15
15
|
|
16
16
|
it "uses nil as a placeholder when no superclass is given" do
|
data/spec/parser/const_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Constants" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should be returned as s(:cdecl) on assignment" do
|
10
|
-
opal_parse("FOO = 1").should == [:cdecl, :FOO, [:
|
10
|
+
opal_parse("FOO = 1").should == [:cdecl, :FOO, [:int, 1]]
|
11
11
|
opal_parse("FOO = BAR").should == [:cdecl, :FOO, [:const, :BAR]]
|
12
12
|
end
|
13
13
|
end
|
data/spec/parser/cvar_spec.rb
CHANGED
data/spec/parser/def_spec.rb
CHANGED
@@ -31,14 +31,14 @@ describe "The def keyword" do
|
|
31
31
|
|
32
32
|
describe "with opt args" do
|
33
33
|
it "should list all opt args as well as block with each lasgn" do
|
34
|
-
opal_parse("def foo(a = 1); end")[2].should == [:args, :a, [:block, [:lasgn, :a, [:
|
35
|
-
opal_parse("def foo(a = 1, b = 2); end")[2].should == [:args, :a, :b, [:block, [:lasgn, :a, [:
|
34
|
+
opal_parse("def foo(a = 1); end")[2].should == [:args, :a, [:block, [:lasgn, :a, [:int, 1]]]]
|
35
|
+
opal_parse("def foo(a = 1, b = 2); end")[2].should == [:args, :a, :b, [:block, [:lasgn, :a, [:int, 1]], [:lasgn, :b, [:int, 2]]]]
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should list lasgn block after all other args" do
|
39
|
-
opal_parse("def foo(a, b = 1); end")[2].should == [:args, :a, :b, [:block, [:lasgn, :b, [:
|
40
|
-
opal_parse("def foo(b = 1, *c); end")[2].should == [:args, :b, :"*c", [:block, [:lasgn, :b, [:
|
41
|
-
opal_parse("def foo(b = 1, &block); end")[2].should == [:args, :b, :"&block", [:block, [:lasgn, :b, [:
|
39
|
+
opal_parse("def foo(a, b = 1); end")[2].should == [:args, :a, :b, [:block, [:lasgn, :b, [:int, 1]]]]
|
40
|
+
opal_parse("def foo(b = 1, *c); end")[2].should == [:args, :b, :"*c", [:block, [:lasgn, :b, [:int, 1]]]]
|
41
|
+
opal_parse("def foo(b = 1, &block); end")[2].should == [:args, :b, :"&block", [:block, [:lasgn, :b, [:int, 1]]]]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
data/spec/parser/gvar_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Global variables" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should return s(:gasgn) on assignment" do
|
10
|
-
opal_parse("$foo = 1").should == [:gasgn, :$foo, [:
|
11
|
-
opal_parse("$: = 1").should == [:gasgn, :$:, [:
|
10
|
+
opal_parse("$foo = 1").should == [:gasgn, :$foo, [:int, 1]]
|
11
|
+
opal_parse("$: = 1").should == [:gasgn, :$:, [:int, 1]]
|
12
12
|
end
|
13
13
|
end
|
data/spec/parser/hash_spec.rb
CHANGED
@@ -6,12 +6,12 @@ describe "Hash literals" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "adds each assoc pair as individual args onto sexp" do
|
9
|
-
opal_parse("{1 => 2}").should == [:hash, [:
|
10
|
-
opal_parse("{1 => 2, 3 => 4}").should == [:hash, [:
|
9
|
+
opal_parse("{1 => 2}").should == [:hash, [:int, 1], [:int, 2]]
|
10
|
+
opal_parse("{1 => 2, 3 => 4}").should == [:hash, [:int, 1], [:int, 2], [:int, 3], [:int, 4]]
|
11
11
|
end
|
12
12
|
|
13
13
|
it "supports 1.9 style hash keys" do
|
14
|
-
opal_parse("{ a: 1 }").should == [:hash, [:
|
15
|
-
opal_parse("{ a: 1, b: 2 }").should == [:hash, [:
|
14
|
+
opal_parse("{ a: 1 }").should == [:hash, [:sym, :a], [:int, 1]]
|
15
|
+
opal_parse("{ a: 1, b: 2 }").should == [:hash, [:sym, :a], [:int, 1], [:sym, :b], [:int, 2]]
|
16
16
|
end
|
17
17
|
end
|
data/spec/parser/iasgn_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Instance variable assignment" do
|
4
4
|
it "always returns an s(:iasgn)" do
|
5
|
-
opal_parse("@a = 1").should == [:iasgn, :@a, [:
|
6
|
-
opal_parse("@A = 1").should == [:iasgn, :@A, [:
|
7
|
-
opal_parse("@class = 1").should == [:iasgn, :@class, [:
|
5
|
+
opal_parse("@a = 1").should == [:iasgn, :@a, [:int, 1]]
|
6
|
+
opal_parse("@A = 1").should == [:iasgn, :@A, [:int, 1]]
|
7
|
+
opal_parse("@class = 1").should == [:iasgn, :@class, [:int, 1]]
|
8
8
|
end
|
9
9
|
end
|
data/spec/parser/if_spec.rb
CHANGED
@@ -2,25 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The if keyword" do
|
4
4
|
it "should return an s(:if) with given truthy and falsy bodies" do
|
5
|
-
opal_parse("if 1; 2; else; 3; end").should == [:if, [:
|
5
|
+
opal_parse("if 1; 2; else; 3; end").should == [:if, [:int, 1], [:int, 2], [:int, 3]]
|
6
6
|
end
|
7
7
|
|
8
8
|
it "uses nil as fasly body if not given else-then" do
|
9
|
-
opal_parse("if 1; 2; end").should == [:if, [:
|
9
|
+
opal_parse("if 1; 2; end").should == [:if, [:int, 1], [:int, 2], nil]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "is treats elsif parts as sub if expressions for else body" do
|
13
|
-
opal_parse("if 1; 2; elsif 3; 4; else; 5; end").should == [:if, [:
|
14
|
-
opal_parse("if 1; 2; elsif 3; 4; end").should == [:if, [:
|
13
|
+
opal_parse("if 1; 2; elsif 3; 4; else; 5; end").should == [:if, [:int, 1], [:int, 2], [:if, [:int, 3], [:int, 4], [:int, 5]]]
|
14
|
+
opal_parse("if 1; 2; elsif 3; 4; end").should == [:if, [:int, 1], [:int, 2], [:if, [:int, 3], [:int, 4], nil]]
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns a simple s(:if) with nil else body for prefix if statement" do
|
18
|
-
opal_parse("1 if 2").should == [:if, [:
|
18
|
+
opal_parse("1 if 2").should == [:if, [:int, 2], [:int, 1], nil]
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "The ternary operator" do
|
23
23
|
it "gets converted into an if statement with true and false parts" do
|
24
|
-
opal_parse("1 ? 2 : 3").should == [:if, [:
|
24
|
+
opal_parse("1 ? 2 : 3").should == [:if, [:int, 1], [:int, 2], [:int, 3]]
|
25
25
|
end
|
26
26
|
end
|
data/spec/parser/iter_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe "Iters" do
|
|
4
4
|
describe "Iter on a command" do
|
5
5
|
it "the outer command call gets the iter" do
|
6
6
|
opal_parse("a b do; end").should == [:iter, [:call, nil, :a, [:arglist, [:call, nil, :b, [:arglist]]]], nil]
|
7
|
-
opal_parse("a 1, b do; end").should == [:iter, [:call, nil, :a, [:arglist, [:
|
7
|
+
opal_parse("a 1, b do; end").should == [:iter, [:call, nil, :a, [:arglist, [:int, 1], [:call, nil, :b, [:arglist]]]], nil]
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -40,14 +40,14 @@ describe "Iters" do
|
|
40
40
|
|
41
41
|
describe "with opt args" do
|
42
42
|
it "adds a s(:block) arg to end of s(:masgn) for each lasgn" do
|
43
|
-
opal_parse("proc do |a = 1|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:block, [:lasgn, :a, [:
|
44
|
-
opal_parse("proc do |a = 1, b = 2|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:block, [:lasgn, :a, [:
|
43
|
+
opal_parse("proc do |a = 1|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:block, [:lasgn, :a, [:int, 1]]]]]
|
44
|
+
opal_parse("proc do |a = 1, b = 2|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:block, [:lasgn, :a, [:int, 1]], [:lasgn, :b, [:int, 2]]]]]
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should add lasgn block after all other args" do
|
48
|
-
opal_parse("proc do |a, b = 1|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:block, [:lasgn, :b, [:
|
49
|
-
opal_parse("proc do |b = 1, *c|; end")[2].should == [:masgn, [:array, [:lasgn, :b], [:splat, [:lasgn, :c]], [:block, [:lasgn, :b, [:
|
50
|
-
opal_parse("proc do |b = 1, &c|; end")[2].should == [:masgn, [:array, [:lasgn, :b], [:block_pass, [:lasgn, :c]], [:block, [:lasgn, :b, [:
|
48
|
+
opal_parse("proc do |a, b = 1|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:block, [:lasgn, :b, [:int, 1]]]]]
|
49
|
+
opal_parse("proc do |b = 1, *c|; end")[2].should == [:masgn, [:array, [:lasgn, :b], [:splat, [:lasgn, :c]], [:block, [:lasgn, :b, [:int, 1]]]]]
|
50
|
+
opal_parse("proc do |b = 1, &c|; end")[2].should == [:masgn, [:array, [:lasgn, :b], [:block_pass, [:lasgn, :c]], [:block, [:lasgn, :b, [:int, 1]]]]]
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
data/spec/parser/lambda_spec.rb
CHANGED
@@ -39,8 +39,8 @@ describe "Lambda literals" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "parses opt args" do
|
42
|
-
opal_parse("-> a = 1 {}")[2].should == [:masgn, [:array, [:lasgn, :a], [:block, [:lasgn, :a, [:
|
43
|
-
opal_parse("-> a = 1, b = 2 {}")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:block, [:lasgn, :a, [:
|
42
|
+
opal_parse("-> a = 1 {}")[2].should == [:masgn, [:array, [:lasgn, :a], [:block, [:lasgn, :a, [:int, 1]]]]]
|
43
|
+
opal_parse("-> a = 1, b = 2 {}")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:block, [:lasgn, :a, [:int, 1]], [:lasgn, :b, [:int, 2]]]]]
|
44
44
|
end
|
45
45
|
|
46
46
|
it "parses block args" do
|
@@ -54,11 +54,11 @@ describe "Lambda literals" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should be the single sexp when given one statement" do
|
57
|
-
opal_parse("-> { 42 }")[3].should == [:
|
57
|
+
opal_parse("-> { 42 }")[3].should == [:int, 42]
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should wrap multiple statements into a s(:block)" do
|
61
|
-
opal_parse("-> { 42; 3.142 }")[3].should == [:block, [:
|
61
|
+
opal_parse("-> { 42; 3.142 }")[3].should == [:block, [:int, 42], [:float, 3.142]]
|
62
62
|
end
|
63
63
|
end
|
64
|
-
end
|
64
|
+
end
|
data/spec/parser/lasgn_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Local assignment" do
|
4
4
|
it "returns an s(:lasgn)" do
|
5
|
-
opal_parse("a = 1").should == [:lasgn, :a, [:
|
6
|
-
opal_parse("a = 1; b = 2").should == [:block, [:lasgn, :a, [:
|
5
|
+
opal_parse("a = 1").should == [:lasgn, :a, [:int, 1]]
|
6
|
+
opal_parse("a = 1; b = 2").should == [:block, [:lasgn, :a, [:int, 1]], [:lasgn, :b, [:int, 2]]]
|
7
7
|
end
|
8
8
|
end
|
data/spec/parser/line_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The __LINE__ keyword" do
|
4
4
|
it "should always return a literal number of the current line" do
|
5
|
-
opal_parse("__LINE__").should == [:
|
6
|
-
opal_parse("\n__LINE__").should == [:
|
5
|
+
opal_parse("__LINE__").should == [:int, 1]
|
6
|
+
opal_parse("\n__LINE__").should == [:int, 2]
|
7
7
|
end
|
8
8
|
end
|
data/spec/parser/lvar_spec.rb
CHANGED
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe "An lvar" do
|
4
4
|
describe "in any scope" do
|
5
5
|
it "should be created when an identifier is previously assigned to" do
|
6
|
-
opal_parse("a = 1; a").should == [:block, [:lasgn, :a, [:
|
7
|
-
opal_parse("a = 1; a; a").should == [:block, [:lasgn, :a, [:
|
6
|
+
opal_parse("a = 1; a").should == [:block, [:lasgn, :a, [:int, 1]], [:lvar, :a]]
|
7
|
+
opal_parse("a = 1; a; a").should == [:block, [:lasgn, :a, [:int, 1]], [:lvar, :a], [:lvar, :a]]
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should not be created when no lasgn is previously used on name" do
|
11
11
|
opal_parse("a").should == [:call, nil, :a, [:arglist]]
|
12
|
-
opal_parse("a = 1; b").should == [:block, [:lasgn, :a, [:
|
12
|
+
opal_parse("a = 1; b").should == [:block, [:lasgn, :a, [:int, 1]], [:call, nil, :b, [:arglist]]]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -20,7 +20,7 @@ describe "An lvar" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should be created by an opt arg" do
|
23
|
-
opal_parse("def a(b=10); b; end").should == [:defn, :a, [:args, :b, [:block, [:lasgn, :b, [:
|
23
|
+
opal_parse("def a(b=10); b; end").should == [:defn, :a, [:args, :b, [:block, [:lasgn, :b, [:int, 10]]]], [:scope, [:block, [:lvar, :b]]]]
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should be created by a rest arg" do
|
@@ -32,7 +32,7 @@ describe "An lvar" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should not be created from locals outside the def" do
|
35
|
-
opal_parse("a = 10; def b; a; end").should == [:block, [:lasgn, :a, [:
|
35
|
+
opal_parse("a = 10; def b; a; end").should == [:block, [:lasgn, :a, [:int, 10]], [:defn, :b, [:args], [:scope, [:block, [:call, nil, :a, [:arglist]]]]]]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/spec/parser/masgn_spec.rb
CHANGED
data/spec/parser/module_spec.rb
CHANGED
@@ -6,11 +6,11 @@ describe "The module keyword" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "does not place single expressions into a s(:block)" do
|
9
|
-
opal_parse('module A; 1; end').should == [:module, :A, [:scope, [:
|
9
|
+
opal_parse('module A; 1; end').should == [:module, :A, [:scope, [:int, 1]]]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "adds multiple body expressions into a s(:block)" do
|
13
|
-
opal_parse('module A; 1; 2; end').should == [:module, :A, [:scope, [:block, [:
|
13
|
+
opal_parse('module A; 1; 2; end').should == [:module, :A, [:scope, [:block, [:int, 1], [:int, 2]]]]
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should accept just a constant for the module name" do
|
data/spec/parser/not_spec.rb
CHANGED
@@ -3,25 +3,25 @@ require 'spec_helper'
|
|
3
3
|
describe "The not keyword" do
|
4
4
|
it "returns s(:not) with the single argument" do
|
5
5
|
opal_parse("not self").should == [:not, [:self]]
|
6
|
-
opal_parse("not 42").should == [:not, [:
|
6
|
+
opal_parse("not 42").should == [:not, [:int, 42]]
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "The '!' expression" do
|
11
11
|
it "returns s(:not) with the single argument" do
|
12
12
|
opal_parse("!self").should == [:not, [:self]]
|
13
|
-
opal_parse("!42").should == [:not, [:
|
13
|
+
opal_parse("!42").should == [:not, [:int, 42]]
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "The '!=' expression" do
|
18
18
|
it "rewrites as !(lhs == rhs)" do
|
19
|
-
opal_parse("1 != 2").should == [:not, [:call, [:
|
19
|
+
opal_parse("1 != 2").should == [:not, [:call, [:int, 1], :==, [:arglist, [:int, 2]]]]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "The '!~' expression" do
|
24
24
|
it "rewrites as !(lhs =~ rhs)" do
|
25
|
-
opal_parse("1 !~ 2").should == [:not, [:call, [:
|
25
|
+
opal_parse("1 !~ 2").should == [:not, [:call, [:int, 1], :=~, [:arglist, [:int, 2]]]]
|
26
26
|
end
|
27
27
|
end
|
@@ -10,7 +10,7 @@ describe "op_asgn1" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns an arglist for args inside braces" do
|
13
|
-
opal_parse("self[:foo] += 1")[2].should == [:arglist, [:
|
13
|
+
opal_parse("self[:foo] += 1")[2].should == [:arglist, [:sym, :foo]]
|
14
14
|
end
|
15
15
|
|
16
16
|
it "only uses the operator, not with '=' appended" do
|
@@ -18,6 +18,6 @@ describe "op_asgn1" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "uses a simple sexp, not an arglist" do
|
21
|
-
opal_parse("self[:foo] += 1")[4].should == [:
|
21
|
+
opal_parse("self[:foo] += 1")[4].should == [:int, 1]
|
22
22
|
end
|
23
23
|
end
|
data/spec/parser/or_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The or statement" do
|
4
4
|
it "should always return s(:or)" do
|
5
|
-
opal_parse("1 or 2").should == [:or, [:
|
5
|
+
opal_parse("1 or 2").should == [:or, [:int, 1], [:int, 2]]
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "The || expression" do
|
10
10
|
it "should always return s(:or)" do
|
11
|
-
opal_parse("1 || 2").should == [:or, [:
|
11
|
+
opal_parse("1 || 2").should == [:or, [:int, 1], [:int, 2]]
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Opal::Parser do
|
4
|
+
it "parses operators before \n in command calls" do
|
5
|
+
[:<<, :>>, :|, :^, :&, :<=>, :==, :===, :=~, :>, :>=, :<, :<=, :<<, :>>, :%, :**].each do |mid|
|
6
|
+
opal_parse("self #{mid}\nself").should == [:call, [:self], mid, [:arglist, [:self]]]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should parse simple ruby values" do
|
11
|
+
opal_eval('3.142').should == 3.142
|
12
|
+
opal_eval('123e1').should == 1230.0
|
13
|
+
opal_eval('123E+10').should == 1230000000000.0
|
14
|
+
opal_eval('123e-9').should == 0.000000123
|
15
|
+
opal_eval('false').should == false
|
16
|
+
opal_eval('true').should == true
|
17
|
+
opal_eval('nil').should == nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should parse ruby strings" do
|
21
|
+
opal_eval('"hello world"').should == "hello world"
|
22
|
+
opal_eval('"hello #{100}"').should == "hello 100"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should parse method calls" do
|
26
|
+
opal_eval("[1, 2, 3, 4].inspect").should == "[1, 2, 3, 4]"
|
27
|
+
opal_eval("[1, 2, 3, 4].map { |a| a + 42 }").should == [43, 44, 45, 46]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should parse constant lookups" do
|
31
|
+
opal_eval("Object").should == Object
|
32
|
+
opal_eval("Array").should == Array
|
33
|
+
opal_eval("Opal::Parser").should == Opal::Parser
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should parse class and module definitions" do
|
37
|
+
opal_eval("class ParserModuleDefinition; end")
|
38
|
+
opal_eval <<-STR
|
39
|
+
class ParserClassDefinition
|
40
|
+
CONSTANT = 500
|
41
|
+
|
42
|
+
def foo
|
43
|
+
500
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.bar
|
47
|
+
42
|
48
|
+
end
|
49
|
+
end
|
50
|
+
STR
|
51
|
+
|
52
|
+
ParserClassDefinition.bar.should == 42
|
53
|
+
ParserClassDefinition.new.foo.should == 500
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "multiline comments" do
|
57
|
+
it "parses multiline comments and ignores them" do
|
58
|
+
opal_parse("=begin\nfoo\n=end\n100").should == [:int, 100]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "raises an exception if not closed before end of file" do
|
62
|
+
lambda { opal_parse("=begin\nfoo\nbar") }.should raise_error(Exception, /embedded document meets end of file/)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/spec/parser/parser_spec.rb
CHANGED
@@ -1,47 +1,41 @@
|
|
1
|
-
|
2
|
-
it "should parse simple ruby values" do
|
3
|
-
opal_eval('3.142').should == 3.142
|
4
|
-
opal_eval('123e1').should == 1230.0
|
5
|
-
opal_eval('123E+10').should == 1230000000000.0
|
6
|
-
opal_eval('123e-9').should == 0.000000123
|
7
|
-
opal_eval('false').should == false
|
8
|
-
opal_eval('true').should == true
|
9
|
-
opal_eval('nil').should == nil
|
10
|
-
end
|
1
|
+
require 'spec_helper'
|
11
2
|
|
12
|
-
|
13
|
-
|
14
|
-
opal_eval('"hello #{100}"').should == "hello 100"
|
15
|
-
end
|
3
|
+
describe Opal::Parser do
|
4
|
+
before { @parser = Opal::Parser.new }
|
16
5
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
describe "extract parser options" do
|
7
|
+
it "should return a hash" do
|
8
|
+
@parser.extract_parser_options("").should be_kind_of(Hash)
|
9
|
+
end
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
11
|
+
it "extracts options when first line starts with '# opal:'" do
|
12
|
+
@parser.extract_parser_options("# opal: foo, bar, baz").keys.should == [:foo, :bar, :baz]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "converts any '-' in option name to '_'" do
|
16
|
+
@parser.extract_parser_options("# opal: foo, bar-ba, baz-ba").keys.should == [:foo, :bar_ba, :baz_ba]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets extracted options as true" do
|
20
|
+
@parser.extract_parser_options("# opal: foo, bar").should == { :foo => true, :bar => true }
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
class ParserClassDefinition
|
32
|
-
CONSTANT = 500
|
23
|
+
it "removes prefix of 'no-' or 'no_' from options" do
|
24
|
+
@parser.extract_parser_options("# opal: no-foo, no_bar").keys.should == [:foo, :bar]
|
25
|
+
end
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
it "sets extracted no_ options as false" do
|
28
|
+
@parser.extract_parser_options("# opal: no-foo, no_bar").should == { :foo => false, :bar => false }
|
29
|
+
end
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
STR
|
31
|
+
it "can have a mixture of false and true options" do
|
32
|
+
@parser.extract_parser_options("# opal: no-foo, bar").should == { :foo => false, :bar => true }
|
33
|
+
end
|
43
34
|
|
44
|
-
|
45
|
-
|
35
|
+
it "only extracts options on first line, if present" do
|
36
|
+
@parser.extract_parser_options("# hello world").should == {}
|
37
|
+
@parser.extract_parser_options("# hello world\n# opal: foo").should == {}
|
38
|
+
@parser.extract_parser_options("# opal: ").should == {}
|
39
|
+
end
|
46
40
|
end
|
47
41
|
end
|