opal 0.3.16 → 0.3.17

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.
Files changed (251) hide show
  1. data/.gitignore +2 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +8 -7
  4. data/README.md +21 -13
  5. data/Rakefile +64 -78
  6. data/bin/opal +18 -29
  7. data/core/alpha.rb +2 -9
  8. data/core/array.rb +106 -50
  9. data/core/basic_object.rb +10 -8
  10. data/core/boolean.rb +2 -0
  11. data/core/class.rb +25 -13
  12. data/core/comparable.rb +6 -6
  13. data/core/enumerable.rb +90 -94
  14. data/core/enumerator.rb +3 -3
  15. data/core/hash.rb +86 -46
  16. data/core/kernel.rb +55 -39
  17. data/core/load_order +2 -5
  18. data/core/match_data.rb +1 -1
  19. data/core/module.rb +45 -20
  20. data/core/nil_class.rb +6 -2
  21. data/core/numeric.rb +20 -10
  22. data/core/proc.rb +2 -2
  23. data/core/range.rb +72 -13
  24. data/core/regexp.rb +5 -3
  25. data/core/runtime.js +228 -287
  26. data/core/string.rb +345 -37
  27. data/core/top_self.rb +1 -1
  28. data/lib/opal.rb +13 -91
  29. data/lib/opal/builder.rb +47 -120
  30. data/lib/opal/builder_task.rb +74 -0
  31. data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
  32. data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
  33. data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
  34. data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
  35. data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
  36. data/lib/opal/version.rb +2 -3
  37. data/opal.gemspec +1 -2
  38. data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
  39. data/{core_spec → spec}/core/array/append_spec.rb +1 -4
  40. data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
  41. data/{core_spec → spec}/core/array/at_spec.rb +1 -3
  42. data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
  43. data/spec/core/array/clone_spec.rb +15 -0
  44. data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
  45. data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
  46. data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
  47. data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
  48. data/{core_spec → spec}/core/array/count_spec.rb +1 -3
  49. data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
  50. data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
  51. data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
  52. data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
  53. data/{core_spec → spec}/core/array/each_spec.rb +1 -4
  54. data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
  55. data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
  56. data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
  57. data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
  58. data/{core_spec → spec}/core/array/first_spec.rb +1 -3
  59. data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
  60. data/{core_spec → spec}/core/array/include_spec.rb +1 -3
  61. data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
  62. data/{core_spec → spec}/core/array/last_spec.rb +1 -4
  63. data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
  64. data/spec/core/array/map_spec.rb +53 -0
  65. data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
  66. data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
  67. data/{core_spec → spec}/core/array/push_spec.rb +1 -4
  68. data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
  69. data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
  70. data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
  71. data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
  72. data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
  73. data/spec/core/array/size_spec.rb +6 -0
  74. data/spec/core/array/to_ary_spec.rb +6 -0
  75. data/spec/core/array/uniq_spec.rb +22 -0
  76. data/spec/core/array/zip_spec.rb +20 -0
  77. data/{core_spec → spec}/core/class/new_spec.rb +1 -4
  78. data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
  79. data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
  80. data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
  81. data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
  82. data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
  83. data/{core_spec → spec}/core/false/and_spec.rb +1 -3
  84. data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
  85. data/{core_spec → spec}/core/false/or_spec.rb +1 -3
  86. data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
  87. data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
  88. data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
  89. data/spec/core/hash/assoc_spec.rb +25 -0
  90. data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
  91. data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
  92. data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
  93. data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
  94. data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
  95. data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
  96. data/spec/core/hash/merge_spec.rb +37 -0
  97. data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
  98. data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
  99. data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
  100. data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
  101. data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
  102. data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
  103. data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
  104. data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
  105. data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
  106. data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
  107. data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
  108. data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
  109. data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
  110. data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
  111. data/{core_spec → spec}/core/true/and_spec.rb +1 -3
  112. data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
  113. data/{core_spec → spec}/core/true/or_spec.rb +1 -3
  114. data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
  115. data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
  116. data/spec/index.html +11 -0
  117. data/{core_spec → spec}/language/alias_spec.rb +1 -3
  118. data/{core_spec → spec}/language/and_spec.rb +1 -4
  119. data/{core_spec → spec}/language/array_spec.rb +1 -4
  120. data/{core_spec → spec}/language/block_spec.rb +20 -3
  121. data/{core_spec → spec}/language/break_spec.rb +40 -3
  122. data/{core_spec → spec}/language/case_spec.rb +1 -4
  123. data/{core_spec → spec}/language/defined_spec.rb +9 -3
  124. data/{core_spec → spec}/language/ensure_spec.rb +38 -3
  125. data/{core_spec → spec}/language/hash_spec.rb +1 -3
  126. data/{core_spec → spec}/language/if_spec.rb +1 -4
  127. data/{core_spec → spec}/language/loop_spec.rb +1 -3
  128. data/spec/language/metaclass_spec.rb +13 -0
  129. data/{core_spec → spec}/language/next_spec.rb +47 -3
  130. data/{core_spec → spec}/language/or_spec.rb +1 -4
  131. data/{core_spec → spec}/language/predefined_spec.rb +1 -3
  132. data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
  133. data/{core_spec → spec}/language/send_spec.rb +38 -4
  134. data/spec/language/singleton_class_spec.rb +31 -0
  135. data/spec/language/super_spec.rb +188 -0
  136. data/{core_spec → spec}/language/symbol_spec.rb +1 -3
  137. data/{core_spec → spec}/language/undef_spec.rb +1 -3
  138. data/{core_spec → spec}/language/unless_spec.rb +1 -4
  139. data/{core_spec → spec}/language/until_spec.rb +1 -3
  140. data/{core_spec → spec}/language/variables_spec.rb +1 -3
  141. data/{core_spec → spec}/language/while_spec.rb +1 -3
  142. data/{spec → test}/builder/build_source_spec.rb +0 -0
  143. data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
  144. data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
  145. data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
  146. data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
  147. data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
  148. data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
  149. data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
  150. data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
  151. data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
  152. data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
  153. data/{spec → test}/grammar/alias_spec.rb +0 -0
  154. data/{spec → test}/grammar/and_spec.rb +0 -0
  155. data/{spec → test}/grammar/array_spec.rb +0 -0
  156. data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
  157. data/{spec → test}/grammar/begin_spec.rb +0 -0
  158. data/{spec → test}/grammar/block_spec.rb +0 -0
  159. data/{spec → test}/grammar/break_spec.rb +0 -0
  160. data/{spec → test}/grammar/call_spec.rb +0 -0
  161. data/{spec → test}/grammar/class_spec.rb +0 -0
  162. data/{spec → test}/grammar/const_spec.rb +0 -0
  163. data/{spec → test}/grammar/cvar_spec.rb +0 -0
  164. data/{spec → test}/grammar/def_spec.rb +0 -0
  165. data/{spec → test}/grammar/false_spec.rb +0 -0
  166. data/{spec → test}/grammar/file_spec.rb +0 -0
  167. data/{spec → test}/grammar/gvar_spec.rb +0 -0
  168. data/{spec → test}/grammar/hash_spec.rb +0 -0
  169. data/{spec → test}/grammar/iasgn_spec.rb +0 -0
  170. data/{spec → test}/grammar/if_spec.rb +0 -0
  171. data/{spec → test}/grammar/iter_spec.rb +0 -0
  172. data/{spec → test}/grammar/ivar_spec.rb +0 -0
  173. data/{spec → test}/grammar/lasgn_spec.rb +0 -0
  174. data/{spec → test}/grammar/line_spec.rb +0 -0
  175. data/{spec → test}/grammar/lvar_spec.rb +0 -0
  176. data/{spec → test}/grammar/masgn_spec.rb +0 -0
  177. data/{spec → test}/grammar/module_spec.rb +0 -0
  178. data/{spec → test}/grammar/nil_spec.rb +0 -0
  179. data/{spec → test}/grammar/not_spec.rb +0 -0
  180. data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
  181. data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
  182. data/{spec → test}/grammar/or_spec.rb +0 -0
  183. data/{spec → test}/grammar/return_spec.rb +0 -0
  184. data/{spec → test}/grammar/sclass_spec.rb +0 -0
  185. data/{spec → test}/grammar/self_spec.rb +0 -0
  186. data/{spec → test}/grammar/str_spec.rb +0 -0
  187. data/{spec → test}/grammar/super_spec.rb +0 -0
  188. data/{spec → test}/grammar/true_spec.rb +0 -0
  189. data/{spec → test}/grammar/undef_spec.rb +0 -0
  190. data/{spec → test}/grammar/unless_spec.rb +0 -0
  191. data/{spec → test}/grammar/while_spec.rb +0 -0
  192. data/{spec → test}/grammar/xstr_spec.rb +0 -0
  193. data/{spec → test}/grammar/yield_spec.rb +0 -0
  194. data/{spec → test}/spec_helper.rb +0 -0
  195. metadata +330 -264
  196. data/core/debug.js +0 -59
  197. data/core/debug.rb +0 -35
  198. data/core/dir.rb +0 -90
  199. data/core/file.rb +0 -83
  200. data/core/gemlib.rb +0 -30
  201. data/core/io.rb +0 -44
  202. data/core_spec/README.md +0 -34
  203. data/core_spec/core/array/collect_spec.rb +0 -3
  204. data/core_spec/core/array/element_set_spec.rb +0 -7
  205. data/core_spec/core/array/eql_spec.rb +0 -3
  206. data/core_spec/core/array/equal_value_spec.rb +0 -3
  207. data/core_spec/core/array/fixtures/classes.rb +0 -8
  208. data/core_spec/core/array/length_spec.rb +0 -3
  209. data/core_spec/core/array/map_spec.rb +0 -3
  210. data/core_spec/core/array/replace_spec.rb +0 -3
  211. data/core_spec/core/enumerable/collect_spec.rb +0 -3
  212. data/core_spec/core/enumerable/detect_spec.rb +0 -3
  213. data/core_spec/core/enumerable/find_spec.rb +0 -3
  214. data/core_spec/core/enumerable/first_spec.rb +0 -3
  215. data/core_spec/core/enumerable/shared/entries.rb +0 -7
  216. data/core_spec/core/enumerable/shared/find.rb +0 -49
  217. data/core_spec/core/enumerable/shared/take.rb +0 -31
  218. data/core_spec/core/enumerable/to_a_spec.rb +0 -7
  219. data/core_spec/core/hash/assoc_spec.rb +0 -29
  220. data/core_spec/core/object/is_a_spec.rb +0 -2
  221. data/core_spec/core/object/shared/kind_of.rb +0 -0
  222. data/core_spec/core/regexp/shared/match.rb +0 -11
  223. data/core_spec/language/fixtures/block.rb +0 -19
  224. data/core_spec/language/fixtures/break.rb +0 -39
  225. data/core_spec/language/fixtures/defined.rb +0 -9
  226. data/core_spec/language/fixtures/ensure.rb +0 -37
  227. data/core_spec/language/fixtures/next.rb +0 -46
  228. data/core_spec/language/fixtures/send.rb +0 -36
  229. data/core_spec/language/fixtures/super.rb +0 -43
  230. data/core_spec/language/regexp_spec.rb +0 -7
  231. data/core_spec/language/string_spec.rb +0 -4
  232. data/core_spec/language/super_spec.rb +0 -18
  233. data/core_spec/language/versions/hash_1.9.rb +0 -20
  234. data/core_spec/opal/opal/defined_spec.rb +0 -15
  235. data/core_spec/opal/opal/function_spec.rb +0 -11
  236. data/core_spec/opal/opal/native_spec.rb +0 -16
  237. data/core_spec/opal/opal/null_spec.rb +0 -10
  238. data/core_spec/opal/opal/number_spec.rb +0 -11
  239. data/core_spec/opal/opal/object_spec.rb +0 -16
  240. data/core_spec/opal/opal/string_spec.rb +0 -11
  241. data/core_spec/opal/opal/typeof_spec.rb +0 -9
  242. data/core_spec/opal/opal/undefined_spec.rb +0 -10
  243. data/core_spec/opal/true/case_compare_spec.rb +0 -12
  244. data/core_spec/opal/true/class_spec.rb +0 -10
  245. data/core_spec/release_runner.html +0 -17
  246. data/core_spec/runner.html +0 -16
  247. data/core_spec/spec_helper.rb +0 -23
  248. data/lib/opal/context.rb +0 -269
  249. data/lib/opal/dependency_builder.rb +0 -133
  250. data/lib/opal/environment.rb +0 -87
  251. data/lib/opal/parser/sexp.rb +0 -17
@@ -1,5 +1,22 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require File.expand_path('../fixtures/block', __FILE__)
1
+ module BlockSpecs
2
+ class Yielder
3
+ def z
4
+ yield
5
+ end
6
+
7
+ def m(*a)
8
+ yield(*a)
9
+ end
10
+
11
+ def s(a)
12
+ yield(a)
13
+ end
14
+
15
+ def r(a)
16
+ yield(*a)
17
+ end
18
+ end
19
+ end
3
20
 
4
21
  describe "A block" do
5
22
  before :each do
@@ -102,4 +119,4 @@ describe "A block" do
102
119
  @y.m(1, 2, 3) { |a, *b| [a, b] }.should == [1, [2, 3]]
103
120
  end
104
121
  end
105
- end
122
+ end
@@ -1,5 +1,42 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require File.expand_path('../fixtures/break', __FILE__)
1
+ module BreakSpecs
2
+ class Driver
3
+ def initialize(ensures=false)
4
+ @ensures = ensures
5
+ end
6
+
7
+ def note(value)
8
+ ScratchPad << value
9
+ end
10
+ end
11
+
12
+ class Block < Driver
13
+ def break_nil
14
+ note :a
15
+ note yielding {
16
+ note :b
17
+ break
18
+ note :c
19
+ }
20
+ note :d
21
+ end
22
+
23
+ def break_value
24
+ note :a
25
+ note yielding {
26
+ note :b
27
+ break :break
28
+ note :c
29
+ }
30
+ note :d
31
+ end
32
+
33
+ def yielding
34
+ note :aa
35
+ note yield
36
+ note :bb
37
+ end
38
+ end
39
+ end
3
40
 
4
41
  describe "The break statement in a block" do
5
42
  before :each do
@@ -46,4 +83,4 @@ describe "Break inside a while loop" do
46
83
  end.should == 2
47
84
  at.should == 2
48
85
  end
49
- end
86
+ end
@@ -1,5 +1,3 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
1
  describe "The 'case'-construct" do
4
2
  it "evaluates the body of the when clause matching the case target expression" do
5
3
  case 1
@@ -161,5 +159,4 @@ describe "The 'case'-construct" do
161
159
  "foo"
162
160
  end.should == nil
163
161
  end
164
- end
165
-
162
+ end
@@ -1,5 +1,11 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require File.expand_path('../fixtures/defined', __FILE__)
1
+ module DefinedSpecs
2
+ class Basic
3
+ A = 42
4
+
5
+ def a_defined_method
6
+ end
7
+ end
8
+ end
3
9
 
4
10
  describe "The defined? keyword for literals" do
5
11
  it "returns 'self' for self" do
@@ -77,4 +83,4 @@ describe "The defined? keyword when called with a method name" do
77
83
  defined?(@defined_specs_obj.an_undefined_method).should be_nil
78
84
  end
79
85
  end
80
- end
86
+ end
@@ -1,5 +1,40 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require File.expand_path('../fixtures/ensure', __FILE__)
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 implicit_return_in_method_with_ensure
26
+ :method
27
+ ensure
28
+ :ensure
29
+ end
30
+
31
+ def explicit_return_in_method_with_ensure
32
+ return :method
33
+ ensure
34
+ return :ensure
35
+ end
36
+ end
37
+ end
3
38
 
4
39
  describe "An ensure block inside a begin block" do
5
40
  before :each do
@@ -79,4 +114,4 @@ describe "An ensure block inside a method" do
79
114
  it "has an impact on the method's explicit return value" do
80
115
  @obj.explicit_return_in_method_with_ensure.should == :ensure
81
116
  end
82
- end
117
+ end
@@ -1,5 +1,3 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
1
  describe "Hash literal" do
4
2
  it "{} should return an empty hash" do
5
3
  {}.size.should == 0
@@ -40,4 +38,4 @@ describe "Hash literal" do
40
38
  h.size.should == 2
41
39
  h.should == {:a => 1, :b => 2}
42
40
  end
43
- end
41
+ end
@@ -1,5 +1,3 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
1
  describe "The if expression" do
4
2
  it "evaluates body if expression is true" do
5
3
  a = []
@@ -274,5 +272,4 @@ describe "The postfix if form" do
274
272
  end
275
273
  b.should == 126
276
274
  end
277
- end
278
-
275
+ end
@@ -1,5 +1,3 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
1
  describe "The loop expression" do
4
2
  it "repeats the given block until a break is called" do
5
3
  outer_loop = 0
@@ -29,4 +27,4 @@ describe "The loop expression" do
29
27
  break
30
28
  end.should == nil
31
29
  end
32
- end
30
+ end
@@ -0,0 +1,13 @@
1
+ describe "self in a metaclass body (class << obj)" do
2
+ it "is TrueClass for true" do
3
+ class << true; self; end.should == TrueClass
4
+ end
5
+
6
+ it "is FalseClass for false" do
7
+ class << false; self; end.should == FalseClass
8
+ end
9
+
10
+ it "is NilClass for nil" do
11
+ class << nil; self; end.should == NilClass
12
+ end
13
+ end
@@ -1,5 +1,49 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require File.expand_path('../fixtures/next', __FILE__)
1
+ class NextSpecs
2
+ def self.yielding_method(expected)
3
+ yield.should == expected
4
+ :method_return_value
5
+ end
6
+
7
+ def self.yielding
8
+ yield
9
+ end
10
+
11
+ def self.while_next(arg)
12
+ x = true
13
+ while x
14
+ begin
15
+ ScratchPad << :begin
16
+ x = false
17
+ if arg
18
+ next 42
19
+ else
20
+ next
21
+ end
22
+ ensure
23
+ ScratchPad << :ensure
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.while_within_iter(arg)
29
+ yielding do
30
+ x = true
31
+ while x
32
+ begin
33
+ ScratchPad << :begin
34
+ x = false
35
+ if arg
36
+ next 42
37
+ else
38
+ next
39
+ end
40
+ ensure
41
+ ScratchPad << :ensure
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
3
47
 
4
48
  describe "The next statement from within the block" do
5
49
  before :each do
@@ -125,4 +169,4 @@ describe "The next statement" do
125
169
  end
126
170
  end
127
171
  end
128
- end
172
+ end
@@ -1,5 +1,3 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
1
  describe "The || operator" do
4
2
  it "evaluates to true if any of its operands are true" do
5
3
  if false || true || nil
@@ -61,5 +59,4 @@ describe "The or operator" do
61
59
  (false or ()).should be_nil
62
60
  (() or ()).should be_nil
63
61
  end
64
- end
65
-
62
+ end
@@ -1,5 +1,3 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
-
3
1
  describe "Predefined global $~" do
4
2
  it "is set to contain the MatchData object of the last match if successful" do
5
3
  md = /foo/.match 'foo'
@@ -18,4 +16,4 @@ describe "Predefined global $~" do
18
16
  /foo/ =~ 'bar'
19
17
  $~.nil?.should == true
20
18
  end
21
- end
19
+ end
@@ -1,7 +1,10 @@
1
- require File.expand_path('../../../spec_helper', __FILE__)
1
+ describe "Literal Regexps" do
2
+ it "yields a Regexp" do
3
+ /Hello/.should be_kind_of(Regexp)
4
+ end
5
+ end
2
6
 
3
7
  describe "Regexps with interpolation" do
4
-
5
8
  it "allows interpolation of strings" do
6
9
  str = "foo|bar"
7
10
  /#{str}/.should == /foo|bar/
@@ -14,4 +17,4 @@ describe "Regexps with interpolation" do
14
17
  str = "a"
15
18
  /[#{str}-z]/.should == /[a-z]/
16
19
  end
17
- end
20
+ end
@@ -1,5 +1,39 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
2
- require File.expand_path('../fixtures/send', __FILE__)
1
+ module LangSendSpecs
2
+
3
+ def self.fooM0; 100; end
4
+ def self.fooM1(a); [a]; end
5
+ def self.fooM2(a,b); [a,b]; end
6
+ def self.fooM3(a,b,c); [a,b,c]; end
7
+ def self.fooM4(a,b,c,d); [a,b,c,d]; end
8
+ def self.fooM5(a,b,c,d,e); [a,b,c,d,e]; end
9
+ def self.fooM0O1(a=1); [a]; end
10
+ def self.fooM1O1(a,b=1); [a,b]; end
11
+ def self.fooM2O1(a,b,c=1); [a,b,c]; end
12
+ def self.fooM3O1(a,b,c,d=1); [a,b,c,d]; end
13
+ def self.fooM4O1(a,b,c,d,e=1); [a,b,c,d,e]; end
14
+ def self.fooM0O2(a=1,b=2); [a,b]; end
15
+ def self.fooM0R(*r); r; end
16
+ def self.fooM1R(a, *r); [a, r]; end
17
+ def self.fooM0O1R(a=1, *r); [a, r]; end
18
+ def self.fooM1O1R(a, b=1, *r); [a, b, r]; end
19
+
20
+ def self.one(a); a; end
21
+ def self.oneb(a,&b); [a,yield(b)]; end
22
+
23
+ def self.makeproc(&b) b end
24
+
25
+ def self.yield_now; yield; end
26
+
27
+ class ToProc
28
+ def initialize(val)
29
+ @val = val
30
+ end
31
+
32
+ def to_proc
33
+ Proc.new { @val }
34
+ end
35
+ end
36
+ end
3
37
 
4
38
  specs = LangSendSpecs
5
39
 
@@ -58,7 +92,7 @@ describe "Invoking a method" do
58
92
  specs.oneb(10) { 200 }.should == [10,200]
59
93
  end
60
94
 
61
- it "wwith a block converts the block to a Proc" do
95
+ it "with a block converts the block to a Proc" do
62
96
  prc = specs.makeproc { "hello" }
63
97
  prc.should be_kind_of(Proc)
64
98
  prc.call.should == "hello"
@@ -102,4 +136,4 @@ describe "Invoking a method" do
102
136
  specs.fooM1(:rbx => :cool, :specs => :fail_sometimes).should == [{ :rbx => :cool, :specs => :fail_sometimes }]
103
137
  (specs.fooM1 :rbx => :cool, :specs => :fail_sometimes).should == [{ :rbx => :cool, :specs => :fail_sometimes }]
104
138
  end
105
- end
139
+ end
@@ -0,0 +1,31 @@
1
+ describe "A singleton class" do
2
+ it "is TrueClass for true" do
3
+ true.singleton_class.should == TrueClass
4
+ end
5
+
6
+ it "is FalseClass for false" do
7
+ false.singleton_class.should == FalseClass
8
+ end
9
+
10
+ it "is NilClass for nil" do
11
+ nil.singleton_class.should == NilClass
12
+ end
13
+
14
+ it "raises a TypeError for Fixnum's" do
15
+ lambda { 1.singleton_class }.should raise_error(TypeError)
16
+ end
17
+
18
+ it "raises a TypeError for synbols" do
19
+ lambda { :symbol.singleton_class }.should raise_error(TypeError)
20
+ end
21
+
22
+ it "is a singleton Class instance" do
23
+ o = mock('x')
24
+ o.singleton_class.should be_kind_of(Class)
25
+ o.singleton_class.should_not equal(Object)
26
+ end
27
+
28
+ it "is a Class for classes" do
29
+ ClassSpecs::A::singleton_class.should be_kind_of(Class)
30
+ end
31
+ end
@@ -0,0 +1,188 @@
1
+ describe "The super keyword" do
2
+ it "calls the method on the calling class" do
3
+ Super::S1::A.new.foo([]).should == ["A#foo", "A#bar"]
4
+ Super::S1::A.new.bar([]).should == ["A#bar"]
5
+ Super::S1::B.new.foo([]).should == ["B#foo", "A#foo", "B#bar", "A#bar"]
6
+ Super::S1::B.new.bar([]).should == ["B#bar", "A#bar"]
7
+ end
8
+
9
+ it "searches the full inheritence chain" do
10
+ Super::S2::B.new.foo([]).should == ["B#foo", "A#baz"]
11
+ Super::S2::B.new.baz([]).should == ["A#baz"]
12
+ Super::S2::C.new.foo([]).should == ["B#foo", "C#baz", "A#baz"]
13
+ Super::S2::C.new.baz([]).should == ["C#baz", "A#baz"]
14
+ end
15
+
16
+ it "searches class methods" do
17
+ Super::S3::A.new.foo([]).should == ["A#foo"]
18
+ Super::S3::A.foo([]).should == ["A::foo"]
19
+ Super::S3::A.bar([]).should == ["A::bar", "A::foo"]
20
+ Super::S3::B.new.foo([]).should == ["A#foo"]
21
+ Super::S3::B.foo([]).should == ["B::foo", "A::foo"]
22
+ Super::S3::B.bar([]).should == ["B::bar", "A::bar", "B::foo", "A::foo"]
23
+ end
24
+
25
+ it "calls the method on the calling class including modules" do
26
+ Super::MS1::A.new.foo([]).should == ["ModA#foo", "ModA#bar"]
27
+ Super::MS1::A.new.bar([]).should == ["ModA#bar"]
28
+ Super::MS1::B.new.foo([]).should == ["B#foo","ModA#foo","ModB#bar","ModA#bar"]
29
+ Super::MS1::B.new.bar([]).should == ["ModB#bar", "ModA#bar"]
30
+ end
31
+
32
+ it "searches the full inheritence chain including modules" do
33
+ Super::MS2::B.new.foo([]).should == ["ModB#foo", "A#baz"]
34
+ Super::MS2::B.new.baz([]).should == ["A#baz"]
35
+ Super::MS2::C.new.baz([]).should == ["C#baz", "A#baz"]
36
+ Super::MS2::C.new.foo([]).should == ["ModB#foo","C#baz","A#baz"]
37
+ end
38
+
39
+ it "calls the superclass method when in a block" do
40
+ Super::S6.new.here.should == :good
41
+ end
42
+
43
+ it "calls the superclass when initial method is define_method'd" do
44
+ Super::S7.new.here.should == :good
45
+ end
46
+ end
47
+
48
+ module Super
49
+ module S1
50
+ class A
51
+ def foo(a)
52
+ a << "A#foo"
53
+ bar(a)
54
+ end
55
+ def bar(a)
56
+ a << "A#bar"
57
+ end
58
+ end
59
+ class B < A
60
+ def foo(a)
61
+ a << "B#foo"
62
+ super(a)
63
+ end
64
+ def bar(a)
65
+ a << "B#bar"
66
+ super(a)
67
+ end
68
+ end
69
+ end
70
+
71
+ module S2
72
+ class A
73
+ def baz(a)
74
+ a << "A#baz"
75
+ end
76
+ end
77
+ class B < A
78
+ def foo(a)
79
+ a << "B#foo"
80
+ baz(a)
81
+ end
82
+ end
83
+ class C < B
84
+ def baz(a)
85
+ a << "C#baz"
86
+ super(a)
87
+ end
88
+ end
89
+ end
90
+
91
+ module S3
92
+ class A
93
+ def foo(a)
94
+ a << "A#foo"
95
+ end
96
+ def self.foo(a)
97
+ a << "A::foo"
98
+ end
99
+ def self.bar(a)
100
+ a << "A::bar"
101
+ foo(a)
102
+ end
103
+ end
104
+ class B < A
105
+ def self.foo(a)
106
+ a << "B::foo"
107
+ super(a)
108
+ end
109
+ def self.bar(a)
110
+ a << "B::bar"
111
+ super(a)
112
+ end
113
+ end
114
+ end
115
+
116
+ class S5
117
+ def here
118
+ :good
119
+ end
120
+ end
121
+
122
+ class S6 < S5
123
+ def under
124
+ yield
125
+ end
126
+
127
+ def here
128
+ under {
129
+ super
130
+ }
131
+ end
132
+ end
133
+
134
+ class S7 < S5
135
+ define_method(:here) { super() }
136
+ end
137
+
138
+ module MS1
139
+ module ModA
140
+ def foo(a)
141
+ a << "ModA#foo"
142
+ bar(a)
143
+ end
144
+ def bar(a)
145
+ a << "ModA#bar"
146
+ end
147
+ end
148
+ class A
149
+ include ModA
150
+ end
151
+ module ModB
152
+ def bar(a)
153
+ a << "ModB#bar"
154
+ super(a)
155
+ end
156
+ end
157
+ class B < A
158
+ def foo(a)
159
+ a << "B#foo"
160
+ super(a)
161
+ end
162
+ include ModB
163
+ end
164
+ end
165
+
166
+ module MS2
167
+ class A
168
+ def baz(a)
169
+ a << "A#baz"
170
+ end
171
+ end
172
+ module ModB
173
+ def foo(a)
174
+ a << "ModB#foo"
175
+ baz(a)
176
+ end
177
+ end
178
+ class B < A
179
+ include ModB
180
+ end
181
+ class C < B
182
+ def baz(a)
183
+ a << "C#baz"
184
+ super(a)
185
+ end
186
+ end
187
+ end
188
+ end