opal 0.3.41 → 0.3.42
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 +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,14 @@
|
|
1
|
+
opal_filter "Array#flatten" do
|
2
|
+
fails "Array#flatten does not call flatten on elements"
|
3
|
+
fails "Array#flatten raises an ArgumentError on recursive arrays"
|
4
|
+
fails "Array#flatten flattens any element which responds to #to_ary, using the return value of said method"
|
5
|
+
fails "Array#flatten returns subclass instance for Array subclasses"
|
6
|
+
fails "Array#flatten with a non-Array object in the Array ignores the return value of #to_ary if it is nil"
|
7
|
+
fails "Array#flatten with a non-Array object in the Array raises a TypeError if the return value of #to_ary is not an Array"
|
8
|
+
end
|
9
|
+
|
10
|
+
opal_filter "Array#flatten!" do
|
11
|
+
fails "Array#flatten! does not call flatten! on elements"
|
12
|
+
fails "Array#flatten! raises an ArgumentError on recursive arrays"
|
13
|
+
fails "Array#flatten! flattens any elements which responds to #to_ary, using the return value of said method"
|
14
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
opal_filter "Array#join" do
|
2
|
+
fails "Array#join calls #to_str to convert the separator to a String"
|
3
|
+
fails "Array#join does not call #to_str on the separator if the array is empty"
|
4
|
+
fails "Array#join raises a TypeError if the separator cannot be coerced to a String by calling #to_str"
|
5
|
+
fails "Array#join raises a TypeError if passed false as the separator"
|
6
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
opal_filter "coerce integers" do
|
2
|
+
fails "Array#at raises a TypeError when the passed argument can't be coerced to Integer"
|
3
|
+
fails "Array#delete_at tries to convert the passed argument to an Integer using #to_int"
|
4
|
+
fails "Array#fetch tries to convert the passed argument to an Integer using #to_int"
|
5
|
+
fails "Array#fetch raises a TypeError when the passed argument can't be coerced to Integer"
|
6
|
+
fails "Array#first tries to convert the passed argument to an Integer using #to_int"
|
7
|
+
fails "Array#first raises a TypeError if the passed argument is not numeric"
|
8
|
+
fails "Array#insert tries to convert the passed position argument to an Integer using #to_int"
|
9
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
opal_filter 'tainted' do
|
2
|
+
fails "Array#clear keeps tainted status"
|
3
|
+
fails "Array#compact! keeps tainted status even if all elements are removed"
|
4
|
+
fails "Array#delete_at keeps tainted status"
|
5
|
+
fails "Array#delete_if keeps tainted status"
|
6
|
+
fails "Array#delete keeps tainted status"
|
7
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module ClassSpecs
|
2
|
+
|
3
|
+
def self.sclass_with_block
|
4
|
+
class << self
|
5
|
+
yield
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.sclass_with_return
|
10
|
+
class << self
|
11
|
+
return :inner
|
12
|
+
end
|
13
|
+
return :outer
|
14
|
+
end
|
15
|
+
|
16
|
+
class A; end
|
17
|
+
|
18
|
+
def self.string_class_variables(obj)
|
19
|
+
obj.class_variables.map { |x| x.to_s }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.string_instance_variables(obj)
|
23
|
+
obj.instance_variables.map { |x| x.to_s }
|
24
|
+
end
|
25
|
+
|
26
|
+
class B
|
27
|
+
@@cvar = :cvar
|
28
|
+
@ivar = :ivar
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class C
|
33
|
+
def self.make_class_variable
|
34
|
+
@@cvar = :cvar
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.make_class_instance_variable
|
38
|
+
@civ = :civ
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class D
|
43
|
+
def make_class_variable
|
44
|
+
@@cvar = :cvar
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class E
|
49
|
+
def self.cmeth() :cmeth end
|
50
|
+
def meth() :meth end
|
51
|
+
|
52
|
+
class << self
|
53
|
+
def smeth() :smeth end
|
54
|
+
end
|
55
|
+
|
56
|
+
CONSTANT = :constant!
|
57
|
+
end
|
58
|
+
|
59
|
+
class F; end
|
60
|
+
class F
|
61
|
+
def meth() :meth end
|
62
|
+
end
|
63
|
+
class F
|
64
|
+
def another() :another end
|
65
|
+
end
|
66
|
+
|
67
|
+
class G
|
68
|
+
def override() :nothing end
|
69
|
+
def override() :override end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Container
|
73
|
+
class A; end
|
74
|
+
class B; end
|
75
|
+
end
|
76
|
+
|
77
|
+
O = Object.new
|
78
|
+
class << O
|
79
|
+
def smeth
|
80
|
+
:smeth
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class H
|
85
|
+
def self.inherited(sub)
|
86
|
+
track_inherited << sub
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.track_inherited
|
90
|
+
@inherited_modules ||= []
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class K < H; end
|
95
|
+
|
96
|
+
class I
|
97
|
+
class J < self
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class K
|
102
|
+
def example_instance_method
|
103
|
+
end
|
104
|
+
def self.example_class_method
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class L; end
|
109
|
+
|
110
|
+
class M < L; end
|
111
|
+
end
|
112
|
+
|
113
|
+
class Class
|
114
|
+
def example_instance_method_of_class; end
|
115
|
+
def self.example_class_method_of_class; end
|
116
|
+
end
|
117
|
+
class << Class
|
118
|
+
def example_instance_method_of_singleton_class; end
|
119
|
+
def self.example_class_method_of_singleton_class; end
|
120
|
+
end
|
121
|
+
class Object
|
122
|
+
def example_instance_method_of_object; end
|
123
|
+
def self.example_class_method_of_object; end
|
124
|
+
end
|
File without changes
|
File without changes
|
data/spec/grammar/alias_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe "The alias keyword" do
|
|
20
20
|
|
21
21
|
describe "with gvar and nth ref" do
|
22
22
|
it "should return a s(:valias) with two values as arguments" do
|
23
|
-
opal_parse("alias $foo $1").should == [:valias, :$foo, :"
|
23
|
+
opal_parse("alias $foo $1").should == [:valias, :$foo, :"1"]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/spec/grammar/def_spec.rb
CHANGED
data/spec/grammar/lvar_spec.rb
CHANGED
@@ -24,8 +24,7 @@ describe "An lvar" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should be created by a rest arg" do
|
27
|
-
|
28
|
-
# opal_parse("def a(*b); b; end").should == [:defn, :a, [:args, :"*b"], [:scope, [:block, [:lvar, :b]]]]
|
27
|
+
opal_parse("def a(*b); b; end").should == [:defn, :a, [:args, :"*b"], [:scope, [:block, [:lvar, :b]]]]
|
29
28
|
end
|
30
29
|
|
31
30
|
it "should be created by a block arg" do
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "$1..$9" do
|
4
|
+
it "parses as s(:nth_ref)" do
|
5
|
+
opal_parse('$1').first.should == :nth_ref
|
6
|
+
end
|
7
|
+
|
8
|
+
it "references the number 1..9 as first part" do
|
9
|
+
opal_parse('$1').should == [:nth_ref, '1']
|
10
|
+
opal_parse('$9').should == [:nth_ref, '9']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/spec/grammar/sclass_spec.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Singleton classes" do
|
4
|
-
|
5
|
-
|
6
|
-
# opal_parse('class << A; end')[2].should == [:scope]
|
4
|
+
pending "returns an empty s(:scope) when given an empty body" do
|
5
|
+
opal_parse('class << A; end')[2].should == [:scope]
|
7
6
|
end
|
8
7
|
|
9
8
|
it "does not place single expressions into an s(:block)" do
|
@@ -14,9 +13,9 @@ describe "Singleton classes" do
|
|
14
13
|
opal_parse('class << A; 1; 2; end')[2].should == [:scope, [:block, [:lit, 1], [:lit, 2]]]
|
15
14
|
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# opal_parse('class << self; end').should == [:sclass, [:self], [:scope]]
|
16
|
+
pending "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]]
|
21
19
|
end
|
22
20
|
end
|
21
|
+
|
data/spec/grammar/str_spec.rb
CHANGED
@@ -55,7 +55,7 @@ describe "Strings" do
|
|
55
55
|
opal_parse('%Q{#@@foo}').should == [:dstr, "", [:evstr, [:cvar, :@@foo]]]
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
pending "should match '{' and '}' pairs used to start string before ending match" do
|
59
59
|
opal_parse('%Q{{}}').should == [:str, "{}"]
|
60
60
|
opal_parse('%Q{foo{bar}baz}').should == [:str, "foo{bar}baz"]
|
61
61
|
opal_parse('%Q{{foo}bar}').should == [:str, "{foo}bar"]
|
@@ -65,7 +65,7 @@ describe "Strings" do
|
|
65
65
|
opal_parse('%Q{a{b{c}#{foo}d}e}').should == [:dstr, "a{b{c}", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d}e"]]
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
pending "should match '(' and ')' pairs used to start string before ending match" do
|
69
69
|
opal_parse('%Q(())').should == [:str, "()"]
|
70
70
|
opal_parse('%Q(foo(bar)baz)').should == [:str, "foo(bar)baz"]
|
71
71
|
opal_parse('%Q((foo)bar)').should == [:str, "(foo)bar"]
|
@@ -75,7 +75,7 @@ describe "Strings" do
|
|
75
75
|
opal_parse('%Q(a(b(c)#{foo}d)e)').should == [:dstr, "a(b(c)", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d)e"]]
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
pending "should match '[' and ']' pairs used to start string before ending match" do
|
79
79
|
opal_parse('%Q[[]]').should == [:str, "[]"]
|
80
80
|
opal_parse('%Q[foo[bar]baz]').should == [:str, "foo[bar]baz"]
|
81
81
|
opal_parse('%Q[[foo]bar]').should == [:str, "[foo]bar"]
|
@@ -92,7 +92,7 @@ describe "Strings" do
|
|
92
92
|
it "parses other Qstrings within interpolations" do
|
93
93
|
opal_parse('%Q{#{ %Q{} }}').should == [:dstr, "", [:evstr, [:str, ""]]]
|
94
94
|
end
|
95
|
-
end
|
95
|
+
end
|
96
96
|
|
97
97
|
describe "from character shortcuts" do
|
98
98
|
it "produces a string sexp" do
|
data/spec/grammar/xstr_spec.rb
CHANGED
@@ -65,7 +65,7 @@ describe "x-strings" do
|
|
65
65
|
opal_parse('%x{#@@foo}').should == [:dxstr, "", [:evstr, [:cvar, :@@foo]]]
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
pending "should match '{' and '}' pairs used to start string before ending match" do
|
69
69
|
opal_parse('%x{{}}').should == [:xstr, "{}"]
|
70
70
|
opal_parse('%x{foo{bar}baz}').should == [:xstr, "foo{bar}baz"]
|
71
71
|
opal_parse('%x{{foo}bar}').should == [:xstr, "{foo}bar"]
|
@@ -75,7 +75,7 @@ describe "x-strings" do
|
|
75
75
|
opal_parse('%x{a{b{c}#{foo}d}e}').should == [:dxstr, "a{b{c}", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d}e"]]
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
pending "should match '(' and ')' pairs used to start string before ending match" do
|
79
79
|
opal_parse('%x(())').should == [:xstr, "()"]
|
80
80
|
opal_parse('%x(foo(bar)baz)').should == [:xstr, "foo(bar)baz"]
|
81
81
|
opal_parse('%x((foo)bar)').should == [:xstr, "(foo)bar"]
|
@@ -85,7 +85,7 @@ describe "x-strings" do
|
|
85
85
|
opal_parse('%x(a(b(c)#{foo}d)e)').should == [:dxstr, "a(b(c)", [:evstr, [:call, nil, :foo, [:arglist]]], [:str, "d)e"]]
|
86
86
|
end
|
87
87
|
|
88
|
-
|
88
|
+
pending "should match '[' and ']' pairs used to start string before ending match" do
|
89
89
|
opal_parse('%x[[]]').should == [:xstr, "[]"]
|
90
90
|
opal_parse('%x[foo[bar]baz]').should == [:xstr, "foo[bar]baz"]
|
91
91
|
opal_parse('%x[[foo]bar]').should == [:xstr, "[foo]bar"]
|
@@ -113,4 +113,4 @@ describe "x-strings" do
|
|
113
113
|
}.should raise_error(Exception)
|
114
114
|
end
|
115
115
|
end
|
116
|
-
end
|
116
|
+
end
|
data/spec/iconv.rb
ADDED
File without changes
|
data/spec/language/alias_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
1
3
|
class AliasObject
|
2
|
-
|
3
|
-
attr_reader :
|
4
|
+
attr :foo
|
5
|
+
attr_reader :bar
|
4
6
|
attr_accessor :baz
|
5
7
|
|
6
8
|
def prep; @foo = 3; @bar = 4; end
|
@@ -20,4 +22,139 @@ describe "The alias keyword" do
|
|
20
22
|
end
|
21
23
|
@obj.__value.should == 5
|
22
24
|
end
|
23
|
-
|
25
|
+
|
26
|
+
it "adds the new method to the list of methods" do
|
27
|
+
original_methods = @obj.methods
|
28
|
+
@meta.class_eval do
|
29
|
+
alias __value value
|
30
|
+
end
|
31
|
+
(@obj.methods - original_methods).map {|m| m.to_s }.should == ["__value"]
|
32
|
+
end
|
33
|
+
|
34
|
+
pending "adds the new method to the list of public methods" do
|
35
|
+
original_methods = @obj.public_methods
|
36
|
+
@meta.class_eval do
|
37
|
+
alias __value value
|
38
|
+
end
|
39
|
+
(@obj.public_methods - original_methods).map {|m| m.to_s }.should == ["__value"]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "overwrites an existing method with the target name" do
|
43
|
+
@meta.class_eval do
|
44
|
+
alias false_value value
|
45
|
+
end
|
46
|
+
@obj.false_value.should == 5
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is reversible" do
|
50
|
+
@meta.class_eval do
|
51
|
+
alias __value value
|
52
|
+
alias value false_value
|
53
|
+
end
|
54
|
+
@obj.value.should == 6
|
55
|
+
|
56
|
+
@meta.class_eval do
|
57
|
+
alias value __value
|
58
|
+
end
|
59
|
+
@obj.value.should == 5
|
60
|
+
end
|
61
|
+
|
62
|
+
pending "operates on the object's metaclass when used in instance_eval" do
|
63
|
+
@obj.instance_eval do
|
64
|
+
alias __value value
|
65
|
+
end
|
66
|
+
|
67
|
+
@obj.__value.should == 5
|
68
|
+
lambda { AliasObject.new.__value }.should raise_error(NoMethodError)
|
69
|
+
end
|
70
|
+
|
71
|
+
pending "operates on methods defined via attr, attr_reader, and attr_accessor" do
|
72
|
+
@obj.prep
|
73
|
+
@obj.instance_eval do
|
74
|
+
alias afoo foo
|
75
|
+
alias abar bar
|
76
|
+
alias abaz baz
|
77
|
+
end
|
78
|
+
|
79
|
+
@obj.afoo.should == 3
|
80
|
+
@obj.abar.should == 4
|
81
|
+
@obj.baz = 5
|
82
|
+
@obj.abaz.should == 5
|
83
|
+
end
|
84
|
+
|
85
|
+
pending "operates on methods with splat arguments" do
|
86
|
+
class AliasObject2;end
|
87
|
+
AliasObject2.class_eval do
|
88
|
+
def test(*args)
|
89
|
+
4
|
90
|
+
end
|
91
|
+
def test_with_check(*args)
|
92
|
+
test_without_check(*args)
|
93
|
+
end
|
94
|
+
alias test_without_check test
|
95
|
+
alias test test_with_check
|
96
|
+
end
|
97
|
+
AliasObject2.new.test(1,2,3,4,5).should == 4
|
98
|
+
end
|
99
|
+
|
100
|
+
it "operates on methods with splat arguments on eigenclasses" do
|
101
|
+
@meta.class_eval do
|
102
|
+
def test(*args)
|
103
|
+
4
|
104
|
+
end
|
105
|
+
def test_with_check(*args)
|
106
|
+
test_without_check(*args)
|
107
|
+
end
|
108
|
+
alias test_without_check test
|
109
|
+
alias test test_with_check
|
110
|
+
end
|
111
|
+
@obj.test(1,2,3,4,5).should == 4
|
112
|
+
end
|
113
|
+
|
114
|
+
pending "operates on methods with splat arguments defined in a superclass" do
|
115
|
+
class AliasObject3;end
|
116
|
+
class Sub3 < AliasObject3;end
|
117
|
+
AliasObject3.class_eval do
|
118
|
+
def test(*args)
|
119
|
+
4
|
120
|
+
end
|
121
|
+
def test_with_check(*args)
|
122
|
+
test_without_check(*args)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
Sub3.class_eval do
|
126
|
+
alias test_without_check test
|
127
|
+
alias test test_with_check
|
128
|
+
end
|
129
|
+
Sub3.new.test(1,2,3,4,5).should == 4
|
130
|
+
end
|
131
|
+
|
132
|
+
pending "operates on methods with splat arguments defined in a superclass using text block for class eval" do
|
133
|
+
class Sub < AliasObject;end
|
134
|
+
AliasObject.class_eval <<-code
|
135
|
+
def test(*args)
|
136
|
+
4
|
137
|
+
end
|
138
|
+
def test_with_check(*args)
|
139
|
+
test_without_check(*args)
|
140
|
+
end
|
141
|
+
alias test_without_check test
|
142
|
+
alias test test_with_check
|
143
|
+
code
|
144
|
+
Sub.new.test("testing").should == 4
|
145
|
+
end
|
146
|
+
|
147
|
+
pending "is not allowed against Fixnum or String instances" do
|
148
|
+
lambda do
|
149
|
+
1.instance_eval do
|
150
|
+
alias :foo :to_s
|
151
|
+
end
|
152
|
+
end.should raise_error(TypeError)
|
153
|
+
|
154
|
+
lambda do
|
155
|
+
:blah.instance_eval do
|
156
|
+
alias :foo :to_s
|
157
|
+
end
|
158
|
+
end.should raise_error(TypeError)
|
159
|
+
end
|
160
|
+
end
|