opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
data/spec/opal/erb/erb_spec.rb
CHANGED
@@ -2,15 +2,17 @@ require 'erb'
|
|
2
2
|
|
3
3
|
require File.expand_path('../simple', __FILE__)
|
4
4
|
require File.expand_path('../quoted', __FILE__)
|
5
|
+
require File.expand_path('../inline_block', __FILE__)
|
5
6
|
|
6
7
|
describe "ERB files" do
|
7
8
|
before :each do
|
8
9
|
@simple = Template['opal/erb/simple']
|
9
10
|
@quoted = Template['opal/erb/quoted']
|
11
|
+
@inline_block = Template['opal/erb/inline_block']
|
10
12
|
end
|
11
13
|
|
12
14
|
it "should be defined by their filename on Template namespace" do
|
13
|
-
@simple.should be_kind_of(
|
15
|
+
@simple.should be_kind_of(Template)
|
14
16
|
end
|
15
17
|
|
16
18
|
it "calling the block with a context should render the block" do
|
@@ -22,4 +24,8 @@ describe "ERB files" do
|
|
22
24
|
@name = "adam"
|
23
25
|
@quoted.render(self).should == "<div class=\"foo\">hello there adam</div>\n"
|
24
26
|
end
|
27
|
+
|
28
|
+
it "should be able to handle inline blocks" do
|
29
|
+
@inline_block.should be_kind_of(Template)
|
30
|
+
end
|
25
31
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Hash.allocate" do
|
4
|
+
before { @subclass = Class.new(Hash) }
|
5
|
+
|
6
|
+
it "returns an instance of Hash or subclass" do
|
7
|
+
Hash.allocate.should be_kind_of Hash
|
8
|
+
@subclass.allocate.should be_kind_of @subclass
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return a Hash ready to be used" do
|
12
|
+
h = @subclass.allocate
|
13
|
+
h[:foo] = 100
|
14
|
+
h[:foo].should == 100
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Kernel#instance_variable_defined?" do
|
4
|
+
before do
|
5
|
+
@foo = :bar
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns true if ivar is defined" do
|
9
|
+
instance_variable_defined?(:@foo).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns false if ivar is not defined" do
|
13
|
+
instance_variable_defined?(:@this_does_not_exist).should be_false
|
14
|
+
end
|
15
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
describe "Kernel.rand" do
|
2
|
-
|
2
|
+
it "returns a float if no argument is passed" do
|
3
3
|
rand.should be_kind_of(Float)
|
4
4
|
end
|
5
5
|
|
6
|
-
|
6
|
+
it "returns an integer for an integer argument" do
|
7
7
|
rand(77).should be_kind_of(Integer)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "return member from range" do
|
10
|
+
it "return member from range" do
|
11
11
|
r = (1..10)
|
12
12
|
r.to_a.include?(rand(r)).should == true
|
13
13
|
end
|
14
14
|
|
15
|
-
it "should convert negative number and convert to integer" do
|
15
|
+
it "should convert negative number and convert to integer" do
|
16
16
|
rand(-0.1).should == 0
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "returns a numeric in opal" do
|
20
20
|
rand.should be_kind_of(Numeric)
|
21
21
|
rand(77).should be_kind_of(Numeric)
|
@@ -8,6 +8,10 @@ class RespondToSpecs
|
|
8
8
|
end
|
9
9
|
|
10
10
|
undef undefed_method
|
11
|
+
|
12
|
+
def some_method
|
13
|
+
:foo
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
describe "Kernel.respond_to?" do
|
@@ -22,7 +26,16 @@ describe "Kernel#respond_to?" do
|
|
22
26
|
@a = RespondToSpecs.new
|
23
27
|
end
|
24
28
|
|
29
|
+
it "returns true if a method exists" do
|
30
|
+
@a.respond_to?(:some_method).should be_true
|
31
|
+
end
|
32
|
+
|
25
33
|
it "indicates if an object responds to a message" do
|
26
34
|
@a.respond_to?(:undefed_method).should be_false
|
27
35
|
end
|
28
|
-
|
36
|
+
|
37
|
+
it "returns false if a method exists, but is marked with a 'rb_stub' property" do
|
38
|
+
`#{@a}.$some_method.rb_stub = true`
|
39
|
+
@a.respond_to?(:some_method).should be_false
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Blocks" do
|
4
|
+
it "accept default arguments" do
|
5
|
+
proc { |a, b = 100| [a, b] }.call(:foo, :bar).should == [:foo, :bar]
|
6
|
+
proc { |a, b = 100| [a, b] }.call(:foo).should == [:foo, 100]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "the block variable can be optionally overwritten without destroying original block reference" do
|
10
|
+
klass = Class.new { def foo(&block); block = 100 if false; block; end }
|
11
|
+
klass.new.foo {}.should be_kind_of(Proc)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class RescueReturningSpec
|
4
|
+
def single
|
5
|
+
begin
|
6
|
+
raise "ERROR"
|
7
|
+
rescue
|
8
|
+
:foo
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def multiple
|
13
|
+
begin
|
14
|
+
raise "ERROR"
|
15
|
+
rescue
|
16
|
+
to_s
|
17
|
+
:bar
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "The rescue keyword" do
|
23
|
+
it "returns last value of expression evaluated" do
|
24
|
+
RescueReturningSpec.new.single.should == :foo
|
25
|
+
RescueReturningSpec.new.multiple.should == :bar
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class OpalReturnSpec
|
4
|
+
def returning_expression
|
5
|
+
(false || return)
|
6
|
+
end
|
7
|
+
|
8
|
+
def returning_block
|
9
|
+
@values = []
|
10
|
+
|
11
|
+
[1, 2, 3, 4, 5].each do |n|
|
12
|
+
return if n == 3
|
13
|
+
@values << n
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :values
|
18
|
+
|
19
|
+
def returning_block_value
|
20
|
+
[1, 2, 3, 4, 5].each { return :foo }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "The return statement" do
|
25
|
+
it "can be used as an expression" do
|
26
|
+
OpalReturnSpec.new.returning_expression.should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can return from a method when inside a block" do
|
30
|
+
spec = OpalReturnSpec.new
|
31
|
+
spec.returning_block
|
32
|
+
spec.values.size.should == 2
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns the return value from a method returning by block" do
|
36
|
+
OpalReturnSpec.new.returning_block_value.should == :foo
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SingletonClassConstantsSpec
|
4
|
+
class << self
|
5
|
+
$singleton_class_constant_spec = String
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Singleton Classes" do
|
10
|
+
it "looks up constants in body" do
|
11
|
+
$singleton_class_constant_spec.should == String
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SingletonMethodSuperSpec
|
4
|
+
def meth
|
5
|
+
"bar"
|
6
|
+
end
|
7
|
+
|
8
|
+
def passing_block(*args, &block)
|
9
|
+
[args, block_given?]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.pass_block(&block)
|
13
|
+
block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def super_args(*a)
|
17
|
+
block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.super_args(*a)
|
21
|
+
block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
class A < SingletonMethodSuperSpec
|
25
|
+
def passing_block(*a)
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.pass_block
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def super_args(*a)
|
34
|
+
super(*a)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.super_args(*a)
|
38
|
+
super()
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class MultipleSuperSpec
|
44
|
+
def to_s
|
45
|
+
if true
|
46
|
+
super
|
47
|
+
else
|
48
|
+
super()
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# FIXME: we cant make a better test case than this??? For some reason, a single test cannot be deduced
|
54
|
+
describe "The 'super' keyword" do
|
55
|
+
it "passes the right arguments when a variable rewrites special `arguments` js object" do
|
56
|
+
Struct.new(:a, :b, :c).new(1, 2, 3).b.should == 2
|
57
|
+
end
|
58
|
+
|
59
|
+
it "calls super method on object that defines singleton method calling super" do
|
60
|
+
obj = SingletonMethodSuperSpec.new
|
61
|
+
def obj.meth; "foo " + super; end
|
62
|
+
obj.meth.should == "foo bar"
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "with no arguments or parens" do
|
66
|
+
before do
|
67
|
+
@obj = SingletonMethodSuperSpec::A.new
|
68
|
+
@kls = SingletonMethodSuperSpec::A
|
69
|
+
end
|
70
|
+
|
71
|
+
it "passes the block to super" do
|
72
|
+
@obj.passing_block(1, 2, 3).should == [[1, 2, 3], false]
|
73
|
+
@obj.passing_block(1, 2, 3) { }.should == [[1, 2, 3], true]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "passes the block to super on singleton methods" do
|
77
|
+
@kls.pass_block.should be_false
|
78
|
+
@kls.pass_block { }.should be_true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "with arguments or empty parens" do
|
83
|
+
before do
|
84
|
+
@obj = SingletonMethodSuperSpec::A.new
|
85
|
+
@kls = SingletonMethodSuperSpec::A
|
86
|
+
end
|
87
|
+
|
88
|
+
it "does not pass the block to super" do
|
89
|
+
@obj.super_args(1, 2, 3) { }.should be_false
|
90
|
+
@kls.super_args() { }.should be_false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "inside a class body" do
|
95
|
+
it "does not break when multiple super statements are in body" do
|
96
|
+
lambda { MultipleSuperSpec.new.to_s }.should_not raise_error
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Mass assignment" do
|
4
|
+
it "supports setting attributes on lhs" do
|
5
|
+
object = Class.new { attr_accessor :foo, :bar }.new
|
6
|
+
|
7
|
+
object.foo, object.bar = 100, 200
|
8
|
+
|
9
|
+
object.foo.should == 100
|
10
|
+
object.bar.should == 200
|
11
|
+
end
|
12
|
+
|
13
|
+
it "supports setting []= on lhs" do
|
14
|
+
hash = {}
|
15
|
+
hash[:foo], hash[:bar] = 3.142, 42
|
16
|
+
|
17
|
+
hash[:foo].should == 3.142
|
18
|
+
hash[:bar].should == 42
|
19
|
+
end
|
20
|
+
end
|
@@ -34,7 +34,7 @@ describe "Module#constants" do
|
|
34
34
|
result.size.should == 1
|
35
35
|
result.should include("FOO")
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should only return constants defined directly on class" do
|
39
39
|
result = ConstantsSpecsClass.constants
|
40
40
|
result.size.should == 3
|
@@ -44,6 +44,6 @@ describe "Module#constants" do
|
|
44
44
|
it "should include constants inherited from superclass" do
|
45
45
|
result = SubConstantsSpecsClass.constants
|
46
46
|
result.size.should == 4
|
47
|
-
result.should include("
|
47
|
+
result.should include("CLASS_CONST4", "CLASS_CONST1", "CLASS_CONST2", "CLASS_CONST3")
|
48
48
|
end
|
49
49
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe "Native::Base.alias_native" do
|
2
|
+
it "refers to an attribute on @native" do
|
3
|
+
Class.new {
|
4
|
+
include Native::Base
|
5
|
+
|
6
|
+
alias_native :a, :a
|
7
|
+
}.new(`{ a: 2 }`).a.should == 2
|
8
|
+
end
|
9
|
+
|
10
|
+
it "refers to an attribute on @native and calls it if it's a function" do
|
11
|
+
Class.new {
|
12
|
+
include Native::Base
|
13
|
+
|
14
|
+
alias_native :a, :a
|
15
|
+
}.new(`{ a: function() { return 42; } }`).a.should == 42
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe "Native#each" do
|
2
|
+
it "enumerates on object properties" do
|
3
|
+
Native(`{ a: 2, b: 3 }`).each {|name, value|
|
4
|
+
((name == :a && value == 2) || (name == :b && value == 3)).should be_true
|
5
|
+
}
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns an enumerator when no block is given" do
|
9
|
+
enum = Native(`{ a: 2, b: 3 }`).each
|
10
|
+
|
11
|
+
enum.should be_kind_of Enumerator
|
12
|
+
enum.to_a.should == [[:a, 2], [:b, 3]]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe "Native#[]" do
|
2
|
+
it "should return the same value for bridged classes" do
|
3
|
+
Native(`2`).should === 2
|
4
|
+
Native(`"lol"`).should === "lol"
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should return functions as is" do
|
8
|
+
Native(`{ a: function(){} }`)[:a].should be_kind_of Proc
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should wrap natives into a Native object" do
|
12
|
+
Native(`{ a: { b: 2 } }`)[:a][:b].should == 2
|
13
|
+
end
|
14
|
+
end
|