opal 0.3.41 → 0.3.42
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +14 -1
- data/Gemfile +2 -5
- data/Rakefile +41 -3
- data/bin/opal +33 -0
- data/lib/opal.rb +2 -12
- data/lib/opal/core_ext.rb +5 -0
- data/lib/opal/grammar.rb +2207 -2138
- data/lib/opal/grammar.y +21 -0
- data/lib/opal/grammar_helpers.rb +360 -0
- data/lib/opal/lexer.rb +55 -401
- data/lib/opal/lexer_scope.rb +28 -0
- data/lib/opal/parser.rb +155 -171
- data/lib/opal/target_scope.rb +257 -0
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +6 -2
- data/opal/opal-parser.js.erb +3 -2
- data/opal/opal.rb +20 -18
- data/opal/opal/array.rb +21 -12
- data/opal/opal/basic_object.rb +2 -1
- data/opal/opal/boolean.rb +3 -0
- data/opal/opal/browser_loader.js +57 -0
- data/opal/opal/class.rb +51 -13
- data/opal/opal/date.rb +1 -20
- data/opal/opal/enumerable.rb +66 -33
- data/opal/opal/error.rb +2 -0
- data/opal/opal/hash.rb +1 -1
- data/opal/opal/kernel.rb +14 -3
- data/opal/opal/nil_class.rb +4 -0
- data/opal/opal/proc.rb +9 -1
- data/opal/opal/racc.rb +2 -2
- data/opal/opal/regexp.rb +1 -1
- data/opal/opal/runtime.js +14 -4
- data/opal/opal/string.rb +21 -4
- data/opal/opal/time.rb +27 -0
- data/spec/core/array/allocate_spec.rb +7 -1
- data/spec/core/array/append_spec.rb +18 -3
- data/spec/core/array/array_spec.rb +7 -0
- data/spec/core/array/assoc_spec.rb +23 -8
- data/spec/core/array/at_spec.rb +23 -3
- data/spec/core/array/choice_spec.rb +20 -0
- data/spec/core/array/clear_spec.rb +45 -4
- data/spec/core/array/combination_spec.rb +55 -0
- data/spec/core/array/compact_spec.rb +72 -1
- data/spec/core/array/constructor_spec.rb +13 -2
- data/spec/core/array/count_spec.rb +15 -7
- data/spec/core/array/delete_at_spec.rb +44 -1
- data/spec/core/array/delete_if_spec.rb +52 -2
- data/spec/core/array/delete_spec.rb +83 -2
- data/spec/core/array/drop_spec.rb +24 -16
- data/spec/core/array/drop_while_spec.rb +17 -0
- data/spec/core/array/each_index_spec.rb +11 -1
- data/spec/core/array/each_spec.rb +20 -2
- data/spec/core/array/empty_spec.rb +4 -1
- data/spec/core/array/eql_spec.rb +14 -0
- data/spec/core/array/fetch_spec.rb +31 -2
- data/spec/core/array/find_index_spec.rb +8 -0
- data/spec/core/array/first_spec.rb +45 -8
- data/spec/core/array/fixtures/classes.rb +538 -0
- data/spec/core/array/flatten_spec.rb +200 -7
- data/spec/core/array/frozen_spec.rb +32 -0
- data/spec/core/array/include_spec.rb +16 -1
- data/spec/core/array/index_spec.rb +5 -25
- data/spec/core/array/insert_spec.rb +37 -3
- data/spec/core/array/inspect_spec.rb +6 -12
- data/spec/core/array/intersection_spec.rb +55 -4
- data/spec/core/array/join_spec.rb +29 -4
- data/spec/core/array/keep_if_spec.rb +13 -6
- data/spec/core/array/last_spec.rb +35 -1
- data/spec/core/array/length_spec.rb +7 -4
- data/spec/core/array/map_spec.rb +9 -47
- data/spec/core/array/minus_spec.rb +68 -4
- data/spec/core/array/multiply_spec.rb +138 -6
- data/spec/core/array/new_spec.rb +92 -3
- data/spec/core/array/ntimes_spec.rb +26 -0
- data/spec/core/array/plus_spec.rb +48 -2
- data/spec/core/array/pop_spec.rb +159 -39
- data/spec/core/array/push_spec.rb +29 -1
- data/spec/core/array/rassoc_spec.rb +31 -2
- data/spec/core/array/reject_spec.rb +89 -2
- data/spec/core/array/replace_spec.rb +7 -29
- data/spec/core/array/reverse_each_spec.rb +25 -1
- data/spec/core/array/reverse_spec.rb +53 -1
- data/spec/core/array/rindex_spec.rb +55 -5
- data/spec/core/array/select_spec.rb +35 -8
- data/spec/core/array/shared/collect.rb +0 -0
- data/spec/core/array/shared/enumeratorize.rb +12 -0
- data/spec/core/array/shared/eql.rb +95 -0
- data/spec/core/array/shared/index.rb +37 -0
- data/spec/core/array/shared/inspect.rb +3 -0
- data/spec/core/array/shared/join.rb +7 -0
- data/spec/core/array/shared/keep_if.rb +0 -0
- data/spec/core/array/shared/length.rb +0 -0
- data/spec/core/array/shared/replace.rb +0 -0
- data/spec/core/array/shared/slice.rb +0 -0
- data/spec/core/array/shift_spec.rb +132 -23
- data/spec/core/array/shuffle_spec.rb +82 -6
- data/spec/core/array/size_spec.rb +7 -4
- data/spec/core/array/slice_spec.rb +132 -1
- data/spec/core/array/sort_spec.rb +263 -14
- data/spec/core/array/take_spec.rb +24 -16
- data/spec/core/array/take_while_spec.rb +14 -10
- data/spec/core/array/to_a_spec.rb +18 -1
- data/spec/core/array/to_ary_spec.rb +15 -1
- data/spec/core/array/try_convert_spec.rb +39 -2
- data/spec/core/array/uniq_spec.rb +148 -3
- data/spec/core/array/unshift_spec.rb +36 -1
- data/spec/core/array/zip_spec.rb +36 -1
- data/spec/core/class/new_spec.rb +8 -6
- data/spec/core/enumerable/all_spec.rb +37 -9
- data/spec/core/enumerable/any_spec.rb +45 -7
- data/spec/core/enumerable/collect_spec.rb +4 -1
- data/spec/core/enumerable/count_spec.rb +4 -1
- data/spec/core/enumerable/detect_spec.rb +2 -2
- data/spec/core/enumerable/drop_spec.rb +4 -1
- data/spec/core/enumerable/drop_while_spec.rb +4 -1
- data/spec/core/enumerable/each_slice_spec.rb +2 -1
- data/spec/core/enumerable/each_with_index_spec.rb +4 -1
- data/spec/core/enumerable/each_with_object_spec.rb +4 -1
- data/spec/core/enumerable/entries_spec.rb +4 -1
- data/spec/core/enumerable/find_all_spec.rb +4 -1
- data/spec/core/enumerable/find_index_spec.rb +4 -1
- data/spec/core/enumerable/find_spec.rb +5 -2
- data/spec/core/enumerable/first_spec.rb +4 -1
- data/spec/core/enumerable/fixtures/classes.rb +198 -2
- data/spec/core/enumerable/grep_spec.rb +4 -1
- data/spec/core/enumerable/take_spec.rb +4 -1
- data/spec/core/enumerable/to_a_spec.rb +4 -1
- data/spec/core/false/and_spec.rb +11 -0
- data/spec/core/false/inspect_spec.rb +7 -0
- data/spec/core/false/or_spec.rb +11 -0
- data/spec/core/false/to_s_spec.rb +7 -0
- data/spec/core/false/xor_spec.rb +11 -0
- data/spec/core/kernel/rand_spec.rb +5 -5
- data/spec/core/module/const_get_spec.rb +4 -4
- data/spec/core/module/fixtures/classes.rb +434 -0
- data/spec/core/module/method_defined_spec.rb +49 -0
- data/spec/core/module/module_function_spec.rb +28 -0
- data/spec/core/nil/and_spec.rb +3 -1
- data/spec/core/nil/dup_spec.rb +7 -0
- data/spec/core/nil/inspect_spec.rb +3 -1
- data/spec/core/nil/nil_spec.rb +3 -1
- data/spec/core/nil/or_spec.rb +4 -2
- data/spec/core/nil/to_a_spec.rb +3 -1
- data/spec/core/nil/to_f_spec.rb +3 -1
- data/spec/core/nil/to_i_spec.rb +3 -1
- data/spec/core/nil/to_s_spec.rb +3 -1
- data/spec/core/nil/xor_spec.rb +4 -2
- data/spec/core/string/element_reference_spec.rb +14 -1
- data/spec/core/string/fixtures/classes.rb +0 -0
- data/spec/core/true/and_spec.rb +11 -0
- data/spec/core/true/inspect_spec.rb +7 -0
- data/spec/core/true/or_spec.rb +11 -0
- data/spec/core/true/to_s_spec.rb +7 -0
- data/spec/core/true/xor_spec.rb +11 -0
- data/spec/{core → core_ext}/array/element_reference_spec.rb +0 -0
- data/spec/{core → core_ext}/array/equal_value_spec.rb +0 -0
- data/spec/{core → core_ext}/array/fill_spec.rb +0 -0
- data/spec/{core → core_ext}/array/reduce_spec.rb +0 -0
- data/spec/core_ext/basic_object/send_spec.rb +3 -3
- data/spec/{core → core_ext}/boolean/singleton_class_spec.rb +0 -0
- data/spec/{core → core_ext}/boolean/to_json_spec.rb +0 -0
- data/spec/core_ext/class/_inherited_spec.rb +3 -3
- data/spec/core_ext/class/proc_methods_spec.rb +2 -2
- data/spec/core_ext/class/singleton_methods_spec.rb +8 -8
- data/spec/core_ext/method_missing_spec.rb +3 -3
- data/spec/core_ext/native/method_missing_spec.rb +3 -2
- data/spec/core_ext/native/to_native_spec.rb +3 -2
- data/spec/{core → core_ext}/nil/to_json_spec.rb +0 -0
- data/spec/date.rb +0 -0
- data/spec/fileutils.rb +0 -0
- data/spec/filters/ancestors.rb +4 -0
- data/spec/filters/array_delete.rb +3 -0
- data/spec/filters/array_fetch.rb +3 -0
- data/spec/filters/array_first.rb +3 -0
- data/spec/filters/array_flatten.rb +14 -0
- data/spec/filters/array_intersection.rb +5 -0
- data/spec/filters/array_join.rb +6 -0
- data/spec/filters/array_subclasses.rb +4 -0
- data/spec/filters/block_args.rb +3 -0
- data/spec/filters/coerce_integer.rb +9 -0
- data/spec/filters/frozen.rb +4 -0
- data/spec/filters/mocks.rb +3 -0
- data/spec/filters/should_receive.rb +4 -0
- data/spec/filters/tainted.rb +7 -0
- data/spec/fixtures/class.rb +124 -0
- data/spec/fixtures/class_variables.rb +0 -0
- data/spec/fixtures/constants.rb +0 -0
- data/spec/grammar/alias_spec.rb +1 -1
- data/spec/grammar/def_spec.rb +1 -0
- data/spec/grammar/lvar_spec.rb +1 -2
- data/spec/grammar/nth_ref_spec.rb +13 -0
- data/spec/grammar/sclass_spec.rb +6 -7
- data/spec/grammar/str_spec.rb +4 -4
- data/spec/grammar/string_spec.rb +8 -0
- data/spec/grammar/xstr_spec.rb +4 -4
- data/spec/iconv.rb +0 -0
- data/spec/language/alias_spec.rb +140 -3
- data/spec/language/and_spec.rb +14 -7
- data/spec/language/array_spec.rb +57 -5
- data/spec/language/block_spec.rb +466 -49
- data/spec/language/break_spec.rb +294 -44
- data/spec/language/case_spec.rb +151 -3
- data/spec/language/class_spec.rb +196 -0
- data/spec/language/class_variable_spec.rb +56 -0
- data/spec/language/def_spec.rb +507 -4
- data/spec/language/defined_spec.rb +19 -7
- data/spec/language/ensure_spec.rb +26 -39
- data/spec/language/execution_spec.rb +15 -0
- data/spec/language/fixtures/array.rb +11 -0
- data/spec/language/fixtures/block.rb +57 -0
- data/spec/language/fixtures/break.rb +240 -0
- data/spec/language/fixtures/ensure.rb +72 -0
- data/spec/language/fixtures/literal_lambda.rb +7 -0
- data/spec/language/fixtures/metaclass.rb +33 -0
- data/spec/language/fixtures/module.rb +24 -0
- data/spec/language/fixtures/next.rb +78 -12
- data/spec/language/fixtures/return.rb +118 -0
- data/spec/language/fixtures/send.rb +110 -0
- data/spec/language/fixtures/send_1.9.rb +22 -0
- data/spec/language/fixtures/super.rb +308 -0
- data/spec/language/fixtures/variables.rb +58 -0
- data/spec/language/fixtures/yield.rb +5 -0
- data/spec/language/for_spec.rb +192 -0
- data/spec/language/hash_spec.rb +29 -5
- data/spec/language/if_spec.rb +90 -9
- data/spec/language/literal_lambda_spec.rb +1 -47
- data/spec/language/loop_spec.rb +39 -2
- data/spec/language/metaclass_spec.rb +151 -5
- data/spec/language/module_spec.rb +56 -0
- data/spec/language/next_spec.rb +370 -12
- data/spec/language/not_spec.rb +55 -0
- data/spec/language/numbers_spec.rb +56 -0
- data/spec/language/or_spec.rb +31 -3
- data/spec/language/order_spec.rb +79 -0
- data/spec/language/precedence_spec.rb +483 -0
- data/spec/language/proc_spec.rb +249 -21
- data/spec/language/redo_spec.rb +67 -0
- data/spec/language/rescue_spec.rb +121 -0
- data/spec/language/retry_spec.rb +56 -0
- data/spec/language/return_spec.rb +281 -0
- data/spec/language/send_spec.rb +141 -48
- data/spec/language/singleton_class_spec.rb +1 -1
- data/spec/language/string_spec.rb +11 -0
- data/spec/language/super_spec.rb +213 -133
- data/spec/language/symbol_spec.rb +2 -1
- data/spec/language/undef_spec.rb +3 -1
- data/spec/language/unless_spec.rb +6 -2
- data/spec/language/until_spec.rb +102 -3
- data/spec/language/variables_spec.rb +1212 -16
- data/spec/language/versions/array_1.9.rb +39 -0
- data/spec/language/versions/case_1.9.rb +20 -0
- data/spec/language/versions/hash_1.9.rb +18 -0
- data/spec/language/versions/literal_lambda_1.9.rb +143 -0
- data/spec/language/versions/not_1.9.rb +22 -0
- data/spec/language/versions/send_1.9.rb +241 -0
- data/spec/language/versions/symbol_1.9.rb +15 -0
- data/spec/language/versions/variables_1.9.rb +8 -0
- data/spec/language/while_spec.rb +70 -5
- data/spec/language/yield_spec.rb +32 -6
- data/spec/mspec/guards/block_device.rb +0 -0
- data/spec/mspec/guards/endian.rb +0 -0
- data/spec/mspec/helpers/environment.rb +0 -0
- data/spec/mspec/helpers/language_version.rb +0 -0
- data/spec/mspec/helpers/tmp.rb +0 -0
- data/spec/ospec/filter.rb +32 -0
- data/spec/ospec/main.rb.erb +18 -0
- data/spec/ospec/phantom.rb +97 -0
- data/spec/ospec/runner.rb +95 -0
- data/spec/ospec/sprockets.js +40 -0
- data/spec/pp.rb +3 -0
- data/spec/rbconfig.rb +5 -0
- data/spec/spec_helper.rb +53 -26
- data/spec/yaml.rb +0 -0
- metadata +275 -31
- data/config.ru +0 -8
- data/lib/opal/processor.rb +0 -47
- data/lib/opal/scope.rb +0 -236
- data/lib/opal/server.rb +0 -94
- data/spec/core/boolean/and_spec.rb +0 -17
- data/spec/core/boolean/inspect_spec.rb +0 -9
- data/spec/core/boolean/or_spec.rb +0 -17
- data/spec/core/boolean/to_s_spec.rb +0 -9
- data/spec/core/boolean/xor_spec.rb +0 -17
@@ -0,0 +1,72 @@
|
|
1
|
+
module EnsureSpec
|
2
|
+
class Container
|
3
|
+
attr_reader :executed
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@executed = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def raise_in_method_with_ensure
|
10
|
+
@executed << :method
|
11
|
+
raise "An Exception"
|
12
|
+
ensure
|
13
|
+
@executed << :ensure
|
14
|
+
end
|
15
|
+
|
16
|
+
def raise_and_rescue_in_method_with_ensure
|
17
|
+
@executed << :method
|
18
|
+
raise "An Exception"
|
19
|
+
rescue
|
20
|
+
@executed << :rescue
|
21
|
+
ensure
|
22
|
+
@executed << :ensure
|
23
|
+
end
|
24
|
+
|
25
|
+
def throw_in_method_with_ensure
|
26
|
+
@executed << :method
|
27
|
+
throw(:symbol)
|
28
|
+
ensure
|
29
|
+
@executed << :ensure
|
30
|
+
end
|
31
|
+
|
32
|
+
def implicit_return_in_method_with_ensure
|
33
|
+
:method
|
34
|
+
ensure
|
35
|
+
:ensure
|
36
|
+
end
|
37
|
+
|
38
|
+
def explicit_return_in_method_with_ensure
|
39
|
+
return :method
|
40
|
+
ensure
|
41
|
+
return :ensure
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module EnsureSpec
|
47
|
+
|
48
|
+
class Test
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@values = []
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :values
|
55
|
+
|
56
|
+
def call_block
|
57
|
+
begin
|
58
|
+
@values << :start
|
59
|
+
yield
|
60
|
+
ensure
|
61
|
+
@values << :end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def do_test
|
66
|
+
call_block do
|
67
|
+
@values << :in_block
|
68
|
+
return :did_test
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module MetaClassSpecs
|
2
|
+
|
3
|
+
def self.metaclass_of obj
|
4
|
+
class << obj
|
5
|
+
self
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class A
|
10
|
+
def self.cheese
|
11
|
+
'edam'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class B < A
|
16
|
+
def self.cheese
|
17
|
+
'stilton'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class C
|
22
|
+
class << self
|
23
|
+
class << self
|
24
|
+
def ham
|
25
|
+
'iberico'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class D < C; end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ModuleSpecs
|
2
|
+
module Modules
|
3
|
+
class Klass
|
4
|
+
end
|
5
|
+
|
6
|
+
A = "Module"
|
7
|
+
B = 1
|
8
|
+
C = nil
|
9
|
+
D = true
|
10
|
+
E = false
|
11
|
+
end
|
12
|
+
|
13
|
+
module Anonymous
|
14
|
+
end
|
15
|
+
|
16
|
+
module IncludedInObject
|
17
|
+
module IncludedModuleSpecs
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Object
|
23
|
+
include ModuleSpecs::IncludedInObject
|
24
|
+
end
|
@@ -8,6 +8,12 @@ class NextSpecs
|
|
8
8
|
yield
|
9
9
|
end
|
10
10
|
|
11
|
+
# The methods below are defined to spec the behavior of the next statement
|
12
|
+
# while specifically isolating whether the statement is in an Iter block or
|
13
|
+
# not. In a normal spec example, the code is always nested inside a block.
|
14
|
+
# Rather than rely on that implicit context in this case, the context is
|
15
|
+
# made explicit because of the interaction of next in a loop nested inside
|
16
|
+
# an Iter block.
|
11
17
|
def self.while_next(arg)
|
12
18
|
x = true
|
13
19
|
while x
|
@@ -43,20 +49,80 @@ class NextSpecs
|
|
43
49
|
end
|
44
50
|
end
|
45
51
|
end
|
46
|
-
end
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
def self.until_next(arg)
|
54
|
+
x = false
|
55
|
+
until x
|
56
|
+
begin
|
57
|
+
ScratchPad << :begin
|
58
|
+
x = true
|
59
|
+
if arg
|
60
|
+
next 42
|
61
|
+
else
|
62
|
+
next
|
63
|
+
end
|
64
|
+
ensure
|
65
|
+
ScratchPad << :ensure
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.until_within_iter(arg)
|
71
|
+
yielding do
|
72
|
+
x = false
|
73
|
+
until x
|
74
|
+
begin
|
75
|
+
ScratchPad << :begin
|
76
|
+
x = true
|
77
|
+
if arg
|
78
|
+
next 42
|
79
|
+
else
|
80
|
+
next
|
81
|
+
end
|
82
|
+
ensure
|
83
|
+
ScratchPad << :ensure
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
52
87
|
end
|
53
|
-
|
54
|
-
|
88
|
+
|
89
|
+
def self.loop_next(arg)
|
90
|
+
x = 1
|
91
|
+
loop do
|
92
|
+
break if x == 2
|
93
|
+
|
94
|
+
begin
|
95
|
+
ScratchPad << :begin
|
96
|
+
x += 1
|
97
|
+
if arg
|
98
|
+
next 42
|
99
|
+
else
|
100
|
+
next
|
101
|
+
end
|
102
|
+
ensure
|
103
|
+
ScratchPad << :ensure
|
104
|
+
end
|
105
|
+
end
|
55
106
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
107
|
+
|
108
|
+
def self.loop_within_iter(arg)
|
109
|
+
yielding do
|
110
|
+
x = 1
|
111
|
+
loop do
|
112
|
+
break if x == 2
|
113
|
+
|
114
|
+
begin
|
115
|
+
ScratchPad << :begin
|
116
|
+
x += 1
|
117
|
+
if arg
|
118
|
+
next 42
|
119
|
+
else
|
120
|
+
next
|
121
|
+
end
|
122
|
+
ensure
|
123
|
+
ScratchPad << :ensure
|
124
|
+
end
|
125
|
+
end
|
60
126
|
end
|
61
127
|
end
|
62
|
-
end
|
128
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module ReturnSpecs
|
2
|
+
class Blocks
|
3
|
+
def yielding_method
|
4
|
+
yield
|
5
|
+
ScratchPad.record :after_yield
|
6
|
+
end
|
7
|
+
|
8
|
+
def enclosing_method
|
9
|
+
yielding_method do
|
10
|
+
ScratchPad.record :before_return
|
11
|
+
return :return_value
|
12
|
+
ScratchPad.record :after_return
|
13
|
+
end
|
14
|
+
|
15
|
+
ScratchPad.record :after_call
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class NestedCalls < Blocks
|
20
|
+
def invoking_method(&b)
|
21
|
+
yielding_method(&b)
|
22
|
+
ScratchPad.record :after_invoke
|
23
|
+
end
|
24
|
+
|
25
|
+
def enclosing_method
|
26
|
+
invoking_method do
|
27
|
+
ScratchPad.record :before_return
|
28
|
+
return :return_value
|
29
|
+
ScratchPad.record :after_return
|
30
|
+
end
|
31
|
+
ScratchPad.record :after_invoke
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class NestedBlocks < Blocks
|
36
|
+
def enclosing_method
|
37
|
+
yielding_method do
|
38
|
+
yielding_method do
|
39
|
+
ScratchPad.record :before_return
|
40
|
+
return :return_value
|
41
|
+
ScratchPad.record :after_return
|
42
|
+
end
|
43
|
+
ScratchPad.record :after_invoke1
|
44
|
+
end
|
45
|
+
ScratchPad.record :after_invoke2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class SavedInnerBlock
|
50
|
+
def add(&b)
|
51
|
+
@block = b
|
52
|
+
end
|
53
|
+
|
54
|
+
def outer
|
55
|
+
yield
|
56
|
+
@block.call
|
57
|
+
end
|
58
|
+
|
59
|
+
def inner
|
60
|
+
yield
|
61
|
+
end
|
62
|
+
|
63
|
+
def start
|
64
|
+
outer do
|
65
|
+
inner do
|
66
|
+
add do
|
67
|
+
ScratchPad.record :before_return
|
68
|
+
return :return_value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
ScratchPad.record :bottom_of_start
|
74
|
+
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class ThroughDefineMethod
|
80
|
+
lamb = proc { |x| x.call }
|
81
|
+
define_method :foo, lamb
|
82
|
+
|
83
|
+
def mp(&b); b; end
|
84
|
+
|
85
|
+
def outer
|
86
|
+
pr = mp { return :good }
|
87
|
+
|
88
|
+
foo(pr)
|
89
|
+
return :bad
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class DefineMethod
|
94
|
+
lamb = proc { return :good }
|
95
|
+
define_method :foo, lamb
|
96
|
+
|
97
|
+
def outer
|
98
|
+
val = :bad
|
99
|
+
|
100
|
+
# This is tricky, but works. If lamb properly returns, then the
|
101
|
+
# return value will go into val before we run the ensure.
|
102
|
+
#
|
103
|
+
# If lamb's return keeps unwinding incorrectly, val will still
|
104
|
+
# have it's old value.
|
105
|
+
#
|
106
|
+
# We can therefore use val to figure out what happened.
|
107
|
+
begin
|
108
|
+
val = foo()
|
109
|
+
ensure
|
110
|
+
if val != :good
|
111
|
+
return :bad
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
return val
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module LangSendSpecs
|
2
|
+
# module_function
|
3
|
+
|
4
|
+
def self.fooM0; 100 end
|
5
|
+
def self.fooM1(a); [a]; end
|
6
|
+
def self.fooM2(a,b); [a,b]; end
|
7
|
+
def self.fooM3(a,b,c); [a,b,c]; end
|
8
|
+
def self.fooM4(a,b,c,d); [a,b,c,d]; end
|
9
|
+
def self.fooM5(a,b,c,d,e); [a,b,c,d,e]; end
|
10
|
+
def self.fooM0O1(a=1); [a]; end
|
11
|
+
def self.fooM1O1(a,b=1); [a,b]; end
|
12
|
+
def self.fooM2O1(a,b,c=1); [a,b,c]; end
|
13
|
+
def self.fooM3O1(a,b,c,d=1); [a,b,c,d]; end
|
14
|
+
def self.fooM4O1(a,b,c,d,e=1); [a,b,c,d,e]; end
|
15
|
+
def self.fooM0O2(a=1,b=2); [a,b]; end
|
16
|
+
def self.fooM0R(*r); r; end
|
17
|
+
def self.fooM1R(a, *r); [a, r]; end
|
18
|
+
def self.fooM0O1R(a=1, *r); [a, r]; end
|
19
|
+
def self.fooM1O1R(a, b=1, *r); [a, b, r]; end
|
20
|
+
|
21
|
+
def self.one(a); a; end
|
22
|
+
# def oneb(a,&b); [a,yield(b)]; end
|
23
|
+
# def twob(a,b,&c); [a,b,yield(c)]; end
|
24
|
+
def self.makeproc(&b) b end
|
25
|
+
|
26
|
+
# def yield_now; yield; end
|
27
|
+
|
28
|
+
def self.double(x); x * 2 end
|
29
|
+
def self.weird_parens
|
30
|
+
# means double((5).to_s)
|
31
|
+
# NOT (double(5)).to_s
|
32
|
+
double (5).to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.rest_len(*a); a.size; end
|
36
|
+
|
37
|
+
def self.twos(a,b,*c)
|
38
|
+
[c.size, c.last]
|
39
|
+
end
|
40
|
+
|
41
|
+
class PrivateSetter
|
42
|
+
attr_reader :foo
|
43
|
+
attr_writer :foo
|
44
|
+
private :foo=
|
45
|
+
|
46
|
+
def call_self_foo_equals(value)
|
47
|
+
self.foo = value
|
48
|
+
end
|
49
|
+
|
50
|
+
def call_self_foo_equals_masgn(value)
|
51
|
+
a, self.foo = 1, value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class PrivateGetter
|
56
|
+
attr_reader :foo
|
57
|
+
private :foo
|
58
|
+
|
59
|
+
def call_self_foo
|
60
|
+
self.foo
|
61
|
+
end
|
62
|
+
|
63
|
+
def call_self_foo_or_equals(value)
|
64
|
+
# self.foo ||= 6
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class AttrSet
|
69
|
+
attr_reader :result
|
70
|
+
def []=(a, b, c, d); @result = [a,b,c,d]; end
|
71
|
+
end
|
72
|
+
|
73
|
+
class ToProc
|
74
|
+
def initialize(val)
|
75
|
+
@val = val
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_proc
|
79
|
+
Proc.new { @val }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class ToAry
|
84
|
+
def initialize(obj)
|
85
|
+
@obj = obj
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_ary
|
89
|
+
@obj
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class MethodMissing
|
94
|
+
def initialize
|
95
|
+
@message = nil
|
96
|
+
@args = nil
|
97
|
+
end
|
98
|
+
|
99
|
+
attr_reader :message, :args
|
100
|
+
|
101
|
+
def method_missing(m, *a)
|
102
|
+
@message = m
|
103
|
+
@args = a
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def lang_send_rest_len(*a)
|
109
|
+
a.size
|
110
|
+
end
|