opal 0.3.11 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.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,17 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The false keyword" do
|
|
4
|
+
it "should always return s(:false)" do
|
|
5
|
+
opal_parse("false").should == [:false]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "cannot be assigned to" do
|
|
9
|
+
lambda {
|
|
10
|
+
opal_parse "true = 1"
|
|
11
|
+
}.should raise_error(Exception)
|
|
12
|
+
|
|
13
|
+
lambda {
|
|
14
|
+
opal_parse "true = true"
|
|
15
|
+
}.should raise_error(Exception)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Global variables" do
|
|
4
|
+
it "should be returned as s(:gvar)" do
|
|
5
|
+
opal_parse("$foo").should == [:gvar, :$foo]
|
|
6
|
+
opal_parse("$:").should == [:gvar, :$:]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should return s(:gasgn) on assignment" do
|
|
10
|
+
opal_parse("$foo = 1").should == [:gasgn, :$foo, [:lit, 1]]
|
|
11
|
+
opal_parse("$: = 1").should == [:gasgn, :$:, [:lit, 1]]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Hash literals" do
|
|
4
|
+
it "without any assocs should return an empty hash sexp" do
|
|
5
|
+
opal_parse("{}").should == [:hash]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "adds each assoc pair as individual args onto sexp" do
|
|
9
|
+
opal_parse("{1 => 2}").should == [:hash, [:lit, 1], [:lit, 2]]
|
|
10
|
+
opal_parse("{1 => 2, 3 => 4}").should == [:hash, [:lit, 1], [:lit, 2], [:lit, 3], [:lit, 4]]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "supports 1.9 style hash keys" do
|
|
14
|
+
opal_parse("{ a: 1 }").should == [:hash, [:lit, :a], [:lit, 1]]
|
|
15
|
+
opal_parse("{ a: 1, b: 2 }").should == [:hash, [:lit, :a], [:lit, 1], [:lit, :b], [:lit, 2]]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Instance variable assignment" do
|
|
4
|
+
it "always returns an s(:iasgn)" do
|
|
5
|
+
opal_parse("@a = 1").should == [:iasgn, :@a, [:lit, 1]]
|
|
6
|
+
opal_parse("@A = 1").should == [:iasgn, :@A, [:lit, 1]]
|
|
7
|
+
opal_parse("@class = 1").should == [:iasgn, :@class, [:lit, 1]]
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The if keyword" do
|
|
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, [:lit, 1], [:lit, 2], [:lit, 3]]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "uses nil as fasly body if not given else-then" do
|
|
9
|
+
opal_parse("if 1; 2; end").should == [:if, [:lit, 1], [:lit, 2], nil]
|
|
10
|
+
end
|
|
11
|
+
|
|
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, [:lit, 1], [:lit, 2], [:if, [:lit, 3], [:lit, 4], [:lit, 5]]]
|
|
14
|
+
opal_parse("if 1; 2; elsif 3; 4; end").should == [:if, [:lit, 1], [:lit, 2], [:if, [:lit, 3], [:lit, 4], nil]]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "returns a simple s(:if) with nil else body for prefix if statement" do
|
|
18
|
+
opal_parse("1 if 2").should == [:if, [:lit, 2], [:lit, 1], nil]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "The ternary operator" do
|
|
23
|
+
it "gets converted into an if statement with true and false parts" do
|
|
24
|
+
opal_parse("1 ? 2 : 3").should == [:if, [:lit, 1], [:lit, 2], [:lit, 3]]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Iters" do
|
|
4
|
+
describe "Iter on a command" do
|
|
5
|
+
it "the outer command call gets the iter" do
|
|
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, [:lit, 1], [:call, nil, :b, [:arglist]]]], nil]
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "with no args" do
|
|
12
|
+
it "has 'nil' as the args part of sexp" do
|
|
13
|
+
opal_parse("proc do; end")[2].should == nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "with empty || args" do
|
|
18
|
+
it "should have args set to 0" do
|
|
19
|
+
opal_parse("proc do ||; end")[2].should == 0
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "with normal args" do
|
|
24
|
+
it "adds a single s(:lasgn) for 1 norm arg" do
|
|
25
|
+
opal_parse("proc do |a|; end")[2].should == [:lasgn, :a]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "lists multiple norm args inside a s(:masgn)" do
|
|
29
|
+
opal_parse("proc do |a, b|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b]]]
|
|
30
|
+
opal_parse("proc do |a, b, c|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:lasgn, :c]]]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "with splat arg" do
|
|
35
|
+
it "adds a s(:masgn) for the s(:splat) even if its the only arg" do
|
|
36
|
+
opal_parse("proc do |*a|; end")[2].should == [:masgn, [:array, [:splat, [:lasgn, :a]]]]
|
|
37
|
+
opal_parse("proc do |a, *b|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:splat, [:lasgn, :b]]]]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "with opt args" do
|
|
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, [:lit, 1]]]]]
|
|
44
|
+
opal_parse("proc do |a = 1, b = 2|; end")[2].should == [:masgn, [:array, [:lasgn, :a], [:lasgn, :b], [:block, [:lasgn, :a, [:lit, 1]], [:lasgn, :b, [:lit, 2]]]]]
|
|
45
|
+
end
|
|
46
|
+
|
|
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, [:lit, 1]]]]]
|
|
49
|
+
opal_parse("proc do |b = 1, *c|; end")[2].should == [:masgn, [:array, [:lasgn, :b], [:splat, [:lasgn, :c]], [:block, [:lasgn, :b, [:lit, 1]]]]]
|
|
50
|
+
opal_parse("proc do |b = 1, &c|; end")[2].should == [:masgn, [:array, [:lasgn, :b], [:block_pass, [:lasgn, :c]], [:block, [:lasgn, :b, [:lit, 1]]]]]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe "with block arg" do
|
|
55
|
+
it "should add block arg with s(:block_pass) wrapping s(:lasgn) prefix" do
|
|
56
|
+
opal_parse("proc do |&a|; end")[2].should == [:masgn, [:array, [:block_pass, [:lasgn, :a]]]]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Instance variables" do
|
|
4
|
+
it "always return an s(:ivar)" do
|
|
5
|
+
opal_parse("@a").should == [:ivar, :@a]
|
|
6
|
+
opal_parse("@A").should == [:ivar, :@A]
|
|
7
|
+
opal_parse("@class").should == [:ivar, :@class]
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Local assignment" do
|
|
4
|
+
it "returns an s(:lasgn)" do
|
|
5
|
+
opal_parse("a = 1").should == [:lasgn, :a, [:lit, 1]]
|
|
6
|
+
opal_parse("a = 1; b = 2").should == [:block, [:lasgn, :a, [:lit, 1]], [:lasgn, :b, [:lit, 2]]]
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The __LINE__ keyword" do
|
|
4
|
+
it "should always return a literal number of the current line" do
|
|
5
|
+
opal_parse("__LINE__").should == [:lit, 1]
|
|
6
|
+
opal_parse("\n__LINE__").should == [:lit, 2]
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "An lvar" do
|
|
4
|
+
describe "in any scope" do
|
|
5
|
+
it "should be created when an identifier is previously assigned to" do
|
|
6
|
+
opal_parse("a = 1; a").should == [:block, [:lasgn, :a, [:lit, 1]], [:lvar, :a]]
|
|
7
|
+
opal_parse("a = 1; a; a").should == [:block, [:lasgn, :a, [:lit, 1]], [:lvar, :a], [:lvar, :a]]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should not be created when no lasgn is previously used on name" do
|
|
11
|
+
opal_parse("a").should == [:call, nil, :a, [:arglist]]
|
|
12
|
+
opal_parse("a = 1; b").should == [:block, [:lasgn, :a, [:lit, 1]], [:call, nil, :b, [:arglist]]]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "inside a def" do
|
|
17
|
+
it "should created by a norm arg" do
|
|
18
|
+
opal_parse("def a(b); b; end").should == [:defn, :a, [:args, :b], [:scope, [:block, [:lvar, :b]]]]
|
|
19
|
+
opal_parse("def a(b, c); c; end").should == [:defn, :a, [:args, :b, :c], [:scope, [:block, [:lvar, :c]]]]
|
|
20
|
+
end
|
|
21
|
+
|
|
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, [:lit, 10]]]], [:scope, [:block, [:lvar, :b]]]]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should be created by a rest arg" do
|
|
27
|
+
opal_parse("def a(*b); b; end").should == [:defn, :a, [:args, :"*b"], [:scope, [:block, [:lvar, :b]]]]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should be created by a block arg" do
|
|
31
|
+
opal_parse("def a(&b); b; end").should == [:defn, :a, [:args, :"&b"], [:scope, [:block, [:lvar, :b]]]]
|
|
32
|
+
end
|
|
33
|
+
|
|
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, [:lit, 10]], [:defn, :b, [:args], [:scope, [:block, [:call, nil, :a, [:arglist]]]]]]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The module keyword" do
|
|
4
|
+
it "returns a plain s(:scope) when given an empty body" do
|
|
5
|
+
opal_parse('module A; end').should == [:module, :A, [:scope]]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "does not place single expressions into a s(:block)" do
|
|
9
|
+
opal_parse('module A; 1; end').should == [:module, :A, [:scope, [:lit, 1]]]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "adds multiple body expressions into a s(:block)" do
|
|
13
|
+
opal_parse('module A; 1; 2; end').should == [:module, :A, [:scope, [:block, [:lit, 1], [:lit, 2]]]]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should accept just a constant for the module name" do
|
|
17
|
+
opal_parse('module A; end')[1].should == :A
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should accept a prefix constant for the module name" do
|
|
21
|
+
opal_parse('module ::A; end')[1].should == [:colon3, :A]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should accepts a nested constant for the module name" do
|
|
25
|
+
opal_parse('module A::B; end')[1].should == [:colon2, [:const, :A], :B]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The nil keyword" do
|
|
4
|
+
it "always returns s(:nil)" do
|
|
5
|
+
opal_parse("nil").should == [:nil]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "cannot be assigned to" do
|
|
9
|
+
lambda {
|
|
10
|
+
opal_parse "nil = 1"
|
|
11
|
+
}.should raise_error(Exception)
|
|
12
|
+
|
|
13
|
+
lambda {
|
|
14
|
+
opal_parse "nil = nil"
|
|
15
|
+
}.should raise_error(Exception)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The not keyword" do
|
|
4
|
+
it "returns s(:not) with the single argument" do
|
|
5
|
+
opal_parse("not self").should == [:not, [:self]]
|
|
6
|
+
opal_parse("not 42").should == [:not, [:lit, 42]]
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "The '!' expression" do
|
|
11
|
+
it "returns s(:not) with the single argument" do
|
|
12
|
+
opal_parse("!self").should == [:not, [:self]]
|
|
13
|
+
opal_parse("!42").should == [:not, [:lit, 42]]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "The '!=' expression" do
|
|
18
|
+
it "rewrites as !(lhs == rhs)" do
|
|
19
|
+
opal_parse("1 != 2").should == [:not, [:call, [:lit, 1], :==, [:arglist, [:lit, 2]]]]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "The '!~' expression" do
|
|
24
|
+
it "rewrites as !(lhs =~ rhs)" do
|
|
25
|
+
opal_parse("1 !~ 2").should == [:not, [:call, [:lit, 1], :=~, [:arglist, [:lit, 2]]]]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "op_asgn1" do
|
|
4
|
+
it "returns s(:op_asgn1)" do
|
|
5
|
+
opal_parse('self[:foo] += 1')[0].should == :op_asgn1
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "correctly assigns the receiver" do
|
|
9
|
+
opal_parse("self[:foo] += 1")[1].should == [:self]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "returns an arglist for args inside braces" do
|
|
13
|
+
opal_parse("self[:foo] += 1")[2].should == [:arglist, [:lit, :foo]]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "only uses the operator, not with '=' appended" do
|
|
17
|
+
opal_parse("self[:foo] += 1")[3].should == :+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "uses a simple sexp, not an arglist" do
|
|
21
|
+
opal_parse("self[:foo] += 1")[4].should == [:lit, 1]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "op_asgn2" do
|
|
4
|
+
it "returns s(:op_asgn2)" do
|
|
5
|
+
opal_parse('self.foo += 1')[0].should == :op_asgn2
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "correctly assigns the receiver" do
|
|
9
|
+
opal_parse("self.foo += 1")[1].should == [:self]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "appends '=' onto the identifier in the sexp" do
|
|
13
|
+
opal_parse("self.foo += 1")[2].should == :foo=
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "only uses the operator, not with '=' appended" do
|
|
17
|
+
opal_parse("self.foo += 1")[3].should == :+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "uses a simple sexp, not an arglist" do
|
|
21
|
+
opal_parse("self.foo += 1")[4].should == [:lit, 1]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The or statement" do
|
|
4
|
+
it "should always return s(:or)" do
|
|
5
|
+
opal_parse("1 or 2").should == [:or, [:lit, 1], [:lit, 2]]
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "The || expression" do
|
|
10
|
+
it "should always return s(:or)" do
|
|
11
|
+
opal_parse("1 || 2").should == [:or, [:lit, 1], [:lit, 2]]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The return keyword" do
|
|
4
|
+
it "should return s(:return) when given no arguments" do
|
|
5
|
+
opal_parse("return").should == [:return]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "returns s(:return) with the direct argument when given one argument" do
|
|
9
|
+
opal_parse("return 1").should == [:return, [:lit, 1]]
|
|
10
|
+
opal_parse("return *2").should == [:return, [:splat, [:lit, 2]]]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "returns s(:return) with an s(:array) when args size > 1" do
|
|
14
|
+
opal_parse("return 1, 2").should == [:return, [:array, [:lit, 1], [:lit, 2]]]
|
|
15
|
+
opal_parse("return 1, *2").should == [:return, [:array, [:lit, 1], [:splat, [:lit, 2]]]]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Singleton classes" do
|
|
4
|
+
it "returns an empty s(:scope) when given an empty body" do
|
|
5
|
+
opal_parse('class << A; end')[2].should == [:scope]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "does not place single expressions into an s(:block)" do
|
|
9
|
+
opal_parse('class << A; 1; end')[2].should == [: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')[2].should == [:scope, [:block, [:lit, 1], [:lit, 2]]]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should accept any expressions for singleton part" do
|
|
17
|
+
opal_parse('class << A; end').should == [:sclass, [:const, :A], [:scope]]
|
|
18
|
+
opal_parse('class << self; end').should == [:sclass, [:self], [:scope]]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "The self keyword" do
|
|
4
|
+
it "always returns s(:self)" do
|
|
5
|
+
opal_parse("self").should == [:self]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "cannot be assigned to" do
|
|
9
|
+
lambda {
|
|
10
|
+
opal_parse "self = 1"
|
|
11
|
+
}.should raise_error(Exception)
|
|
12
|
+
|
|
13
|
+
lambda {
|
|
14
|
+
opal_parse "self = self"
|
|
15
|
+
}.should raise_error(Exception)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Strings" do
|
|
4
|
+
it "parses empty strings" do
|
|
5
|
+
opal_parse('""').should == [:str, ""]
|
|
6
|
+
opal_parse("''").should == [:str, ""]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "parses a simple string without interpolation as s(:str)" do
|
|
10
|
+
opal_parse('"foo # { } bar"').should == [:str, "foo # { } bar"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "does not interpolate with single quotes" do
|
|
14
|
+
opal_parse("'\#{foo}'").should == [:str, "\#{foo}"]
|
|
15
|
+
opal_parse("'\#@foo'").should == [:str, "\#@foo"]
|
|
16
|
+
opal_parse("'\#$foo'").should == [:str, "\#$foo"]
|
|
17
|
+
opal_parse("'\#@@foo'").should == [:str, "\#@@foo"]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "supports interpolation with double quotes" do
|
|
21
|
+
opal_parse('"#{foo}"').should == [:dstr, "", [:evstr, [:call, nil, :foo, [:arglist]]]]
|
|
22
|
+
opal_parse('"#@foo"').should == [:dstr, "", [:evstr, [:ivar, :@foo]]]
|
|
23
|
+
opal_parse('"#$foo"').should == [:dstr, "", [:evstr, [:gvar, :$foo]]]
|
|
24
|
+
opal_parse('"#@@foo"').should == [:dstr, "", [:evstr, [:cvar, :@@foo]]]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "allows underscores in ivar, gvar and cvar interpolation" do
|
|
28
|
+
opal_parse('"#@foo_bar"').should == [:dstr, "", [:evstr, [:ivar, :@foo_bar]]]
|
|
29
|
+
opal_parse('"#$foo_bar"').should == [:dstr, "", [:evstr, [:gvar, :$foo_bar]]]
|
|
30
|
+
opal_parse('"#@@foo_bar"').should == [:dstr, "", [:evstr, [:cvar, :@@foo_bar]]]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "from %Q construction" do
|
|
34
|
+
it "can use '[', '(' or '{' matching pairs for string boundry" do
|
|
35
|
+
opal_parse('%Q{foo}').should == [:str, "foo"]
|
|
36
|
+
opal_parse('%Q[foo]').should == [:str, "foo"]
|
|
37
|
+
opal_parse('%Q(foo)').should == [:str, "foo"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "can parse empty strings" do
|
|
41
|
+
opal_parse('%Q{}').should == [:str, ""]
|
|
42
|
+
opal_parse('%Q[]').should == [:str, ""]
|
|
43
|
+
opal_parse('%Q()').should == [:str, ""]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should allow interpolation" do
|
|
47
|
+
opal_parse('%Q(#{foo})').should == [:dstr, "", [:evstr, [:call, nil, :foo, [:arglist]]]]
|
|
48
|
+
opal_parse('%Q[#{foo}]').should == [:dstr, "", [:evstr, [:call, nil, :foo, [:arglist]]]]
|
|
49
|
+
opal_parse('%Q{#{foo}}').should == [:dstr, "", [:evstr, [:call, nil, :foo, [:arglist]]]]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should allow ivar, gvar and cvar interpolation" do
|
|
53
|
+
opal_parse('%Q{#@foo}').should == [:dstr, "", [:evstr, [:ivar, :@foo]]]
|
|
54
|
+
opal_parse('%Q{#$foo}').should == [:dstr, "", [:evstr, [:gvar, :$foo]]]
|
|
55
|
+
opal_parse('%Q{#@@foo}').should == [:dstr, "", [:evstr, [:cvar, :@@foo]]]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should match '{' and '}' pairs used to start string before ending match" do
|
|
59
|
+
opal_parse('%Q{{}}').should == [:str, "{}"]
|
|
60
|
+
opal_parse('%Q{foo{bar}baz}').should == [:str, "foo{bar}baz"]
|
|
61
|
+
opal_parse('%Q{{foo}bar}').should == [:str, "{foo}bar"]
|
|
62
|
+
opal_parse('%Q{foo{bar}}').should == [:str, "foo{bar}"]
|
|
63
|
+
opal_parse('%Q{foo#{bar}baz}').should == [:dstr, "foo", [:evstr, [:call, nil, :bar, [:arglist]]], [:str, "baz"]]
|
|
64
|
+
opal_parse('%Q{a{b{c}d{e}f}g}').should == [:str, "a{b{c}d{e}f}g"]
|
|
65
|
+
opal_parse('%Q{a{b{c}#{foo}d}e}').should == [:dstr, "a{b{c}", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d}e"]]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should match '(' and ')' pairs used to start string before ending match" do
|
|
69
|
+
opal_parse('%Q(())').should == [:str, "()"]
|
|
70
|
+
opal_parse('%Q(foo(bar)baz)').should == [:str, "foo(bar)baz"]
|
|
71
|
+
opal_parse('%Q((foo)bar)').should == [:str, "(foo)bar"]
|
|
72
|
+
opal_parse('%Q(foo(bar))').should == [:str, "foo(bar)"]
|
|
73
|
+
opal_parse('%Q(foo#{bar}baz)').should == [:dstr, "foo", [:evstr, [:call, nil, :bar, [:arglist]]], [:str, "baz"]]
|
|
74
|
+
opal_parse('%Q(a(b(c)d(e)f)g)').should == [:str, "a(b(c)d(e)f)g"]
|
|
75
|
+
opal_parse('%Q(a(b(c)#{foo}d)e)').should == [:dstr, "a(b(c)", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d)e"]]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should match '[' and ']' pairs used to start string before ending match" do
|
|
79
|
+
opal_parse('%Q[[]]').should == [:str, "[]"]
|
|
80
|
+
opal_parse('%Q[foo[bar]baz]').should == [:str, "foo[bar]baz"]
|
|
81
|
+
opal_parse('%Q[[foo]bar]').should == [:str, "[foo]bar"]
|
|
82
|
+
opal_parse('%Q[foo[bar]]').should == [:str, "foo[bar]"]
|
|
83
|
+
opal_parse('%Q[foo#{bar}baz]').should == [:dstr, "foo", [:evstr, [:call, nil, :bar, [:arglist]]], [:str, "baz"]]
|
|
84
|
+
opal_parse('%Q[a[b[c]d[e]f]g]').should == [:str, "a[b[c]d[e]f]g"]
|
|
85
|
+
opal_parse('%Q[a[b[c]#{foo}d]e]').should == [:dstr, "a[b[c]", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d]e"]]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "correctly parses block braces within interpolations" do
|
|
89
|
+
opal_parse('%Q{#{each { nil } }}').should == [:dstr, "", [:evstr, [:iter, [:call, nil, :each, [:arglist]], nil, [:nil]]]]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "parses other Qstrings within interpolations" do
|
|
93
|
+
opal_parse('%Q{#{ %Q{} }}').should == [:dstr, "", [:evstr, [:str, ""]]]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|