opal 0.3.11 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/Gemfile +10 -0
- data/LICENSE +20 -0
- data/README.md +11 -116
- data/Rakefile +126 -0
- data/bin/opal +1 -2
- data/docs/spec_runner.html +16 -0
- data/index.html +434 -0
- data/lib/opal.rb +14 -15
- data/lib/opal/builder.rb +46 -148
- data/lib/opal/command.rb +45 -115
- data/lib/opal/context.rb +139 -78
- data/lib/opal/dependency_builder.rb +34 -0
- data/lib/opal/environment.rb +92 -0
- data/lib/opal/parser/grammar.rb +4915 -0
- data/lib/opal/{parser.y → parser/grammar.y} +430 -284
- data/lib/opal/parser/lexer.rb +1329 -0
- data/lib/opal/parser/parser.rb +1460 -0
- data/lib/opal/parser/scope.rb +140 -0
- data/lib/opal/parser/sexp.rb +17 -0
- data/lib/opal/version.rb +2 -1
- data/opal.gemspec +23 -0
- data/opal.js +3149 -4162
- data/runtime/README.md +25 -0
- data/runtime/corelib/alpha.rb +10 -0
- data/runtime/corelib/array.rb +962 -0
- data/runtime/corelib/basic_object.rb +66 -0
- data/runtime/corelib/boolean.rb +44 -0
- data/runtime/corelib/class.rb +43 -0
- data/runtime/corelib/comparable.rb +25 -0
- data/runtime/corelib/complex.rb +2 -0
- data/runtime/corelib/dir.rb +29 -0
- data/runtime/corelib/enumerable.rb +316 -0
- data/runtime/corelib/enumerator.rb +80 -0
- data/runtime/corelib/error.rb +25 -0
- data/runtime/corelib/file.rb +80 -0
- data/runtime/corelib/hash.rb +503 -0
- data/runtime/corelib/io.rb +44 -0
- data/runtime/corelib/kernel.rb +237 -0
- data/runtime/corelib/load_order +29 -0
- data/runtime/corelib/match_data.rb +37 -0
- data/runtime/corelib/module.rb +171 -0
- data/runtime/corelib/native.rb +50 -0
- data/runtime/corelib/nil_class.rb +47 -0
- data/runtime/corelib/numeric.rb +219 -0
- data/runtime/corelib/object.rb +21 -0
- data/runtime/corelib/proc.rb +42 -0
- data/runtime/corelib/range.rb +38 -0
- data/runtime/corelib/rational.rb +16 -0
- data/runtime/corelib/regexp.rb +63 -0
- data/runtime/corelib/string.rb +185 -0
- data/runtime/corelib/struct.rb +97 -0
- data/runtime/corelib/time.rb +196 -0
- data/runtime/corelib/top_self.rb +7 -0
- data/runtime/gemlib/alpha.rb +5 -0
- data/runtime/gemlib/kernel.rb +17 -0
- data/runtime/gemlib/load_order +2 -0
- data/runtime/kernel/class.js +256 -0
- data/runtime/kernel/debug.js +42 -0
- data/runtime/kernel/init.js +114 -0
- data/runtime/kernel/load_order +5 -0
- data/runtime/kernel/loader.js +151 -0
- data/runtime/kernel/runtime.js +414 -0
- data/runtime/spec/README.md +34 -0
- data/runtime/spec/core/array/allocate_spec.rb +15 -0
- data/runtime/spec/core/array/append_spec.rb +31 -0
- data/runtime/spec/core/array/assoc_spec.rb +29 -0
- data/runtime/spec/core/array/at_spec.rb +38 -0
- data/runtime/spec/core/array/clear_spec.rb +22 -0
- data/runtime/spec/core/array/collect_spec.rb +3 -0
- data/runtime/spec/core/array/compact_spec.rb +42 -0
- data/runtime/spec/core/array/concat_spec.rb +21 -0
- data/runtime/spec/core/array/constructor_spec.rb +24 -0
- data/runtime/spec/core/array/count_spec.rb +11 -0
- data/runtime/spec/core/array/delete_at_spec.rb +31 -0
- data/runtime/spec/core/array/delete_if_spec.rb +24 -0
- data/runtime/spec/core/array/delete_spec.rb +26 -0
- data/runtime/spec/core/array/each_index_spec.rb +33 -0
- data/runtime/spec/core/array/each_spec.rb +11 -0
- data/runtime/spec/core/array/element_reference_spec.rb +136 -0
- data/runtime/spec/core/array/element_set_spec.rb +7 -0
- data/runtime/spec/core/array/empty_spec.rb +10 -0
- data/runtime/spec/core/array/eql_spec.rb +3 -0
- data/runtime/spec/core/array/equal_value_spec.rb +3 -0
- data/runtime/spec/core/array/fetch_spec.rb +26 -0
- data/runtime/spec/core/array/first_spec.rb +54 -0
- data/runtime/spec/core/array/fixtures/classes.rb +8 -0
- data/runtime/spec/core/array/flatten_spec.rb +41 -0
- data/runtime/spec/core/array/include_spec.rb +20 -0
- data/runtime/spec/core/array/insert_spec.rb +59 -0
- data/runtime/spec/core/array/last_spec.rb +57 -0
- data/runtime/spec/core/array/length_spec.rb +3 -0
- data/runtime/spec/core/array/map_spec.rb +3 -0
- data/runtime/spec/core/array/plus_spec.rb +16 -0
- data/runtime/spec/core/array/pop_spec.rb +79 -0
- data/runtime/spec/core/array/push_spec.rb +19 -0
- data/runtime/spec/core/array/rassoc_spec.rb +12 -0
- data/runtime/spec/core/array/reject_spec.rb +54 -0
- data/runtime/spec/core/array/replace_spec.rb +3 -0
- data/runtime/spec/core/array/reverse_each_spec.rb +18 -0
- data/runtime/spec/core/array/reverse_spec.rb +9 -0
- data/runtime/spec/core/array/shared/collect.rb +53 -0
- data/runtime/spec/core/array/shared/eql.rb +19 -0
- data/runtime/spec/core/array/shared/length.rb +6 -0
- data/runtime/spec/core/array/shared/replace.rb +31 -0
- data/runtime/spec/core/class/new_spec.rb +19 -0
- data/runtime/spec/core/enumerable/all_spec.rb +102 -0
- data/runtime/spec/core/enumerable/any_spec.rb +115 -0
- data/runtime/spec/core/enumerable/collect_spec.rb +3 -0
- data/runtime/spec/core/enumerable/count_spec.rb +29 -0
- data/runtime/spec/core/enumerable/detect_spec.rb +3 -0
- data/runtime/spec/core/enumerable/find_spec.rb +3 -0
- data/runtime/spec/core/enumerable/fixtures/classes.rb +26 -0
- data/runtime/spec/core/enumerable/shared/collect.rb +12 -0
- data/runtime/spec/core/enumerable/shared/entries.rb +7 -0
- data/runtime/spec/core/enumerable/shared/find.rb +49 -0
- data/runtime/spec/core/enumerable/to_a_spec.rb +7 -0
- data/runtime/spec/core/false/and_spec.rb +11 -0
- data/runtime/spec/core/false/inspect_spec.rb +7 -0
- data/runtime/spec/core/false/or_spec.rb +11 -0
- data/runtime/spec/core/false/to_s_spec.rb +7 -0
- data/runtime/spec/core/false/xor_spec.rb +11 -0
- data/runtime/spec/core/hash/allocate_spec.rb +15 -0
- data/runtime/spec/core/hash/assoc_spec.rb +29 -0
- data/runtime/spec/core/hash/clear_spec.rb +21 -0
- data/runtime/spec/core/hash/clone_spec.rb +12 -0
- data/runtime/spec/core/hash/default_spec.rb +6 -0
- data/runtime/spec/core/hash/delete_if_spec.rb +15 -0
- data/runtime/spec/core/hash/element_reference_spec.rb +16 -0
- data/runtime/spec/core/hash/element_set_spec.rb +8 -0
- data/runtime/spec/core/hash/new_spec.rb +13 -0
- data/runtime/spec/core/matchdata/to_a_spec.rb +7 -0
- data/runtime/spec/core/nil/and_spec.rb +12 -0
- data/runtime/spec/core/nil/inspect_spec.rb +8 -0
- data/runtime/spec/core/nil/nil_spec.rb +8 -0
- data/runtime/spec/core/nil/or_spec.rb +12 -0
- data/runtime/spec/core/nil/to_a_spec.rb +8 -0
- data/runtime/spec/core/nil/to_f_spec.rb +12 -0
- data/runtime/spec/core/nil/to_i_spec.rb +12 -0
- data/runtime/spec/core/nil/to_s_spec.rb +8 -0
- data/runtime/spec/core/nil/xor_spec.rb +12 -0
- data/runtime/spec/core/numeric/equal_value_spec.rb +11 -0
- data/runtime/spec/core/object/is_a_spec.rb +2 -0
- data/runtime/spec/core/object/shared/kind_of.rb +0 -0
- data/runtime/spec/core/regexp/match_spec.rb +23 -0
- data/runtime/spec/core/regexp/shared/match.rb +11 -0
- data/runtime/spec/core/symbol/to_proc_spec.rb +8 -0
- data/runtime/spec/core/true/and_spec.rb +11 -0
- data/runtime/spec/core/true/inspect_spec.rb +7 -0
- data/runtime/spec/core/true/or_spec.rb +11 -0
- data/runtime/spec/core/true/to_s_spec.rb +7 -0
- data/runtime/spec/core/true/xor_spec.rb +11 -0
- data/runtime/spec/language/alias_spec.rb +25 -0
- data/runtime/spec/language/and_spec.rb +62 -0
- data/runtime/spec/language/array_spec.rb +68 -0
- data/runtime/spec/language/block_spec.rb +105 -0
- data/runtime/spec/language/break_spec.rb +49 -0
- data/runtime/spec/language/case_spec.rb +165 -0
- data/runtime/spec/language/defined_spec.rb +80 -0
- data/runtime/spec/language/ensure_spec.rb +82 -0
- data/runtime/spec/language/fixtures/block.rb +19 -0
- data/runtime/spec/language/fixtures/break.rb +39 -0
- data/runtime/spec/language/fixtures/defined.rb +9 -0
- data/runtime/spec/language/fixtures/ensure.rb +37 -0
- data/runtime/spec/language/fixtures/next.rb +46 -0
- data/runtime/spec/language/fixtures/send.rb +36 -0
- data/runtime/spec/language/fixtures/super.rb +43 -0
- data/runtime/spec/language/hash_spec.rb +43 -0
- data/runtime/spec/language/if_spec.rb +278 -0
- data/runtime/spec/language/loop_spec.rb +32 -0
- data/runtime/spec/language/next_spec.rb +128 -0
- data/runtime/spec/language/or_spec.rb +65 -0
- data/runtime/spec/language/predefined_spec.rb +21 -0
- data/runtime/spec/language/regexp/interpolation_spec.rb +9 -0
- data/runtime/spec/language/regexp_spec.rb +7 -0
- data/runtime/spec/language/send_spec.rb +105 -0
- data/runtime/spec/language/string_spec.rb +4 -0
- data/runtime/spec/language/super_spec.rb +18 -0
- data/runtime/spec/language/symbol_spec.rb +41 -0
- data/runtime/spec/language/undef_spec.rb +16 -0
- data/runtime/spec/language/unless_spec.rb +44 -0
- data/runtime/spec/language/until_spec.rb +137 -0
- data/runtime/spec/language/variables_spec.rb +28 -0
- data/runtime/spec/language/versions/hash_1.9.rb +20 -0
- data/runtime/spec/language/while_spec.rb +175 -0
- data/runtime/spec/library/stringscanner/scan_spec.rb +36 -0
- data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +49 -0
- data/runtime/spec/opal/opal/defined_spec.rb +15 -0
- data/runtime/spec/opal/opal/function_spec.rb +11 -0
- data/runtime/spec/opal/opal/native_spec.rb +16 -0
- data/runtime/spec/opal/opal/null_spec.rb +10 -0
- data/runtime/spec/opal/opal/number_spec.rb +11 -0
- data/runtime/spec/opal/opal/object_spec.rb +16 -0
- data/runtime/spec/opal/opal/string_spec.rb +11 -0
- data/runtime/spec/opal/opal/typeof_spec.rb +9 -0
- data/runtime/spec/opal/opal/undefined_spec.rb +10 -0
- data/runtime/spec/opal/true/case_compare_spec.rb +12 -0
- data/runtime/spec/opal/true/class_spec.rb +10 -0
- data/runtime/spec/spec_helper.rb +25 -0
- data/runtime/stdlib/base64.rb +91 -0
- data/runtime/stdlib/date.rb +4 -0
- data/{stdlib → runtime/stdlib}/dev.rb +0 -0
- data/runtime/stdlib/forwardable.rb +33 -0
- data/runtime/stdlib/optparse.rb +0 -0
- data/runtime/stdlib/pp.rb +6 -0
- data/{stdlib → runtime/stdlib}/racc/parser.rb +0 -0
- data/runtime/stdlib/rbconfig.rb +0 -0
- data/runtime/stdlib/si.rb +17 -0
- data/runtime/stdlib/strscan.rb +53 -0
- data/runtime/stdlib/uri.rb +111 -0
- data/runtime/stdlib/uri/common.rb +1014 -0
- data/runtime/stdlib/uri/ftp.rb +261 -0
- data/runtime/stdlib/uri/generic.rb +1599 -0
- data/runtime/stdlib/uri/http.rb +106 -0
- data/runtime/stdlib/uri/https.rb +22 -0
- data/runtime/stdlib/uri/ldap.rb +260 -0
- data/runtime/stdlib/uri/ldaps.rb +20 -0
- data/runtime/stdlib/uri/mailto.rb +280 -0
- data/spec/builder/build_source_spec.rb +52 -0
- data/spec/builder/fixtures/build_source/adam.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/a.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/spec/builder/fixtures/build_source/beynon.rb +0 -0
- data/spec/builder/fixtures/build_source/charles.js +0 -0
- data/spec/builder/fixtures/build_source/foo/a.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/b.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/x.js +0 -0
- data/spec/builder/fixtures/build_source/foo/y.js +0 -0
- data/spec/builder/output_path_spec.rb +50 -0
- data/spec/grammar/alias_spec.rb +26 -0
- data/spec/grammar/and_spec.rb +13 -0
- data/spec/grammar/array_spec.rb +22 -0
- data/spec/grammar/attrasgn_spec.rb +28 -0
- data/spec/grammar/begin_spec.rb +38 -0
- data/spec/grammar/block_spec.rb +12 -0
- data/spec/grammar/break_spec.rb +17 -0
- data/spec/grammar/call_spec.rb +58 -0
- data/spec/grammar/class_spec.rb +35 -0
- data/spec/grammar/const_spec.rb +13 -0
- data/spec/grammar/cvar_spec.rb +11 -0
- data/spec/grammar/def_spec.rb +60 -0
- data/spec/grammar/false_spec.rb +17 -0
- data/spec/grammar/file_spec.rb +7 -0
- data/spec/grammar/gvar_spec.rb +13 -0
- data/spec/grammar/hash_spec.rb +17 -0
- data/spec/grammar/iasgn_spec.rb +9 -0
- data/spec/grammar/if_spec.rb +26 -0
- data/spec/grammar/iter_spec.rb +59 -0
- data/spec/grammar/ivar_spec.rb +9 -0
- data/spec/grammar/lasgn_spec.rb +8 -0
- data/spec/grammar/line_spec.rb +8 -0
- data/spec/grammar/lvar_spec.rb +38 -0
- data/spec/grammar/module_spec.rb +27 -0
- data/spec/grammar/nil_spec.rb +17 -0
- data/spec/grammar/not_spec.rb +27 -0
- data/spec/grammar/op_asgn1_spec.rb +23 -0
- data/spec/grammar/op_asgn2_spec.rb +23 -0
- data/spec/grammar/or_spec.rb +13 -0
- data/spec/grammar/return_spec.rb +17 -0
- data/spec/grammar/sclass_spec.rb +20 -0
- data/spec/grammar/self_spec.rb +17 -0
- data/spec/grammar/str_spec.rb +96 -0
- data/spec/grammar/super_spec.rb +20 -0
- data/spec/grammar/true_spec.rb +17 -0
- data/spec/grammar/undef_spec.rb +15 -0
- data/spec/grammar/unless_spec.rb +13 -0
- data/spec/grammar/while_spec.rb +15 -0
- data/spec/grammar/xstr_spec.rb +116 -0
- data/spec/grammar/yield_spec.rb +20 -0
- data/spec/spec_helper.rb +9 -0
- metadata +346 -21
- data/lib/opal/bundle.rb +0 -34
- data/lib/opal/lexer.rb +0 -902
- data/lib/opal/nodes.rb +0 -2150
- data/lib/opal/parser.rb +0 -4894
- data/lib/opal/rake/bundle_task.rb +0 -63
- data/opal-parser.js +0 -8343
- data/stdlib/strscan.rb +0 -52
- data/templates/init/Rakefile +0 -7
- data/templates/init/index.html +0 -17
- data/templates/init/lib/__NAME__.rb +0 -2
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
class BuildSourceTest < Opal::Builder
|
4
|
+
attr_reader :files
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@files = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_file(base, source)
|
11
|
+
@files << [base, source]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
build_source_dir = File.expand_path '../fixtures/build_source', __FILE__
|
16
|
+
|
17
|
+
describe "Builder#build_source" do
|
18
|
+
it "should only build ruby sources" do
|
19
|
+
Dir.chdir(build_source_dir) do
|
20
|
+
b = BuildSourceTest.new
|
21
|
+
b.build_source '.', 'foo'
|
22
|
+
|
23
|
+
b.files.size.should == 2
|
24
|
+
b.files.include?(['foo', 'a.rb']).should be_true
|
25
|
+
b.files.include?(['foo', 'b.rb']).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should recursively go into directories to find ruby sources" do
|
30
|
+
Dir.chdir(build_source_dir) do
|
31
|
+
b = BuildSourceTest.new
|
32
|
+
b.build_source '.', 'bar'
|
33
|
+
|
34
|
+
b.files.size.should == 3
|
35
|
+
b.files.include?(['bar', 'a.rb']).should be_true
|
36
|
+
b.files.include?(['bar/wow', 'b.rb']).should be_true
|
37
|
+
b.files.include?(['bar/wow/cow', 'c.rb']).should be_true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to handle top level files" do
|
42
|
+
Dir.chdir(build_source_dir) do
|
43
|
+
b = BuildSourceTest.new
|
44
|
+
b.build_source '.', 'adam.rb'
|
45
|
+
b.files.should == [['.', 'adam.rb']]
|
46
|
+
|
47
|
+
b2 = BuildSourceTest.new
|
48
|
+
b2.build_source '.', 'charles.js'
|
49
|
+
b2.files.should == []
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Builder#output_path" do
|
4
|
+
describe "with an output dir" do
|
5
|
+
it "should return output dir joined with source when base is '.'" do
|
6
|
+
b = Opal::Builder.new '', :out => 'build'
|
7
|
+
|
8
|
+
b.output_path('.', 'foo.rb').should == 'build/foo.js'
|
9
|
+
b.output_path('.', 'bar.rb').should == 'build/bar.js'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the parts joined but with first part of base removed" do
|
13
|
+
b = Opal::Builder.new '', :out => 'build'
|
14
|
+
|
15
|
+
b.output_path('lib', 'foo.rb').should == 'build/foo.js'
|
16
|
+
b.output_path('lib/foo', 'bar.rb').should == 'build/foo/bar.js'
|
17
|
+
b.output_path('lib/foo/bar', 'baz.rb').should == 'build/foo/bar/baz.js'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "without an output dir" do
|
22
|
+
it "should return base and source joined with .js extname" do
|
23
|
+
b = Opal::Builder.new '', :out => ''
|
24
|
+
b.output_path('.', 'foo.rb').should == 'foo.js'
|
25
|
+
b.output_path('lib', 'foo.rb').should == 'lib/foo.js'
|
26
|
+
b.output_path('lib/foo', 'bar.rb').should == 'lib/foo/bar.js'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "supports '.' as output dir" do
|
30
|
+
b = Opal::Builder.new '', :out => '.'
|
31
|
+
b.output_path('.', 'foo.rb').should == 'foo.js'
|
32
|
+
b.output_path('lib', 'foo.rb').should == 'lib/foo.js'
|
33
|
+
b.output_path('lib/foo', 'bar.rb').should == 'lib/foo/bar.js'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "supports nil as output dir" do
|
37
|
+
b = Opal::Builder.new '', :out => nil
|
38
|
+
b.output_path('.', 'foo.rb').should == 'foo.js'
|
39
|
+
b.output_path('lib', 'foo.rb').should == 'lib/foo.js'
|
40
|
+
b.output_path('lib/foo', 'bar.rb').should == 'lib/foo/bar.js'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "supports false as output dir" do
|
44
|
+
b = Opal::Builder.new '', :out => false
|
45
|
+
b.output_path('.', 'foo.rb').should == 'foo.js'
|
46
|
+
b.output_path('lib', 'foo.rb').should == 'lib/foo.js'
|
47
|
+
b.output_path('lib/foo', 'bar.rb').should == 'lib/foo/bar.js'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "The alias keyword" do
|
4
|
+
describe "with fitem" do
|
5
|
+
it "should return an s(:alias) with s(:lit)" do
|
6
|
+
opal_parse("alias a b").should == [:alias, [:lit, :a], [:lit, :b]]
|
7
|
+
opal_parse("alias == equals").should == [:alias, [:lit, :==], [:lit, :equals]]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should accept symbols as names" do
|
11
|
+
opal_parse("alias :foo :bar").should == [:alias, [:lit, :foo], [:lit, :bar]]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "with gvar" do
|
16
|
+
it "should return a s(:valias) with two gvars as arguments" do
|
17
|
+
opal_parse("alias $foo $bar").should == [:valias, :$foo, :$bar]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "with gvar and nth ref" do
|
22
|
+
it "should return a s(:valias) with two values as arguments" do
|
23
|
+
opal_parse("alias $foo $1").should == [:valias, :$foo, :"$1"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "The and statement" do
|
4
|
+
it "should always return s(:and)" do
|
5
|
+
opal_parse("1 and 2").should == [:and, [:lit, 1], [:lit, 2]]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "The && expression" do
|
10
|
+
it "should always return s(:and)" do
|
11
|
+
opal_parse("1 && 2").should == [:and, [:lit, 1], [:lit, 2]]
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Arrays" do
|
4
|
+
it "should parse empty arrays as s(:array)" do
|
5
|
+
opal_parse("[]").should == [:array]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should append regular args onto end of array sexp" do
|
9
|
+
opal_parse("[1]").should == [:array, [:lit, 1]]
|
10
|
+
opal_parse("[1, 2]").should == [:array, [:lit, 1], [:lit, 2]]
|
11
|
+
opal_parse("[1, 2, 3]").should == [:array, [:lit, 1], [:lit, 2], [:lit, 3]]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return a single item s(:array) with given splat if no norm args" do
|
15
|
+
opal_parse("[*1]").should == [:array, [:splat, [:lit, 1]]]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should allow splats combined with any number of norm args" do
|
19
|
+
opal_parse("[1, *2]").should == [:array, [:lit, 1], [:splat, [:lit, 2]]]
|
20
|
+
opal_parse("[1, 2, *3]").should == [:array, [:lit, 1], [:lit, 2], [:splat, [:lit, 3]]]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Attribute assignments" do
|
4
|
+
it "should return a s(:attrasgn) for simple assignments" do
|
5
|
+
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:lit, 1]]]
|
6
|
+
opal_parse('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:lit, 1]]]
|
7
|
+
opal_parse('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:lit, 1]]]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "accepts both '.' and '::' for method call operators" do
|
11
|
+
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:lit, 1]]]
|
12
|
+
opal_parse('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:lit, 1]]]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can accept a constant as assignable name when using '.'" do
|
16
|
+
opal_parse('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:lit, 1]]]
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "when setting element reference" do
|
20
|
+
it "uses []= as the method call" do
|
21
|
+
opal_parse('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:lit, 1], [:lit, 2]]]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "supports multiple arguments inside brackets" do
|
25
|
+
opal_parse('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:lit, 1], [:lit, 2], [:lit, 3]]]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "The begin keyword" do
|
4
|
+
it "should be removed when used without a resuce or enusre body" do
|
5
|
+
opal_parse('begin; 1; end').should == [:lit, 1]
|
6
|
+
opal_parse('begin; 1; 2; end').should == [:block, [:lit, 1], [:lit, 2]]
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with 'rescue' bodies" do
|
10
|
+
it "should create a s(:rescue) sexp" do
|
11
|
+
opal_parse('begin; 1; rescue; 2; end').should == [:rescue, [:lit, 1], [:resbody, [:array], [:lit, 2]]]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "allows multiple rescue bodies" do
|
15
|
+
opal_parse('begin 1; rescue; 2; rescue; 3; end').should == [:rescue, [:lit, 1], [:resbody, [:array], [:lit, 2]], [:resbody, [:array], [:lit, 3]]]
|
16
|
+
end
|
17
|
+
|
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, [:lit, 1], [:resbody, [:array, [:const, :Klass]], [:lit, 2]]]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "accepts an identifier to assign exception to" do
|
23
|
+
opal_parse('begin 1; rescue => a; 2; end').should == [:rescue, [:lit, 1], [:resbody, [:array, [:lasgn, :a, [:gvar, :$!]]], [:lit, 2]]]
|
24
|
+
opal_parse('begin 1; rescue Klass => a; 2; end').should == [:rescue, [:lit, 1], [:resbody, [:array, [:const, :Klass],[:lasgn, :a, [:gvar, :$!]]], [:lit, 2]]]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "accepts an ivar to assign exception to" do
|
28
|
+
opal_parse('begin 1; rescue => @a; 2; end').should == [:rescue, [:lit, 1], [:resbody, [:array, [:iasgn, :@a, [:gvar, :$!]]], [:lit, 2]]]
|
29
|
+
opal_parse('begin 1; rescue Klass => @a; 2; end').should == [:rescue, [:lit, 1], [:resbody, [:array, [:const, :Klass],[:iasgn, :@a, [:gvar, :$!]]], [:lit, 2]]]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "with an 'ensure' block" do
|
34
|
+
it "should propagate into single s(:ensure) statement when no rescue block given" do
|
35
|
+
opal_parse('begin; 1; ensure; 2; end').should == [:ensure, [:lit, 1], [:lit, 2]]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Block statements" do
|
4
|
+
it "should return the direct expression if only one expresssion in block" do
|
5
|
+
opal_parse("42").should == [:lit, 42]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return an s(:block) with all expressions appended for > 1 expression" do
|
9
|
+
opal_parse("42; 43").should == [:block, [:lit, 42], [:lit, 43]]
|
10
|
+
opal_parse("42; 43\n44").should == [:block, [:lit, 42], [:lit, 43], [:lit, 44]]
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "The break keyword" do
|
4
|
+
it "should return s(:break) when given no args" do
|
5
|
+
opal_parse("break").should == [:break]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns s(:break) with a single arg not wrapped in s(:array)" do
|
9
|
+
opal_parse("break 1").should == [:break, [:lit, 1]]
|
10
|
+
opal_parse("break *1").should == [:break, [:splat, [:lit, 1]]]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns s(:break) with an s(:array) for args size > 1" do
|
14
|
+
opal_parse("break 1, 2").should == [:break, [:array, [:lit, 1], [:lit, 2]]]
|
15
|
+
opal_parse("break 1, *2").should == [:break, [:array, [:lit, 1], [:splat, [:lit, 2]]]]
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Method calls" do
|
4
|
+
it "should use 'nil' for calls without a receiver" do
|
5
|
+
opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
|
6
|
+
opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should always have an arglist when not passed any arguments" do
|
10
|
+
opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
|
11
|
+
opal_parse("self.foo").should == [:call, [:self], :foo, [:arglist]]
|
12
|
+
opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
|
13
|
+
opal_parse("self.foo()").should == [:call, [:self], :foo, [:arglist]]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "appends all arguments onto arglist" do
|
17
|
+
opal_parse("foo 1").should == [:call, nil, :foo, [:arglist, [:lit, 1]]]
|
18
|
+
opal_parse("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:lit, 1], [:lit, 2]]]
|
19
|
+
opal_parse("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:lit, 1], [:splat, [:lit, 2]]]]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Operator calls" do
|
24
|
+
it "should become regular calls with operator as method" do
|
25
|
+
opal_parse("1 + 2").should == [:call, [:lit, 1], :+, [:arglist, [:lit, 2]]]
|
26
|
+
opal_parse("1 - 2").should == [:call, [:lit, 1], :-, [:arglist, [:lit, 2]]]
|
27
|
+
opal_parse("1 / 2").should == [:call, [:lit, 1], :/, [:arglist, [:lit, 2]]]
|
28
|
+
opal_parse("1 * 2").should == [:call, [:lit, 1], :*, [:arglist, [:lit, 2]]]
|
29
|
+
opal_parse("1 % 2").should == [:call, [:lit, 1], :%, [:arglist, [:lit, 2]]]
|
30
|
+
opal_parse("1 ** 2").should == [:call, [:lit, 1], :**, [:arglist, [:lit, 2]]]
|
31
|
+
|
32
|
+
opal_parse("+self").should == [:call, [:self], :+@, [:arglist]]
|
33
|
+
opal_parse("-self").should == [:call, [:self], :-@, [:arglist]]
|
34
|
+
|
35
|
+
opal_parse("1 | 2").should == [:call, [:lit, 1], :|, [:arglist, [:lit, 2]]]
|
36
|
+
opal_parse("1 ^ 2").should == [:call, [:lit, 1], :^, [:arglist, [:lit, 2]]]
|
37
|
+
opal_parse("1 & 2").should == [:call, [:lit, 1], :&, [:arglist, [:lit, 2]]]
|
38
|
+
opal_parse("1 <=> 2").should == [:call, [:lit, 1], :<=>, [:arglist, [:lit, 2]]]
|
39
|
+
|
40
|
+
opal_parse("1 < 2").should == [:call, [:lit, 1], :<, [:arglist, [:lit, 2]]]
|
41
|
+
opal_parse("1 <= 2").should == [:call, [:lit, 1], :<=, [:arglist, [:lit, 2]]]
|
42
|
+
opal_parse("1 > 2").should == [:call, [:lit, 1], :>, [:arglist, [:lit, 2]]]
|
43
|
+
opal_parse("1 >= 2").should == [:call, [:lit, 1], :>=, [:arglist, [:lit, 2]]]
|
44
|
+
|
45
|
+
opal_parse("1 == 2").should == [:call, [:lit, 1], :==, [:arglist, [:lit, 2]]]
|
46
|
+
opal_parse("1 === 2").should == [:call, [:lit, 1], :===, [:arglist, [:lit, 2]]]
|
47
|
+
opal_parse("1 =~ 2").should == [:call, [:lit, 1], :=~, [:arglist, [:lit, 2]]]
|
48
|
+
|
49
|
+
opal_parse("~1").should == [:call, [:lit, 1], :~, [:arglist]]
|
50
|
+
opal_parse("1 << 2").should == [:call, [:lit, 1], :<<, [:arglist, [:lit, 2]]]
|
51
|
+
opal_parse("1 >> 2").should == [:call, [:lit, 1], :>>, [:arglist, [:lit, 2]]]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "optimizes +@ and -@ on numerics" do
|
55
|
+
opal_parse("+1").should == [:lit, 1]
|
56
|
+
opal_parse("-1").should == [:lit, -1]
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "The class keyword" do
|
4
|
+
it "returns a plain s(:scope) when given an empty body" do
|
5
|
+
opal_parse('class A; end').should == [:class, :A, nil, [:scope]]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "does not place single expressions into a s(:block)" do
|
9
|
+
opal_parse('class A; 1; end').should == [:class, :A, nil, [:scope, [:lit, 1]]]
|
10
|
+
end
|
11
|
+
|
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, [:lit, 1], [:lit, 2]]]]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "uses nil as a placeholder when no superclass is given" do
|
17
|
+
opal_parse('class A; end')[2].should == nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "reflects the given superclass" do
|
21
|
+
opal_parse('class A < B; end')[2].should == [:const, :B]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should accept just a constant for the class name" do
|
25
|
+
opal_parse('class A; end')[1].should == :A
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept a prefix constant for the class name" do
|
29
|
+
opal_parse('class ::A; end')[1].should == [:colon3, :A]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should accept a nested constant for the class name" do
|
33
|
+
opal_parse('class A::B; end')[1].should == [:colon2, [:const, :A], :B]
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Constants" do
|
4
|
+
it "should always become a s(:const)" do
|
5
|
+
opal_parse("FOO").should == [:const, :FOO]
|
6
|
+
opal_parse("BAR").should == [:const, :BAR]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be returned as s(:cdecl) on assignment" do
|
10
|
+
opal_parse("FOO = 1").should == [:cdecl, :FOO, [:lit, 1]]
|
11
|
+
opal_parse("FOO = BAR").should == [:cdecl, :FOO, [:const, :BAR]]
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Class variables" do
|
4
|
+
it "should always be returned as s(:cvar)" do
|
5
|
+
opal_parse("@@foo").should == [:cvar, :@@foo]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should always be converted to s(:cvdecl) on assignment" do
|
9
|
+
opal_parse("@@foo = 100").should == [:cvdecl, :@@foo, [:lit, 100]]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "The def keyword" do
|
4
|
+
describe "for normal definitions" do
|
5
|
+
it "should return s(:defn)" do
|
6
|
+
opal_parse("def a; end").should == [:defn, :a, [:args], [:scope, [:block, [:nil]]]]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "adds s(:nil) on an empty body" do
|
10
|
+
opal_parse("def foo; end").last.should == [:scope, [:block, [:nil]]]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "for singleton definitions" do
|
15
|
+
it "should return s(:defs)" do
|
16
|
+
opal_parse("def self.a; end").should == [:defs, [:self], :a, [:args], [:scope, [:block]]]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not add s(:nil) on an empty body" do
|
20
|
+
opal_parse("def self.foo; end").last.should == [:scope, [:block]]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "with normal args" do
|
25
|
+
it "should list all args" do
|
26
|
+
opal_parse("def foo(a); end")[2].should == [:args, :a]
|
27
|
+
opal_parse("def foo(a, b); end")[2].should == [:args, :a, :b]
|
28
|
+
opal_parse("def foo(a, b, c); end")[2].should == [:args, :a, :b, :c]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "with opt args" do
|
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, [:lit, 1]]]]
|
35
|
+
opal_parse("def foo(a = 1, b = 2); end")[2].should == [:args, :a, :b, [:block, [:lasgn, :a, [:lit, 1]], [:lasgn, :b, [:lit, 2]]]]
|
36
|
+
end
|
37
|
+
|
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, [:lit, 1]]]]
|
40
|
+
opal_parse("def foo(b = 1, *c); end")[2].should == [:args, :b, :"*c", [:block, [:lasgn, :b, [:lit, 1]]]]
|
41
|
+
opal_parse("def foo(b = 1, &block); end")[2].should == [:args, :b, :"&block", [:block, [:lasgn, :b, [:lit, 1]]]]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "with rest args" do
|
46
|
+
it "should list rest args in place as a symbol with '*' prefix" do
|
47
|
+
opal_parse("def foo(*a); end")[2].should == [:args, :"*a"]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "uses '*' as an arg name for rest args without a name" do
|
51
|
+
opal_parse("def foo(*); end")[2].should == [:args, :"*"]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "with block arg" do
|
56
|
+
it "should list block argument with the '&' prefix" do
|
57
|
+
opal_parse("def foo(&a); end")[2].should == [:args, :"&a"]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|