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
@@ -0,0 +1,39 @@
|
|
1
|
+
describe "Native#method_missing" do
|
2
|
+
it "should return values" do
|
3
|
+
Native(`{ a: 23 }`).a.should == 23
|
4
|
+
Native(`{ a: { b: 42 } }`).a.b.should == 42
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should call functions" do
|
8
|
+
Native(`{ a: function() { return 42 } }`).a.should == 42
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should pass the proper this to functions" do
|
12
|
+
%x{
|
13
|
+
function foo() {
|
14
|
+
this.baz = 42;
|
15
|
+
}
|
16
|
+
|
17
|
+
foo.prototype.bar = function () {
|
18
|
+
return this.baz;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
obj = `new foo()`
|
23
|
+
Native(obj).bar.should == 42
|
24
|
+
Native(obj).baz = 23
|
25
|
+
Native(obj).bar.should == 23
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set values" do
|
29
|
+
var = `{}`
|
30
|
+
|
31
|
+
Native(var).a = 42
|
32
|
+
`#{var}.a`.should == 42
|
33
|
+
Native(var).a.should == 42
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should pass the block as function" do
|
37
|
+
Native(`{ a: function(func) { return func(); } }`).a { 42 }.should == 42
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "Native.new" do
|
2
|
+
it "fails when trying to instantiate a non derived class" do
|
3
|
+
lambda {
|
4
|
+
Native.new
|
5
|
+
}.should raise_error ArgumentError
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should pass all arguments to derived classes" do
|
9
|
+
Class.new(Native) {
|
10
|
+
def initialize(a, b, &c)
|
11
|
+
@a, @b, @c = a, b, c
|
12
|
+
end
|
13
|
+
|
14
|
+
def proper?
|
15
|
+
not (@a.nil? || @b.nil? || @c.nil?)
|
16
|
+
end
|
17
|
+
}.new(1, 2) { }.proper?.should be_true
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe "Native#nil?" do
|
2
|
+
it "returns true for wrapped null" do
|
3
|
+
Native(`null`).nil?.should be_true
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns true for wrapped undefined" do
|
7
|
+
Native(`undefined`).nil?.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns false for everything else" do
|
11
|
+
Native(`false`).nil?.should be_false
|
12
|
+
Native(`{}`).nil?.should be_false
|
13
|
+
end
|
14
|
+
end
|
@@ -3,7 +3,7 @@ describe "Class Hierarchy" do
|
|
3
3
|
BasicObject.superclass.should == nil
|
4
4
|
Object.superclass.should == BasicObject
|
5
5
|
Module.superclass.should == Object
|
6
|
-
Class.superclass.should ==
|
6
|
+
Class.superclass.should == Module
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should have the right classes" do
|
@@ -18,4 +18,4 @@ describe "Class Hierarchy" do
|
|
18
18
|
Class.new.class.should == Class
|
19
19
|
Module.new.class.should == Module
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
@@ -4,13 +4,9 @@ require 'opal-source-maps'
|
|
4
4
|
describe Opal::SourceMap do
|
5
5
|
before do
|
6
6
|
pathname = 'foo.rb'
|
7
|
-
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
it 'source has the magic comments' do
|
12
|
-
Opal::SourceMap::FILE_REGEXP.should =~ @source
|
13
|
-
Opal::SourceMap::LINE_REGEXP.should =~ @source
|
7
|
+
parser = Opal::Parser.new
|
8
|
+
@source = parser.parse("1 + 1", pathname)
|
9
|
+
@map = Opal::SourceMap.new(parser.fragments, pathname)
|
14
10
|
end
|
15
11
|
|
16
12
|
it 'does not blow while generating the map' do
|
data/spec/ospec/main.rb.erb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
<% require_asset '
|
2
|
-
<% require_asset 'opal-parser' %>
|
3
|
-
<% require_asset 'mspec' %>
|
4
|
-
<% require_asset 'ospec/runner' %>
|
1
|
+
<% require_asset 'spec_helper' %>
|
5
2
|
|
6
3
|
# Load all opal filters
|
7
|
-
<% Dir.glob('spec/
|
4
|
+
<% Dir.glob('spec/filters/**/*.rb').each do |s| %>
|
8
5
|
<% require_asset s.sub(/^spec\//, '').sub(/\.rb$/, '') %>
|
9
6
|
<% end %>
|
10
7
|
|
data/spec/parser/alias_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The alias keyword" do
|
4
4
|
describe "with fitem" do
|
5
|
-
it "should return an s(:alias) with s(:
|
6
|
-
opal_parse("alias a b").should == [:alias, [:
|
7
|
-
opal_parse("alias == equals").should == [:alias, [:
|
5
|
+
it "should return an s(:alias) with s(:sym)" do
|
6
|
+
opal_parse("alias a b").should == [:alias, [:sym, :a], [:sym, :b]]
|
7
|
+
opal_parse("alias == equals").should == [:alias, [:sym, :==], [:sym, :equals]]
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should accept symbols as names" do
|
11
|
-
opal_parse("alias :foo :bar").should == [:alias, [:
|
11
|
+
opal_parse("alias :foo :bar").should == [:alias, [:sym, :foo], [:sym, :bar]]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
data/spec/parser/and_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The and statement" do
|
4
4
|
it "should always return s(:and)" do
|
5
|
-
opal_parse("1 and 2").should == [:and, [:
|
5
|
+
opal_parse("1 and 2").should == [:and, [: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(:and)" do
|
11
|
-
opal_parse("1 && 2").should == [:and, [:
|
11
|
+
opal_parse("1 && 2").should == [:and, [:int, 1], [:int, 2]]
|
12
12
|
end
|
13
13
|
end
|
data/spec/parser/array_spec.rb
CHANGED
@@ -6,17 +6,17 @@ describe "Arrays" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should append regular args onto end of array sexp" do
|
9
|
-
opal_parse("[1]").should == [:array, [:
|
10
|
-
opal_parse("[1, 2]").should == [:array, [:
|
11
|
-
opal_parse("[1, 2, 3]").should == [:array, [:
|
9
|
+
opal_parse("[1]").should == [:array, [:int, 1]]
|
10
|
+
opal_parse("[1, 2]").should == [:array, [:int, 1], [:int, 2]]
|
11
|
+
opal_parse("[1, 2, 3]").should == [:array, [:int, 1], [:int, 2], [:int, 3]]
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return a single item s(:array) with given splat if no norm args" do
|
15
|
-
opal_parse("[*1]").should == [:array, [:splat, [:
|
15
|
+
opal_parse("[*1]").should == [:array, [:splat, [:int, 1]]]
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should allow splats combined with any number of norm args" do
|
19
|
-
opal_parse("[1, *2]").should == [:array, [:
|
20
|
-
opal_parse("[1, 2, *3]").should == [:array, [:
|
19
|
+
opal_parse("[1, *2]").should == [:array, [:int, 1], [:splat, [:int, 2]]]
|
20
|
+
opal_parse("[1, 2, *3]").should == [:array, [:int, 1], [:int, 2], [:splat, [:int, 3]]]
|
21
21
|
end
|
22
22
|
end
|
@@ -2,27 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Attribute assignments" do
|
4
4
|
it "should return a s(:attrasgn) for simple assignments" do
|
5
|
-
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:
|
6
|
-
opal_parse('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:
|
7
|
-
opal_parse('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:
|
5
|
+
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
|
6
|
+
opal_parse('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:int, 1]]]
|
7
|
+
opal_parse('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:int, 1]]]
|
8
8
|
end
|
9
9
|
|
10
10
|
it "accepts both '.' and '::' for method call operators" do
|
11
|
-
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:
|
12
|
-
opal_parse('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:
|
11
|
+
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
|
12
|
+
opal_parse('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
|
13
13
|
end
|
14
14
|
|
15
15
|
it "can accept a constant as assignable name when using '.'" do
|
16
|
-
opal_parse('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:
|
16
|
+
opal_parse('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:int, 1]]]
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "when setting element reference" do
|
20
20
|
it "uses []= as the method call" do
|
21
|
-
opal_parse('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:
|
21
|
+
opal_parse('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2]]]
|
22
22
|
end
|
23
23
|
|
24
24
|
it "supports multiple arguments inside brackets" do
|
25
|
-
opal_parse('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:
|
25
|
+
opal_parse('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2], [:int, 3]]]
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/spec/parser/begin_spec.rb
CHANGED
@@ -2,41 +2,41 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "The begin keyword" do
|
4
4
|
it "should be removed when used without a resuce or enusre body" do
|
5
|
-
opal_parse('begin; 1; end').should == [:
|
6
|
-
opal_parse('begin; 1; 2; end').should == [:block, [:
|
5
|
+
opal_parse('begin; 1; end').should == [:int, 1]
|
6
|
+
opal_parse('begin; 1; 2; end').should == [:block, [:int, 1], [:int, 2]]
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "with 'rescue' bodies" do
|
10
10
|
it "should create a s(:rescue) sexp" do
|
11
|
-
opal_parse('begin; 1; rescue; 2; end').should == [:rescue, [:
|
11
|
+
opal_parse('begin; 1; rescue; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
|
12
12
|
end
|
13
13
|
|
14
14
|
it "allows multiple rescue bodies" do
|
15
|
-
opal_parse('begin 1; rescue; 2; rescue; 3; end').should == [:rescue, [:
|
15
|
+
opal_parse('begin 1; rescue; 2; rescue; 3; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]], [:resbody, [:array], [:int, 3]]]
|
16
16
|
end
|
17
17
|
|
18
18
|
it "accepts a list of classes used to match against the exception" do
|
19
|
-
opal_parse('begin 1; rescue Klass; 2; end').should == [:rescue, [:
|
19
|
+
opal_parse('begin 1; rescue Klass; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass]], [:int, 2]]]
|
20
20
|
end
|
21
21
|
|
22
22
|
it "accepts an identifier to assign exception to" do
|
23
|
-
opal_parse('begin 1; rescue => a; 2; end').should == [:rescue, [:
|
24
|
-
opal_parse('begin 1; rescue Klass => a; 2; end').should == [:rescue, [:
|
23
|
+
opal_parse('begin 1; rescue => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
|
24
|
+
opal_parse('begin 1; rescue Klass => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
|
25
25
|
end
|
26
26
|
|
27
27
|
it "accepts an ivar to assign exception to" do
|
28
|
-
opal_parse('begin 1; rescue => @a; 2; end').should == [:rescue, [:
|
29
|
-
opal_parse('begin 1; rescue Klass => @a; 2; end').should == [:rescue, [:
|
28
|
+
opal_parse('begin 1; rescue => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
|
29
|
+
opal_parse('begin 1; rescue Klass => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should parse newline right after rescue" do
|
33
|
-
opal_parse("begin; 1; rescue\n 2; end").should == [:rescue, [:
|
33
|
+
opal_parse("begin; 1; rescue\n 2; end").should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "with an 'ensure' block" do
|
38
38
|
it "should propagate into single s(:ensure) statement when no rescue block given" do
|
39
|
-
opal_parse('begin; 1; ensure; 2; end').should == [:ensure, [:
|
39
|
+
opal_parse('begin; 1; ensure; 2; end').should == [:ensure, [:int, 1], [:int, 2]]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/spec/parser/block_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Block statements" do
|
4
4
|
it "should return the direct expression if only one expresssion in block" do
|
5
|
-
opal_parse("42").should == [:
|
5
|
+
opal_parse("42").should == [:int, 42]
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return an s(:block) with all expressions appended for > 1 expression" do
|
9
|
-
opal_parse("42; 43").should == [:block, [:
|
10
|
-
opal_parse("42; 43\n44").should == [:block, [:
|
9
|
+
opal_parse("42; 43").should == [:block, [:int, 42], [:int, 43]]
|
10
|
+
opal_parse("42; 43\n44").should == [:block, [:int, 42], [:int, 43], [:int, 44]]
|
11
11
|
end
|
12
12
|
end
|
data/spec/parser/break_spec.rb
CHANGED
@@ -6,12 +6,12 @@ describe "The break keyword" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "returns s(:break) with a single arg not wrapped in s(:array)" do
|
9
|
-
opal_parse("break 1").should == [:break, [:
|
10
|
-
opal_parse("break *1").should == [:break, [:splat, [:
|
9
|
+
opal_parse("break 1").should == [:break, [:int, 1]]
|
10
|
+
opal_parse("break *1").should == [:break, [:splat, [:int, 1]]]
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns s(:break) with an s(:array) for args size > 1" do
|
14
|
-
opal_parse("break 1, 2").should == [:break, [:array, [:
|
15
|
-
opal_parse("break 1, *2").should == [:break, [:array, [:
|
14
|
+
opal_parse("break 1, 2").should == [:break, [:array, [:int, 1], [:int, 2]]]
|
15
|
+
opal_parse("break 1, *2").should == [:break, [:array, [:int, 1], [:splat, [:int, 2]]]]
|
16
16
|
end
|
17
17
|
end
|
data/spec/parser/call_spec.rb
CHANGED
@@ -14,91 +14,93 @@ describe "Method calls" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "appends all arguments onto arglist" do
|
17
|
-
opal_parse("foo 1").should == [:call, nil, :foo, [:arglist, [:
|
18
|
-
opal_parse("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:
|
19
|
-
opal_parse("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:
|
17
|
+
opal_parse("foo 1").should == [:call, nil, :foo, [:arglist, [:int, 1]]]
|
18
|
+
opal_parse("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:int, 2]]]
|
19
|
+
opal_parse("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:splat, [:int, 2]]]]
|
20
20
|
end
|
21
|
-
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
opal_parse("
|
26
|
-
opal_parse("1 - 2").should == [:operator, :-, [:lit, 1], [:lit, 2]]
|
27
|
-
opal_parse("1 / 2").should == [:operator, :/, [:lit, 1], [:lit, 2]]
|
28
|
-
opal_parse("1 * 2").should == [:operator, :*, [:lit, 1], [:lit, 2]]
|
22
|
+
it "supports leading dots on newline" do
|
23
|
+
opal_parse("foo\n.bar").should == [:call, [:call, nil, :foo, [:arglist]], :bar, [:arglist]]
|
24
|
+
lambda { opal_parse("foo\n..bar") }.should raise_error(Exception)
|
29
25
|
end
|
26
|
+
end
|
30
27
|
|
28
|
+
describe "Operator calls" do
|
31
29
|
it "should parse all other operators into method calls" do
|
32
|
-
opal_parse("1 % 2").should == [:call, [:
|
33
|
-
opal_parse("1 ** 2").should == [:call, [:
|
30
|
+
opal_parse("1 % 2").should == [:call, [:int, 1], :%, [:arglist, [:int, 2]]]
|
31
|
+
opal_parse("1 ** 2").should == [:call, [:int, 1], :**, [:arglist, [:int, 2]]]
|
34
32
|
|
35
33
|
opal_parse("+self").should == [:call, [:self], :+@, [:arglist]]
|
36
34
|
opal_parse("-self").should == [:call, [:self], :-@, [:arglist]]
|
37
35
|
|
38
|
-
opal_parse("1 | 2").should == [:call, [:
|
39
|
-
opal_parse("1 ^ 2").should == [:call, [:
|
40
|
-
opal_parse("1 & 2").should == [:call, [:
|
41
|
-
opal_parse("1 <=> 2").should == [:call, [:
|
36
|
+
opal_parse("1 | 2").should == [:call, [:int, 1], :|, [:arglist, [:int, 2]]]
|
37
|
+
opal_parse("1 ^ 2").should == [:call, [:int, 1], :^, [:arglist, [:int, 2]]]
|
38
|
+
opal_parse("1 & 2").should == [:call, [:int, 1], :&, [:arglist, [:int, 2]]]
|
39
|
+
opal_parse("1 <=> 2").should == [:call, [:int, 1], :<=>, [:arglist, [:int, 2]]]
|
42
40
|
|
43
|
-
opal_parse("1 < 2").should == [:call, [:
|
44
|
-
opal_parse("1 <= 2").should == [:call, [:
|
45
|
-
opal_parse("1 > 2").should == [:call, [:
|
46
|
-
opal_parse("1 >= 2").should == [:call, [:
|
41
|
+
opal_parse("1 < 2").should == [:call, [:int, 1], :<, [:arglist, [:int, 2]]]
|
42
|
+
opal_parse("1 <= 2").should == [:call, [:int, 1], :<=, [:arglist, [:int, 2]]]
|
43
|
+
opal_parse("1 > 2").should == [:call, [:int, 1], :>, [:arglist, [:int, 2]]]
|
44
|
+
opal_parse("1 >= 2").should == [:call, [:int, 1], :>=, [:arglist, [:int, 2]]]
|
47
45
|
|
48
|
-
opal_parse("1 == 2").should == [:call, [:
|
49
|
-
opal_parse("1 === 2").should == [:call, [:
|
50
|
-
opal_parse("1 =~ 2").should == [:call, [:
|
46
|
+
opal_parse("1 == 2").should == [:call, [:int, 1], :==, [:arglist, [:int, 2]]]
|
47
|
+
opal_parse("1 === 2").should == [:call, [:int, 1], :===, [:arglist, [:int, 2]]]
|
48
|
+
opal_parse("1 =~ 2").should == [:call, [:int, 1], :=~, [:arglist, [:int, 2]]]
|
51
49
|
|
52
|
-
opal_parse("~1").should == [:call, [:
|
53
|
-
opal_parse("1 << 2").should == [:call, [:
|
54
|
-
opal_parse("1 >> 2").should == [:call, [:
|
50
|
+
opal_parse("~1").should == [:call, [:int, 1], :~, [:arglist]]
|
51
|
+
opal_parse("1 << 2").should == [:call, [:int, 1], :<<, [:arglist, [:int, 2]]]
|
52
|
+
opal_parse("1 >> 2").should == [:call, [:int, 1], :>>, [:arglist, [:int, 2]]]
|
55
53
|
end
|
56
54
|
|
57
55
|
it "optimizes +@ and -@ on numerics" do
|
58
|
-
opal_parse("+1").should == [:
|
59
|
-
opal_parse("-1").should == [:
|
56
|
+
opal_parse("+1").should == [:int, 1]
|
57
|
+
opal_parse("-1").should == [:int, -1]
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
63
61
|
describe "Optional paren calls" do
|
64
62
|
it "should correctly parse - and -@" do
|
65
|
-
opal_parse("x - 1").should == [:
|
66
|
-
opal_parse("x -1").should == [:call, nil, :x, [:arglist, [:
|
63
|
+
opal_parse("x - 1").should == [:call, [:call, nil, :x, [:arglist]], :-, [:arglist, [:int, 1]]]
|
64
|
+
opal_parse("x -1").should == [:call, nil, :x, [:arglist, [:int, -1]]]
|
67
65
|
end
|
68
66
|
|
69
67
|
it "should correctly parse + and +@" do
|
70
|
-
opal_parse("x + 1").should == [:
|
71
|
-
opal_parse("x +1").should == [:call, nil, :x, [:arglist, [:
|
68
|
+
opal_parse("x + 1").should == [:call, [:call, nil, :x, [:arglist]], :+, [:arglist, [:int, 1]]]
|
69
|
+
opal_parse("x +1").should == [:call, nil, :x, [:arglist, [:int, 1]]]
|
72
70
|
end
|
73
71
|
|
74
72
|
it "should correctly parse / and regexps" do
|
75
|
-
opal_parse("x / 500").should == [:
|
76
|
-
opal_parse("x /foo/").should == [:call, nil, :x, [:arglist, [:
|
73
|
+
opal_parse("x / 500").should == [:call, [:call, nil, :x, [:arglist]], :/, [:arglist, [:int, 500]]]
|
74
|
+
opal_parse("x /foo/").should == [:call, nil, :x, [:arglist, [:regexp, /foo/]]]
|
77
75
|
end
|
78
76
|
|
79
77
|
it "should parse LPAREN_ARG correctly" do
|
80
|
-
opal_parse("x (1).y").should == [:call, nil, :x, [:arglist, [:call, [:
|
81
|
-
opal_parse("x(1).y").should == [:call, [:call, nil, :x, [:arglist, [:
|
78
|
+
opal_parse("x (1).y").should == [:call, nil, :x, [:arglist, [:call, [:int, 1], :y, [:arglist]]]]
|
79
|
+
opal_parse("x(1).y").should == [:call, [:call, nil, :x, [:arglist, [:int, 1]]], :y, [:arglist]]
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
85
83
|
describe "Operator precedence" do
|
86
84
|
it "should be raised with parentheses" do
|
87
|
-
opal_parse("(1 + 2) + (3 - 4)").should == [:
|
88
|
-
[:
|
89
|
-
|
85
|
+
opal_parse("(1 + 2) + (3 - 4)").should == [:call,
|
86
|
+
[:call, [:int, 1], :+, [:arglist, [:int, 2]]],
|
87
|
+
:+,
|
88
|
+
[:arglist, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]],
|
90
89
|
]
|
91
|
-
opal_parse("(1 + 2) - (3 - 4)").should == [:
|
92
|
-
[:
|
93
|
-
|
90
|
+
opal_parse("(1 + 2) - (3 - 4)").should == [:call,
|
91
|
+
[:call, [:int, 1], :+, [:arglist, [:int, 2]]],
|
92
|
+
:-,
|
93
|
+
[:arglist, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]],
|
94
94
|
]
|
95
|
-
opal_parse("(1 + 2) * (3 - 4)").should == [:
|
96
|
-
[:
|
97
|
-
|
95
|
+
opal_parse("(1 + 2) * (3 - 4)").should == [:call,
|
96
|
+
[:call, [:int, 1], :+, [:arglist, [:int, 2]]],
|
97
|
+
:*,
|
98
|
+
[:arglist, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]],
|
98
99
|
]
|
99
|
-
opal_parse("(1 + 2) / (3 - 4)").should == [:
|
100
|
-
[:
|
101
|
-
|
100
|
+
opal_parse("(1 + 2) / (3 - 4)").should == [:call,
|
101
|
+
[:call, [:int, 1], :+, [:arglist, [:int, 2]]],
|
102
|
+
:/,
|
103
|
+
[:arglist, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]],
|
102
104
|
]
|
103
105
|
end
|
104
106
|
end
|