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
@@ -1,14 +1,14 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
3
|
describe "``" do
|
4
|
-
|
4
|
+
it "returns the output of the executed sub-process" do
|
5
5
|
ip = 'world'
|
6
6
|
# `echo disc #{ip}`.should == "disc world\n"
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "%x" do
|
11
|
-
|
11
|
+
it "is the same as ``" do
|
12
12
|
ip = 'world'
|
13
13
|
# %x(echo disc #{ip}).should == "disc world\n"
|
14
14
|
end
|
@@ -4,7 +4,7 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
4
4
|
# body
|
5
5
|
# end
|
6
6
|
describe "The for expression" do
|
7
|
-
|
7
|
+
it "iterates over an Enumerable passing each element to the block" do
|
8
8
|
# j = 0
|
9
9
|
# for i in 1..3
|
10
10
|
# j += i
|
@@ -12,7 +12,7 @@ describe "The for expression" do
|
|
12
12
|
# j.should == 6
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
it "iterates over an Hash passing each key-value pair to the block" do
|
16
16
|
# k = 0
|
17
17
|
# l = 0
|
18
18
|
|
@@ -25,7 +25,7 @@ describe "The for expression" do
|
|
25
25
|
# l.should == 30
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
it "iterates over any object responding to 'each'" do
|
29
29
|
# class XYZ
|
30
30
|
# def each
|
31
31
|
# (0..10).each { |i| yield i }
|
@@ -39,7 +39,7 @@ describe "The for expression" do
|
|
39
39
|
# j.should == 55
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
it "allows an instance variable as an iterator name" do
|
43
43
|
# m = [1,2,3]
|
44
44
|
# n = 0
|
45
45
|
# for @var in m
|
@@ -49,7 +49,7 @@ describe "The for expression" do
|
|
49
49
|
# n.should == 3
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
it "allows a class variable as an iterator name" do
|
53
53
|
# class OFor
|
54
54
|
# m = [1,2,3]
|
55
55
|
# n = 0
|
@@ -61,7 +61,7 @@ describe "The for expression" do
|
|
61
61
|
# end
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
it "allows a constant as an iterator name" do
|
65
65
|
# class OFor
|
66
66
|
# m = [1,2,3]
|
67
67
|
# n = 0
|
@@ -95,7 +95,7 @@ describe "The for expression" do
|
|
95
95
|
# 1.9 behaviour verified by nobu in
|
96
96
|
# http://redmine.ruby-lang.org/issues/show/2053
|
97
97
|
ruby_version_is "1.9" do
|
98
|
-
|
98
|
+
it "yields only as many values as there are arguments" do
|
99
99
|
# class OFor
|
100
100
|
# def each
|
101
101
|
# [[1,2,3], [4,5,6]].each do |a|
|
@@ -113,7 +113,7 @@ describe "The for expression" do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
|
116
|
+
it "optionally takes a 'do' after the expression" do
|
117
117
|
# j = 0
|
118
118
|
# for i in 1..3 do
|
119
119
|
# j += i
|
@@ -121,14 +121,14 @@ describe "The for expression" do
|
|
121
121
|
# j.should == 6
|
122
122
|
end
|
123
123
|
|
124
|
-
|
124
|
+
it "allows body begin on the same line if do is used" do
|
125
125
|
# j = 0
|
126
126
|
# for i in 1..3 do j += i
|
127
127
|
# end
|
128
128
|
# j.should == 6
|
129
129
|
end
|
130
130
|
|
131
|
-
|
131
|
+
it "executes code in containing variable scope" do
|
132
132
|
# for i in 1..2
|
133
133
|
# a = 123
|
134
134
|
# end
|
@@ -136,7 +136,7 @@ describe "The for expression" do
|
|
136
136
|
# a.should == 123
|
137
137
|
end
|
138
138
|
|
139
|
-
|
139
|
+
it "executes code in containing variable scope with 'do'" do
|
140
140
|
# for i in 1..2 do
|
141
141
|
# a = 123
|
142
142
|
# end
|
@@ -144,12 +144,12 @@ describe "The for expression" do
|
|
144
144
|
# a.should == 123
|
145
145
|
end
|
146
146
|
|
147
|
-
|
147
|
+
it "returns expr" do
|
148
148
|
# for i in 1..3; end.should == (1..3)
|
149
149
|
# for i,j in { 1 => 10, 2 => 20 }; end.should == { 1 => 10, 2 => 20 }
|
150
150
|
end
|
151
151
|
|
152
|
-
|
152
|
+
it "breaks out of a loop upon 'break', returning nil" do
|
153
153
|
# j = 0
|
154
154
|
# for i in 1..3
|
155
155
|
# j += i
|
@@ -160,13 +160,13 @@ describe "The for expression" do
|
|
160
160
|
# j.should == 3
|
161
161
|
end
|
162
162
|
|
163
|
-
|
163
|
+
it "allows 'break' to have an argument which becomes the value of the for expression" do
|
164
164
|
# for i in 1..3
|
165
165
|
# break 10 if i == 2
|
166
166
|
# end.should == 10
|
167
167
|
end
|
168
168
|
|
169
|
-
|
169
|
+
it "starts the next iteration with 'next'" do
|
170
170
|
# j = 0
|
171
171
|
# for i in 1..5
|
172
172
|
# next if i == 2
|
@@ -177,7 +177,7 @@ describe "The for expression" do
|
|
177
177
|
# j.should == 13
|
178
178
|
end
|
179
179
|
|
180
|
-
|
180
|
+
it "repeats current iteration with 'redo'" do
|
181
181
|
# j = 0
|
182
182
|
# for i in 1..3
|
183
183
|
# j += i
|
@@ -189,4 +189,4 @@ describe "The for expression" do
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
# language_version __FILE__, "for"
|
192
|
+
# language_version __FILE__, "for"
|
@@ -29,7 +29,7 @@ describe "Hash literal" do
|
|
29
29
|
h[:key].should == nil
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "freezes string keys on initialization" do
|
33
33
|
key = "foo"
|
34
34
|
h = {key => "bar"}
|
35
35
|
key.reverse!
|
@@ -50,7 +50,7 @@ describe "Hash literal" do
|
|
50
50
|
h.size.should == 2
|
51
51
|
h.should == {:a => 1, :b => 2}
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "recognizes '=' at the end of the key" do
|
55
55
|
eval("{:a==>1}").should == {:"a=" => 1}
|
56
56
|
eval("{:a= =>1}").should == {:"a=" => 1}
|
@@ -62,4 +62,4 @@ describe "Hash literal" do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
language_version __FILE__, "hash"
|
@@ -222,56 +222,56 @@ describe "The if expression" do
|
|
222
222
|
ScratchPad.clear
|
223
223
|
end
|
224
224
|
|
225
|
-
|
225
|
+
it "mimics an awk conditional with a single-element inclusive-end range" do
|
226
226
|
10.times { |i| ScratchPad << i if (i == 4)..(i == 4) }
|
227
227
|
ScratchPad.recorded.should == [4]
|
228
228
|
end
|
229
229
|
|
230
|
-
|
230
|
+
it "mimics an awk conditional with a many-element inclusive-end range" do
|
231
231
|
10.times { |i| ScratchPad << i if (i == 4)..(i == 7) }
|
232
232
|
ScratchPad.recorded.should == [4, 5, 6, 7]
|
233
233
|
end
|
234
234
|
|
235
|
-
|
235
|
+
it "mimics a sed conditional with a zero-element exclusive-end range" do
|
236
236
|
10.times { |i| ScratchPad << i if (i == 4)...(i == 4) }
|
237
237
|
ScratchPad.recorded.should == [4, 5, 6, 7, 8, 9]
|
238
238
|
end
|
239
239
|
|
240
|
-
|
240
|
+
it "mimics a sed conditional with a many-element exclusive-end range" do
|
241
241
|
10.times { |i| ScratchPad << i if (i == 4)...(i == 5) }
|
242
242
|
ScratchPad.recorded.should == [4, 5]
|
243
243
|
end
|
244
244
|
|
245
|
-
|
245
|
+
it "allows combining two flip-flops" do
|
246
246
|
10.times { |i| ScratchPad << i if (i == 4)...(i == 5) or (i == 7)...(i == 8) }
|
247
247
|
ScratchPad.recorded.should == [4, 5, 7, 8]
|
248
248
|
end
|
249
249
|
|
250
|
-
|
250
|
+
it "evaluates the first conditions lazily with inclusive-end range" do
|
251
251
|
collector = proc { |i| ScratchPad << i }
|
252
252
|
10.times { |i| i if collector[i]...false }
|
253
253
|
ScratchPad.recorded.should == [0]
|
254
254
|
end
|
255
255
|
|
256
|
-
|
256
|
+
it "evaluates the first conditions lazily with exclusive-end range" do
|
257
257
|
collector = proc { |i| ScratchPad << i }
|
258
258
|
10.times { |i| i if collector[i]..false }
|
259
259
|
ScratchPad.recorded.should == [0]
|
260
260
|
end
|
261
261
|
|
262
|
-
|
262
|
+
it "evaluates the second conditions lazily with inclusive-end range" do
|
263
263
|
collector = proc { |i| ScratchPad << i }
|
264
264
|
10.times { |i| i if (i == 4)...collector[i] }
|
265
265
|
ScratchPad.recorded.should == [5]
|
266
266
|
end
|
267
267
|
|
268
|
-
|
268
|
+
it "evaluates the second conditions lazily with exclusive-end range" do
|
269
269
|
collector = proc { |i| ScratchPad << i }
|
270
270
|
10.times { |i| i if (i == 4)..collector[i] }
|
271
271
|
ScratchPad.recorded.should == [4]
|
272
272
|
end
|
273
273
|
|
274
|
-
|
274
|
+
it "scopes state by flip-flop" do
|
275
275
|
store_me = proc { |i| ScratchPad << i if (i == 4)..(i == 7) }
|
276
276
|
store_me[1]
|
277
277
|
store_me[4]
|
@@ -281,7 +281,7 @@ describe "The if expression" do
|
|
281
281
|
ScratchPad.recorded.should == [4, 1, 7]
|
282
282
|
end
|
283
283
|
|
284
|
-
|
284
|
+
it "keeps flip-flops from interfering" do
|
285
285
|
a = proc { |i| ScratchPad << i if (i == 4)..(i == 7) }
|
286
286
|
b = proc { |i| ScratchPad << i if (i == 4)..(i == 7) }
|
287
287
|
6.times(&a)
|
@@ -10,7 +10,7 @@ describe "The loop expression" do
|
|
10
10
|
outer_loop.should == 10
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
it "executes code in its own scope" do
|
14
14
|
loop do
|
15
15
|
inner_loop = 123
|
16
16
|
break
|
@@ -41,7 +41,7 @@ describe "The loop expression" do
|
|
41
41
|
a.should == [1, 2, 4]
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
it "restarts the current iteration with redo" do
|
45
45
|
a = []
|
46
46
|
loop do
|
47
47
|
a << 1
|
@@ -52,7 +52,7 @@ describe "The loop expression" do
|
|
52
52
|
a.should == [1, 1, 2]
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
it "uses a spaghetti nightmare of redo, next and break" do
|
56
56
|
a = []
|
57
57
|
loop do
|
58
58
|
a << 1
|
@@ -15,11 +15,11 @@ describe "self in a metaclass body (class << obj)" do
|
|
15
15
|
class << nil; self; end.should == NilClass
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it "raises a TypeError for numbers" do
|
19
19
|
lambda { class << 1; self; end }.should raise_error(TypeError)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
it "raises a TypeError for symbols" do
|
23
23
|
lambda { class << :symbol; self; end }.should raise_error(TypeError)
|
24
24
|
end
|
25
25
|
|
@@ -38,42 +38,42 @@ describe "A constant on a metaclass" do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
it "can be accessed after the metaclass body is reopened" do
|
42
42
|
class << @object
|
43
43
|
CONST.should == self
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
it "can be accessed via self::CONST" do
|
48
48
|
class << @object
|
49
49
|
self::CONST.should == self
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
it "can be accessed via const_get" do
|
54
54
|
class << @object
|
55
55
|
const_get(:CONST).should == self
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
it "is not defined on the object's class" do
|
60
60
|
@object.class.const_defined?(:CONST).should be_false
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
it "is not defined in the metaclass opener's scope" do
|
64
64
|
class << @object
|
65
65
|
CONST
|
66
66
|
end
|
67
67
|
lambda { CONST }.should raise_error(NameError)
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
it "cannot be accessed via object::CONST" do
|
71
71
|
lambda do
|
72
72
|
@object::CONST
|
73
73
|
end.should raise_error(TypeError)
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
it "raises a NameError for anonymous_module::CONST" do
|
77
77
|
@object = Class.new
|
78
78
|
class << @object
|
79
79
|
CONST = 100
|
@@ -96,17 +96,17 @@ describe "A constant on a metaclass" do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
ruby_version_is "1.9" do
|
99
|
-
|
99
|
+
it "appears in the metaclass constant list" do
|
100
100
|
constants = class << @object; constants; end
|
101
101
|
constants.should include(:CONST)
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
it "does not appear in the object's class constant list" do
|
105
105
|
@object.class.constants.should_not include(:CONST)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
it "is not preserved when the object is duped" do
|
110
110
|
@object = @object.dup
|
111
111
|
|
112
112
|
lambda do
|
@@ -114,7 +114,7 @@ describe "A constant on a metaclass" do
|
|
114
114
|
end.should raise_error(NameError)
|
115
115
|
end
|
116
116
|
|
117
|
-
|
117
|
+
it "is preserved when the object is cloned" do
|
118
118
|
@object = @object.clone
|
119
119
|
|
120
120
|
class << @object
|
@@ -137,7 +137,7 @@ describe "calling methods on the metaclass" do
|
|
137
137
|
b.cheese.should == 'cheshire'
|
138
138
|
end
|
139
139
|
|
140
|
-
|
140
|
+
it "calls a method in deeper chains of metaclasses" do
|
141
141
|
b = MetaClassSpecs::B.new
|
142
142
|
b_meta = MetaClassSpecs.metaclass_of b
|
143
143
|
b_meta_meta = MetaClassSpecs.metaclass_of b_meta
|
@@ -2,28 +2,28 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
2
2
|
require File.expand_path('../fixtures/module', __FILE__)
|
3
3
|
|
4
4
|
describe "The module keyword" do
|
5
|
-
|
5
|
+
it "creates a new module with a non-qualified constant name" do
|
6
6
|
module ModuleSpecsToplevel; end
|
7
7
|
ModuleSpecsToplevel.should be_an_instance_of(Module)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
it "creates a new module with a qualified constant name" do
|
11
11
|
module ModuleSpecs::Nested; end
|
12
12
|
ModuleSpecs::Nested.should be_an_instance_of(Module)
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
it "creates a new module with a variable qualified constant name" do
|
16
16
|
m = Module.new
|
17
17
|
module m::N; end
|
18
18
|
m::N.should be_an_instance_of(Module)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
it "reopens an existing module" do
|
22
22
|
module ModuleSpecs; Reopened = true; end
|
23
23
|
ModuleSpecs::Reopened.should be_true
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it "reopens a module included in Object" do
|
27
27
|
module IncludedModuleSpecs; Reopened = true; end
|
28
28
|
ModuleSpecs::IncludedInObject::IncludedModuleSpecs::Reopened.should be_true
|
29
29
|
end
|
@@ -42,7 +42,7 @@ describe "The module keyword" do
|
|
42
42
|
lambda { module ModuleSpecs::Modules::B; end }.should raise_error(TypeError)
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
it "raises a TypeError if the constant is nil" do
|
46
46
|
lambda { module ModuleSpecs::Modules::C; end }.should raise_error(TypeError)
|
47
47
|
end
|
48
48
|
|
@@ -49,7 +49,7 @@ describe "The next statement from within the block" do
|
|
49
49
|
}.should == :method_return_value
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
it "returns to the currently yielding method in case of chained calls" do
|
53
53
|
class ChainedNextTest
|
54
54
|
def self.meth_with_yield(&b)
|
55
55
|
yield.should == :next_return_value
|
@@ -338,7 +338,7 @@ describe "Assignment via next" do
|
|
338
338
|
end
|
339
339
|
|
340
340
|
ruby_version_is "1.9" do
|
341
|
-
|
341
|
+
it "assigns splatted objects" do
|
342
342
|
def r(val); a = yield(); val.should == a; end
|
343
343
|
r([]){next *nil}
|
344
344
|
r([1]){next *1}
|
@@ -370,7 +370,7 @@ describe "Assignment via next" do
|
|
370
370
|
end
|
371
371
|
|
372
372
|
ruby_version_is "1.9" do
|
373
|
-
|
373
|
+
it "assigns objects to a splatted reference" do
|
374
374
|
def r(val); *a = yield(); val.should == a; end
|
375
375
|
r([nil]){next}
|
376
376
|
r([nil]){next nil}
|
@@ -403,7 +403,7 @@ describe "Assignment via next" do
|
|
403
403
|
end
|
404
404
|
|
405
405
|
ruby_version_is "1.9" do
|
406
|
-
|
406
|
+
it "assigns splatted objects to a splatted reference via a splatted yield" do
|
407
407
|
def r(val); *a = *yield(); val.should == a; end
|
408
408
|
r([]){next *nil}
|
409
409
|
r([1]){next *1}
|
@@ -450,7 +450,7 @@ describe "Assignment via next" do
|
|
450
450
|
end
|
451
451
|
|
452
452
|
ruby_version_is "1.9" do
|
453
|
-
|
453
|
+
it "assigns splatted objects to multiple variables" do
|
454
454
|
def r(val); a,b,*c = *yield(); val.should == [a,b,c]; end
|
455
455
|
r([nil,nil,[]]){next *nil}
|
456
456
|
r([1,nil,[]]){next *1}
|