opal 0.3.11 → 0.3.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/.gitignore +13 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE +20 -0
  4. data/README.md +11 -116
  5. data/Rakefile +126 -0
  6. data/bin/opal +1 -2
  7. data/docs/spec_runner.html +16 -0
  8. data/index.html +434 -0
  9. data/lib/opal.rb +14 -15
  10. data/lib/opal/builder.rb +46 -148
  11. data/lib/opal/command.rb +45 -115
  12. data/lib/opal/context.rb +139 -78
  13. data/lib/opal/dependency_builder.rb +34 -0
  14. data/lib/opal/environment.rb +92 -0
  15. data/lib/opal/parser/grammar.rb +4915 -0
  16. data/lib/opal/{parser.y → parser/grammar.y} +430 -284
  17. data/lib/opal/parser/lexer.rb +1329 -0
  18. data/lib/opal/parser/parser.rb +1460 -0
  19. data/lib/opal/parser/scope.rb +140 -0
  20. data/lib/opal/parser/sexp.rb +17 -0
  21. data/lib/opal/version.rb +2 -1
  22. data/opal.gemspec +23 -0
  23. data/opal.js +3149 -4162
  24. data/runtime/README.md +25 -0
  25. data/runtime/corelib/alpha.rb +10 -0
  26. data/runtime/corelib/array.rb +962 -0
  27. data/runtime/corelib/basic_object.rb +66 -0
  28. data/runtime/corelib/boolean.rb +44 -0
  29. data/runtime/corelib/class.rb +43 -0
  30. data/runtime/corelib/comparable.rb +25 -0
  31. data/runtime/corelib/complex.rb +2 -0
  32. data/runtime/corelib/dir.rb +29 -0
  33. data/runtime/corelib/enumerable.rb +316 -0
  34. data/runtime/corelib/enumerator.rb +80 -0
  35. data/runtime/corelib/error.rb +25 -0
  36. data/runtime/corelib/file.rb +80 -0
  37. data/runtime/corelib/hash.rb +503 -0
  38. data/runtime/corelib/io.rb +44 -0
  39. data/runtime/corelib/kernel.rb +237 -0
  40. data/runtime/corelib/load_order +29 -0
  41. data/runtime/corelib/match_data.rb +37 -0
  42. data/runtime/corelib/module.rb +171 -0
  43. data/runtime/corelib/native.rb +50 -0
  44. data/runtime/corelib/nil_class.rb +47 -0
  45. data/runtime/corelib/numeric.rb +219 -0
  46. data/runtime/corelib/object.rb +21 -0
  47. data/runtime/corelib/proc.rb +42 -0
  48. data/runtime/corelib/range.rb +38 -0
  49. data/runtime/corelib/rational.rb +16 -0
  50. data/runtime/corelib/regexp.rb +63 -0
  51. data/runtime/corelib/string.rb +185 -0
  52. data/runtime/corelib/struct.rb +97 -0
  53. data/runtime/corelib/time.rb +196 -0
  54. data/runtime/corelib/top_self.rb +7 -0
  55. data/runtime/gemlib/alpha.rb +5 -0
  56. data/runtime/gemlib/kernel.rb +17 -0
  57. data/runtime/gemlib/load_order +2 -0
  58. data/runtime/kernel/class.js +256 -0
  59. data/runtime/kernel/debug.js +42 -0
  60. data/runtime/kernel/init.js +114 -0
  61. data/runtime/kernel/load_order +5 -0
  62. data/runtime/kernel/loader.js +151 -0
  63. data/runtime/kernel/runtime.js +414 -0
  64. data/runtime/spec/README.md +34 -0
  65. data/runtime/spec/core/array/allocate_spec.rb +15 -0
  66. data/runtime/spec/core/array/append_spec.rb +31 -0
  67. data/runtime/spec/core/array/assoc_spec.rb +29 -0
  68. data/runtime/spec/core/array/at_spec.rb +38 -0
  69. data/runtime/spec/core/array/clear_spec.rb +22 -0
  70. data/runtime/spec/core/array/collect_spec.rb +3 -0
  71. data/runtime/spec/core/array/compact_spec.rb +42 -0
  72. data/runtime/spec/core/array/concat_spec.rb +21 -0
  73. data/runtime/spec/core/array/constructor_spec.rb +24 -0
  74. data/runtime/spec/core/array/count_spec.rb +11 -0
  75. data/runtime/spec/core/array/delete_at_spec.rb +31 -0
  76. data/runtime/spec/core/array/delete_if_spec.rb +24 -0
  77. data/runtime/spec/core/array/delete_spec.rb +26 -0
  78. data/runtime/spec/core/array/each_index_spec.rb +33 -0
  79. data/runtime/spec/core/array/each_spec.rb +11 -0
  80. data/runtime/spec/core/array/element_reference_spec.rb +136 -0
  81. data/runtime/spec/core/array/element_set_spec.rb +7 -0
  82. data/runtime/spec/core/array/empty_spec.rb +10 -0
  83. data/runtime/spec/core/array/eql_spec.rb +3 -0
  84. data/runtime/spec/core/array/equal_value_spec.rb +3 -0
  85. data/runtime/spec/core/array/fetch_spec.rb +26 -0
  86. data/runtime/spec/core/array/first_spec.rb +54 -0
  87. data/runtime/spec/core/array/fixtures/classes.rb +8 -0
  88. data/runtime/spec/core/array/flatten_spec.rb +41 -0
  89. data/runtime/spec/core/array/include_spec.rb +20 -0
  90. data/runtime/spec/core/array/insert_spec.rb +59 -0
  91. data/runtime/spec/core/array/last_spec.rb +57 -0
  92. data/runtime/spec/core/array/length_spec.rb +3 -0
  93. data/runtime/spec/core/array/map_spec.rb +3 -0
  94. data/runtime/spec/core/array/plus_spec.rb +16 -0
  95. data/runtime/spec/core/array/pop_spec.rb +79 -0
  96. data/runtime/spec/core/array/push_spec.rb +19 -0
  97. data/runtime/spec/core/array/rassoc_spec.rb +12 -0
  98. data/runtime/spec/core/array/reject_spec.rb +54 -0
  99. data/runtime/spec/core/array/replace_spec.rb +3 -0
  100. data/runtime/spec/core/array/reverse_each_spec.rb +18 -0
  101. data/runtime/spec/core/array/reverse_spec.rb +9 -0
  102. data/runtime/spec/core/array/shared/collect.rb +53 -0
  103. data/runtime/spec/core/array/shared/eql.rb +19 -0
  104. data/runtime/spec/core/array/shared/length.rb +6 -0
  105. data/runtime/spec/core/array/shared/replace.rb +31 -0
  106. data/runtime/spec/core/class/new_spec.rb +19 -0
  107. data/runtime/spec/core/enumerable/all_spec.rb +102 -0
  108. data/runtime/spec/core/enumerable/any_spec.rb +115 -0
  109. data/runtime/spec/core/enumerable/collect_spec.rb +3 -0
  110. data/runtime/spec/core/enumerable/count_spec.rb +29 -0
  111. data/runtime/spec/core/enumerable/detect_spec.rb +3 -0
  112. data/runtime/spec/core/enumerable/find_spec.rb +3 -0
  113. data/runtime/spec/core/enumerable/fixtures/classes.rb +26 -0
  114. data/runtime/spec/core/enumerable/shared/collect.rb +12 -0
  115. data/runtime/spec/core/enumerable/shared/entries.rb +7 -0
  116. data/runtime/spec/core/enumerable/shared/find.rb +49 -0
  117. data/runtime/spec/core/enumerable/to_a_spec.rb +7 -0
  118. data/runtime/spec/core/false/and_spec.rb +11 -0
  119. data/runtime/spec/core/false/inspect_spec.rb +7 -0
  120. data/runtime/spec/core/false/or_spec.rb +11 -0
  121. data/runtime/spec/core/false/to_s_spec.rb +7 -0
  122. data/runtime/spec/core/false/xor_spec.rb +11 -0
  123. data/runtime/spec/core/hash/allocate_spec.rb +15 -0
  124. data/runtime/spec/core/hash/assoc_spec.rb +29 -0
  125. data/runtime/spec/core/hash/clear_spec.rb +21 -0
  126. data/runtime/spec/core/hash/clone_spec.rb +12 -0
  127. data/runtime/spec/core/hash/default_spec.rb +6 -0
  128. data/runtime/spec/core/hash/delete_if_spec.rb +15 -0
  129. data/runtime/spec/core/hash/element_reference_spec.rb +16 -0
  130. data/runtime/spec/core/hash/element_set_spec.rb +8 -0
  131. data/runtime/spec/core/hash/new_spec.rb +13 -0
  132. data/runtime/spec/core/matchdata/to_a_spec.rb +7 -0
  133. data/runtime/spec/core/nil/and_spec.rb +12 -0
  134. data/runtime/spec/core/nil/inspect_spec.rb +8 -0
  135. data/runtime/spec/core/nil/nil_spec.rb +8 -0
  136. data/runtime/spec/core/nil/or_spec.rb +12 -0
  137. data/runtime/spec/core/nil/to_a_spec.rb +8 -0
  138. data/runtime/spec/core/nil/to_f_spec.rb +12 -0
  139. data/runtime/spec/core/nil/to_i_spec.rb +12 -0
  140. data/runtime/spec/core/nil/to_s_spec.rb +8 -0
  141. data/runtime/spec/core/nil/xor_spec.rb +12 -0
  142. data/runtime/spec/core/numeric/equal_value_spec.rb +11 -0
  143. data/runtime/spec/core/object/is_a_spec.rb +2 -0
  144. data/runtime/spec/core/object/shared/kind_of.rb +0 -0
  145. data/runtime/spec/core/regexp/match_spec.rb +23 -0
  146. data/runtime/spec/core/regexp/shared/match.rb +11 -0
  147. data/runtime/spec/core/symbol/to_proc_spec.rb +8 -0
  148. data/runtime/spec/core/true/and_spec.rb +11 -0
  149. data/runtime/spec/core/true/inspect_spec.rb +7 -0
  150. data/runtime/spec/core/true/or_spec.rb +11 -0
  151. data/runtime/spec/core/true/to_s_spec.rb +7 -0
  152. data/runtime/spec/core/true/xor_spec.rb +11 -0
  153. data/runtime/spec/language/alias_spec.rb +25 -0
  154. data/runtime/spec/language/and_spec.rb +62 -0
  155. data/runtime/spec/language/array_spec.rb +68 -0
  156. data/runtime/spec/language/block_spec.rb +105 -0
  157. data/runtime/spec/language/break_spec.rb +49 -0
  158. data/runtime/spec/language/case_spec.rb +165 -0
  159. data/runtime/spec/language/defined_spec.rb +80 -0
  160. data/runtime/spec/language/ensure_spec.rb +82 -0
  161. data/runtime/spec/language/fixtures/block.rb +19 -0
  162. data/runtime/spec/language/fixtures/break.rb +39 -0
  163. data/runtime/spec/language/fixtures/defined.rb +9 -0
  164. data/runtime/spec/language/fixtures/ensure.rb +37 -0
  165. data/runtime/spec/language/fixtures/next.rb +46 -0
  166. data/runtime/spec/language/fixtures/send.rb +36 -0
  167. data/runtime/spec/language/fixtures/super.rb +43 -0
  168. data/runtime/spec/language/hash_spec.rb +43 -0
  169. data/runtime/spec/language/if_spec.rb +278 -0
  170. data/runtime/spec/language/loop_spec.rb +32 -0
  171. data/runtime/spec/language/next_spec.rb +128 -0
  172. data/runtime/spec/language/or_spec.rb +65 -0
  173. data/runtime/spec/language/predefined_spec.rb +21 -0
  174. data/runtime/spec/language/regexp/interpolation_spec.rb +9 -0
  175. data/runtime/spec/language/regexp_spec.rb +7 -0
  176. data/runtime/spec/language/send_spec.rb +105 -0
  177. data/runtime/spec/language/string_spec.rb +4 -0
  178. data/runtime/spec/language/super_spec.rb +18 -0
  179. data/runtime/spec/language/symbol_spec.rb +41 -0
  180. data/runtime/spec/language/undef_spec.rb +16 -0
  181. data/runtime/spec/language/unless_spec.rb +44 -0
  182. data/runtime/spec/language/until_spec.rb +137 -0
  183. data/runtime/spec/language/variables_spec.rb +28 -0
  184. data/runtime/spec/language/versions/hash_1.9.rb +20 -0
  185. data/runtime/spec/language/while_spec.rb +175 -0
  186. data/runtime/spec/library/stringscanner/scan_spec.rb +36 -0
  187. data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +49 -0
  188. data/runtime/spec/opal/opal/defined_spec.rb +15 -0
  189. data/runtime/spec/opal/opal/function_spec.rb +11 -0
  190. data/runtime/spec/opal/opal/native_spec.rb +16 -0
  191. data/runtime/spec/opal/opal/null_spec.rb +10 -0
  192. data/runtime/spec/opal/opal/number_spec.rb +11 -0
  193. data/runtime/spec/opal/opal/object_spec.rb +16 -0
  194. data/runtime/spec/opal/opal/string_spec.rb +11 -0
  195. data/runtime/spec/opal/opal/typeof_spec.rb +9 -0
  196. data/runtime/spec/opal/opal/undefined_spec.rb +10 -0
  197. data/runtime/spec/opal/true/case_compare_spec.rb +12 -0
  198. data/runtime/spec/opal/true/class_spec.rb +10 -0
  199. data/runtime/spec/spec_helper.rb +25 -0
  200. data/runtime/stdlib/base64.rb +91 -0
  201. data/runtime/stdlib/date.rb +4 -0
  202. data/{stdlib → runtime/stdlib}/dev.rb +0 -0
  203. data/runtime/stdlib/forwardable.rb +33 -0
  204. data/runtime/stdlib/optparse.rb +0 -0
  205. data/runtime/stdlib/pp.rb +6 -0
  206. data/{stdlib → runtime/stdlib}/racc/parser.rb +0 -0
  207. data/runtime/stdlib/rbconfig.rb +0 -0
  208. data/runtime/stdlib/si.rb +17 -0
  209. data/runtime/stdlib/strscan.rb +53 -0
  210. data/runtime/stdlib/uri.rb +111 -0
  211. data/runtime/stdlib/uri/common.rb +1014 -0
  212. data/runtime/stdlib/uri/ftp.rb +261 -0
  213. data/runtime/stdlib/uri/generic.rb +1599 -0
  214. data/runtime/stdlib/uri/http.rb +106 -0
  215. data/runtime/stdlib/uri/https.rb +22 -0
  216. data/runtime/stdlib/uri/ldap.rb +260 -0
  217. data/runtime/stdlib/uri/ldaps.rb +20 -0
  218. data/runtime/stdlib/uri/mailto.rb +280 -0
  219. data/spec/builder/build_source_spec.rb +52 -0
  220. data/spec/builder/fixtures/build_source/adam.rb +0 -0
  221. data/spec/builder/fixtures/build_source/bar/a.rb +0 -0
  222. data/spec/builder/fixtures/build_source/bar/wow/b.rb +0 -0
  223. data/spec/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
  224. data/spec/builder/fixtures/build_source/beynon.rb +0 -0
  225. data/spec/builder/fixtures/build_source/charles.js +0 -0
  226. data/spec/builder/fixtures/build_source/foo/a.rb +0 -0
  227. data/spec/builder/fixtures/build_source/foo/b.rb +0 -0
  228. data/spec/builder/fixtures/build_source/foo/x.js +0 -0
  229. data/spec/builder/fixtures/build_source/foo/y.js +0 -0
  230. data/spec/builder/output_path_spec.rb +50 -0
  231. data/spec/grammar/alias_spec.rb +26 -0
  232. data/spec/grammar/and_spec.rb +13 -0
  233. data/spec/grammar/array_spec.rb +22 -0
  234. data/spec/grammar/attrasgn_spec.rb +28 -0
  235. data/spec/grammar/begin_spec.rb +38 -0
  236. data/spec/grammar/block_spec.rb +12 -0
  237. data/spec/grammar/break_spec.rb +17 -0
  238. data/spec/grammar/call_spec.rb +58 -0
  239. data/spec/grammar/class_spec.rb +35 -0
  240. data/spec/grammar/const_spec.rb +13 -0
  241. data/spec/grammar/cvar_spec.rb +11 -0
  242. data/spec/grammar/def_spec.rb +60 -0
  243. data/spec/grammar/false_spec.rb +17 -0
  244. data/spec/grammar/file_spec.rb +7 -0
  245. data/spec/grammar/gvar_spec.rb +13 -0
  246. data/spec/grammar/hash_spec.rb +17 -0
  247. data/spec/grammar/iasgn_spec.rb +9 -0
  248. data/spec/grammar/if_spec.rb +26 -0
  249. data/spec/grammar/iter_spec.rb +59 -0
  250. data/spec/grammar/ivar_spec.rb +9 -0
  251. data/spec/grammar/lasgn_spec.rb +8 -0
  252. data/spec/grammar/line_spec.rb +8 -0
  253. data/spec/grammar/lvar_spec.rb +38 -0
  254. data/spec/grammar/module_spec.rb +27 -0
  255. data/spec/grammar/nil_spec.rb +17 -0
  256. data/spec/grammar/not_spec.rb +27 -0
  257. data/spec/grammar/op_asgn1_spec.rb +23 -0
  258. data/spec/grammar/op_asgn2_spec.rb +23 -0
  259. data/spec/grammar/or_spec.rb +13 -0
  260. data/spec/grammar/return_spec.rb +17 -0
  261. data/spec/grammar/sclass_spec.rb +20 -0
  262. data/spec/grammar/self_spec.rb +17 -0
  263. data/spec/grammar/str_spec.rb +96 -0
  264. data/spec/grammar/super_spec.rb +20 -0
  265. data/spec/grammar/true_spec.rb +17 -0
  266. data/spec/grammar/undef_spec.rb +15 -0
  267. data/spec/grammar/unless_spec.rb +13 -0
  268. data/spec/grammar/while_spec.rb +15 -0
  269. data/spec/grammar/xstr_spec.rb +116 -0
  270. data/spec/grammar/yield_spec.rb +20 -0
  271. data/spec/spec_helper.rb +9 -0
  272. metadata +346 -21
  273. data/lib/opal/bundle.rb +0 -34
  274. data/lib/opal/lexer.rb +0 -902
  275. data/lib/opal/nodes.rb +0 -2150
  276. data/lib/opal/parser.rb +0 -4894
  277. data/lib/opal/rake/bundle_task.rb +0 -63
  278. data/opal-parser.js +0 -8343
  279. data/stdlib/strscan.rb +0 -52
  280. data/templates/init/Rakefile +0 -7
  281. data/templates/init/index.html +0 -17
  282. data/templates/init/lib/__NAME__.rb +0 -2
@@ -0,0 +1,65 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "The || operator" do
4
+ it "evaluates to true if any of its operands are true" do
5
+ if false || true || nil
6
+ x = true
7
+ end
8
+ x.should == true
9
+ end
10
+
11
+ it "evaluates to false if all of its operands are false" do
12
+ if false || nil
13
+ x = true
14
+ end
15
+ x.should == nil
16
+ end
17
+
18
+ it "is evaluated before assignment operators" do
19
+ x = nil || true
20
+ x.should == true
21
+ end
22
+
23
+ it "has a lower precedence than the && operator" do
24
+ x = 1 || false && x = 2
25
+ x.should == 1
26
+ end
27
+
28
+ it "treats empty expressions as nil" do
29
+ (() || true).should be_true
30
+ (() || false).should be_false
31
+ (true || ()).should be_true
32
+ (false || ()).should be_nil
33
+ (() || ()).should be_nil
34
+ end
35
+ end
36
+
37
+ describe "The or operator" do
38
+ it "evaluates to true if any of its operands are true" do
39
+ x = nil
40
+ if false or true
41
+ x = true
42
+ end
43
+ x.should == true
44
+ end
45
+
46
+ it "is evaluated after variables are assigned" do
47
+ x = nil or true
48
+ x.should == nil
49
+ end
50
+
51
+ it "has a lower precedence than the || operator" do
52
+ x = y= nil
53
+ x = true || false or y = 1
54
+ y.should == nil
55
+ end
56
+
57
+ it "treats empty expressions as nil" do
58
+ (() or true).should be_true
59
+ (() or false).should be_false
60
+ (true or ()).should be_true
61
+ (false or ()).should be_nil
62
+ (() or ()).should be_nil
63
+ end
64
+ end
65
+
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Predefined global $~" do
4
+ it "is set to contain the MatchData object of the last match if successful" do
5
+ md = /foo/.match 'foo'
6
+ $~.should be_kind_of(MatchData)
7
+ $~.object_id.should == md.object_id
8
+
9
+ /bar/ =~ 'bar'
10
+ $~.should be_kind_of(MatchData)
11
+ $~.object_id.should_not == md.object_id
12
+ end
13
+
14
+ it "is set to nil if the last match was unsuccessful" do
15
+ /foo/ =~ 'foo'
16
+ $~.nil?.should == false
17
+
18
+ /foo/ =~ 'bar'
19
+ $~.nil?.should == true
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "Regexps with interpolation" do
4
+
5
+ it "allows interpolation of strings" do
6
+ str = "foo|bar"
7
+ /#{str}/.should == /foo|bar/
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Literal Regexps" do
4
+ it "yields a Regexp" do
5
+ /Hello/.should be_kind_of(Regexp)
6
+ end
7
+ end
@@ -0,0 +1,105 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/send', __FILE__)
3
+
4
+ specs = LangSendSpecs
5
+
6
+ describe "Invoking a method" do
7
+ describe "with zero arguments" do
8
+ it "requires no arguments passed" do
9
+ specs.fooM0.should == 100
10
+ end
11
+
12
+ it "raises ArgumentError if the method has a positive arity" do
13
+ lambda {
14
+ specs.fooM1
15
+ }.should raise_error(ArgumentError)
16
+ end
17
+ end
18
+
19
+ describe "with only manditory arguments" do
20
+ it "requires exactly thr same number of passed values" do
21
+ specs.fooM1(1).should == [1]
22
+ specs.fooM2(1,2).should == [1,2]
23
+ specs.fooM3(1,2,3).should == [1,2,3]
24
+ specs.fooM4(1,2,3,4).should == [1,2,3,4]
25
+ specs.fooM5(1,2,3,4,5).should == [1,2,3,4,5]
26
+ end
27
+ end
28
+
29
+ describe "with optional arguments" do
30
+ it "uses the optional argument if none is is passed" do
31
+ specs.fooM0O1.should == [1]
32
+ end
33
+
34
+ it "uses the passed argument if available" do
35
+ specs.fooM0O1(2).should == [2]
36
+ end
37
+ end
38
+
39
+ describe "with manditory and optional arguments" do
40
+ it "uses the passed values in left to right order" do
41
+ specs.fooM1O1(2).should == [2, 1]
42
+ end
43
+ end
44
+
45
+ describe "with a rest argument" do
46
+ it "is an empty array if there are no additional arguments" do
47
+ specs.fooM0R().should == []
48
+ specs.fooM1R(1).should == [1, []]
49
+ end
50
+
51
+ it "gathers unused arguments" do
52
+ specs.fooM0R(1).should == [1]
53
+ specs.fooM1R(1,2).should == [1, [2]]
54
+ end
55
+ end
56
+
57
+ it "with a block makes it available to yield" do
58
+ specs.oneb(10) { 200 }.should == [10,200]
59
+ end
60
+
61
+ it "wwith a block converts the block to a Proc" do
62
+ prc = specs.makeproc { "hello" }
63
+ prc.should be_kind_of(Proc)
64
+ prc.call.should == "hello"
65
+ end
66
+
67
+ it "with an object as a block used 'to_proc' for coercion" do
68
+ o = LangSendSpecs::ToProc.new(:from_to_proc)
69
+
70
+ specs.makeproc(&o).call.should == :from_to_proc
71
+
72
+ specs.yield_now(&o).should == :from_to_proc
73
+ end
74
+
75
+ it "with same names as existing variables is ok" do
76
+ foobar = 100
77
+
78
+ def foobar; 200; end
79
+
80
+ foobar.should == 100
81
+ foobar().should == 200
82
+ end
83
+
84
+ it "with splat operator makes the object the direct arguments" do
85
+ a = [1,2,3]
86
+ specs.fooM3(*a).should == [1,2,3]
87
+ end
88
+
89
+ it "without parantheses works" do
90
+ (specs.fooM3 1,2,3).should == [1,2,3]
91
+ end
92
+
93
+ it "passes literal hashes without curly braces as the last parameter" do
94
+ specs.fooM3('abc', 456, 'rbx' => 'cool', 'specs' => 'fail sometimes', 'oh' => 'weh').should == ['abc', 456, {'rbx' => 'cool', 'specs' => 'fail sometimes', 'oh' => 'weh'}]
95
+ end
96
+
97
+ it "passes a literal hash without curly braces or parens" do
98
+ (specs.fooM3 'abc', 456, 'rbx' => 'cool', 'specs' => 'fail sometimes', 'oh' => 'weh').should == ['abc', 456, {'rbx' => 'cool', 'specs' => 'fail sometimes', 'oh' => 'weh'}]
99
+ end
100
+
101
+ it "allows to literal hashes without curly braces as the only parameter" do
102
+ specs.fooM1(:rbx => :cool, :specs => :fail_sometimes).should == [{ :rbx => :cool, :specs => :fail_sometimes }]
103
+ (specs.fooM1 :rbx => :cool, :specs => :fail_sometimes).should == [{ :rbx => :cool, :specs => :fail_sometimes }]
104
+ end
105
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Ruby character strings" do
4
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require File.expand_path('../fixtures/super', __FILE__)
3
+
4
+ describe "The super keyword" do
5
+ it "calls the method on the calling class" do
6
+ Super::S1::A.new.foo([]).should == ["A#foo", "A#bar"]
7
+ Super::S1::A.new.bar([]).should == ["A#bar"]
8
+ Super::S1::B.new.foo([]).should == ["B#foo", "A#foo", "B#bar", "A#bar"]
9
+ Super::S1::B.new.bar([]).should == ["B#bar", "A#bar"]
10
+ end
11
+
12
+ it "searches the full inheritence chain" do
13
+ Super::S2::B.new.foo([]).should == ["B#foo", "A#baz"]
14
+ Super::S2::B.new.baz([]).should == ["A#baz"]
15
+ Super::S2::C.new.foo([]).should == ["B#foo", "C#baz", "A#baz"]
16
+ Super::S2::C.new.baz([]).should == ["C#baz", "A#baz"]
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "A Symbol literal" do
4
+ it "is a ':' followed by any number of valid characters" do
5
+ a = :foo
6
+ a.should be_kind_of(Symbol)
7
+ # FIXME: this doesnt work as Symbols are Strings
8
+ #a.inspect.should == ':foo'
9
+ end
10
+
11
+ it "is a ':' followed by any valid variable, method, or constant name" do
12
+ # Add more of these?
13
+ [ :Foo,
14
+ :foo,
15
+ :@foo,
16
+ :@@foo,
17
+ :$foo,
18
+ :_,
19
+ :~,
20
+ :-,
21
+ :FOO,
22
+ :_Foo,
23
+ :&,
24
+ :_9
25
+ ].each { |s| s.should be_kind_of(Symbol) }
26
+ end
27
+
28
+ it "is a ':' followed by a single- or double-quoted string that may contain otherwise invalid characters" do
29
+ [ [:'foo bar', ':"foo bar"'],
30
+ [:'++', ':"++"'],
31
+ [:'9', ':"9"'],
32
+ [:"foo #{1 + 1}", ':"foo 2"']
33
+ ].each {
34
+ # FIXME: Symbols are Strings, so #inspect wont work
35
+ }
36
+ end
37
+
38
+ it "may contain '::' in the string" do
39
+ :'Some::Class'.should be_kind_of(Symbol)
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ class UndefSpecClass
4
+ def meth(other);other;end
5
+ end
6
+
7
+ describe "The undef keyword" do
8
+ it "undefines 'meth='" do
9
+ obj = ::UndefSpecClass.new
10
+ (obj.meth 5).should == 5
11
+ class ::UndefSpecClass
12
+ undef meth
13
+ end
14
+ lambda { obj.meth 5 }.should raise_error(NoMethodError)
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "The unless expression" do
4
+ it "evaluates the unless body when the expression is false" do
5
+ unless false
6
+ a = true
7
+ else
8
+ a = false
9
+ end
10
+
11
+ a.should == true
12
+ end
13
+
14
+ it "returns the last statement in the body" do
15
+ unless false
16
+ 'foo'
17
+ 'bar'
18
+ 'baz'
19
+ end.should == 'baz'
20
+ end
21
+
22
+ it "evaluates the else body when the expression is true" do
23
+ unless true
24
+ 'foo'
25
+ else
26
+ 'bar'
27
+ end.should == 'bar'
28
+ end
29
+
30
+ it "takes and optional then after the expression" do
31
+ unless false then
32
+ 'baz'
33
+ end.should == 'baz'
34
+ end
35
+
36
+ it "does not return a value when the expression is true" do
37
+ unless true; end.should == nil
38
+ end
39
+
40
+ it "allows expression and body to be on one line (using 'then')" do
41
+ unless false then 'foo'; else 'bar'; end.should == 'foo'
42
+ end
43
+ end
44
+
@@ -0,0 +1,137 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "The until expression" do
4
+ it "runs while the expression is false" do
5
+ i = 0
6
+ until i > 9
7
+ i += 1
8
+ end
9
+
10
+ i.should == 10
11
+ end
12
+
13
+ it "optionally takes a 'do' after the expression" do
14
+ i = 0
15
+ until i > 9 do
16
+ i += 1
17
+ end
18
+
19
+ i.should == 10
20
+ end
21
+
22
+ it "allows body begin on the same line if do is used" do
23
+ i = 0
24
+ until i > 9 do i += 1
25
+ end
26
+
27
+ i.should == 10
28
+ end
29
+
30
+ it "executes code in containing variable scope" do
31
+ i = 0
32
+ until i == 1
33
+ a = 123
34
+ i = 1
35
+ end
36
+
37
+ a.should == 123
38
+ end
39
+
40
+ it "executes code in containing variable scope with 'do'" do
41
+ i = 0
42
+ until i == 1 do
43
+ a = 123
44
+ i = 1
45
+ end
46
+
47
+ a.should == 123
48
+ end
49
+
50
+ it "returns nil if ended when condition became true" do
51
+ i = 0
52
+ until i > 9
53
+ i += 1
54
+ end.should == nil
55
+ end
56
+
57
+ it "evaluates the body if expression is empty" do
58
+ a = []
59
+ until ()
60
+ a << :body_evaluated
61
+ break
62
+ end
63
+ a.should == [:body_evaluated]
64
+ end
65
+
66
+ it "stops running body if interrupted by break" do
67
+ i = 0
68
+ until i > 9
69
+ i += 1
70
+ break if i > 5
71
+ end
72
+ i.should == 6
73
+ end
74
+
75
+ it "returns value passed to break if interrupted by break" do
76
+ until false
77
+ break 123
78
+ end.should == 123
79
+ end
80
+
81
+ it "returns nil if interrupted by break with no arguments" do
82
+ until false
83
+ break
84
+ end.should == nil
85
+ end
86
+
87
+ it "skips to end of body with next" do
88
+ a = []
89
+ i = 0
90
+ until (i+=1)>=5
91
+ next if i==3
92
+ a << i
93
+ end
94
+ a.should == [1, 2, 4]
95
+ end
96
+ end
97
+
98
+ describe "The until modifier" do
99
+ it "runs preceding statement while the condition is false" do
100
+ i = 0
101
+ i += 1 until i > 9
102
+ i.should == 10
103
+ end
104
+
105
+ it "evaluates condition before statement execution" do
106
+ a = []
107
+ i = 0
108
+ a << i until (i+=1) >= 3
109
+ a.should == [1,2]
110
+ end
111
+
112
+ it "does not run the preceding statement if the condition is true" do
113
+ i = 0
114
+ i += 1 until true
115
+ i.should == 0
116
+ end
117
+
118
+ it "returns nil if ended when condition became true" do
119
+ i = 0
120
+ (i += 1 until i>9).should == nil
121
+ end
122
+
123
+ it "returns value passed to break if interrupted by break" do
124
+ (break 123 until false).should == 123
125
+ end
126
+
127
+ it "returns nil if interrupted by break with no arguments" do
128
+ (break until false).should == nil
129
+ end
130
+
131
+ it "skips to end of body with next" do
132
+ i = 0
133
+ j = 0
134
+ ((i+=1) == 3 ? next : j+=i) until i > 10
135
+ j.should == 63
136
+ end
137
+ end