opal 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +40 -9
  3. data/CHANGELOG.md +349 -0
  4. data/Gemfile +7 -8
  5. data/README.md +25 -3
  6. data/Rakefile +4 -2
  7. data/bin/opal +1 -1
  8. data/examples/rack/Gemfile +3 -0
  9. data/examples/rack/app/application.rb +13 -0
  10. data/examples/rack/app/user.rb +21 -0
  11. data/examples/rack/config.ru +7 -0
  12. data/examples/rack/index.html.erb +10 -0
  13. data/examples/sinatra/Gemfile +4 -0
  14. data/examples/sinatra/app/application.rb +7 -0
  15. data/examples/sinatra/config.ru +21 -0
  16. data/lib/mspec/opal/rake_task.rb +29 -8
  17. data/lib/mspec/opal/runner.rb +5 -4
  18. data/lib/opal.rb +1 -0
  19. data/lib/opal/builder.rb +0 -28
  20. data/lib/opal/cli.rb +0 -14
  21. data/lib/opal/compiler.rb +12 -11
  22. data/lib/opal/fragment.rb +8 -1
  23. data/lib/opal/nodes/array.rb +1 -1
  24. data/lib/opal/nodes/base.rb +4 -0
  25. data/lib/opal/nodes/call.rb +6 -2
  26. data/lib/opal/nodes/call_special.rb +1 -1
  27. data/lib/opal/nodes/class.rb +2 -2
  28. data/lib/opal/nodes/constants.rb +3 -1
  29. data/lib/opal/nodes/helpers.rb +23 -14
  30. data/lib/opal/nodes/if.rb +16 -9
  31. data/lib/opal/nodes/literal.rb +37 -5
  32. data/lib/opal/nodes/logic.rb +7 -1
  33. data/lib/opal/nodes/module.rb +2 -2
  34. data/lib/opal/nodes/scope.rb +13 -2
  35. data/lib/opal/nodes/top.rb +9 -0
  36. data/lib/opal/nodes/variables.rb +5 -2
  37. data/lib/opal/parser.rb +306 -71
  38. data/lib/opal/parser/grammar.rb +2667 -2775
  39. data/lib/opal/parser/grammar.y +177 -233
  40. data/lib/opal/parser/lexer.rb +511 -427
  41. data/lib/opal/parser/sexp.rb +15 -3
  42. data/lib/opal/source_map.rb +8 -4
  43. data/lib/opal/sprockets.rb +4 -0
  44. data/lib/opal/sprockets/cache_key_fix.rb +17 -0
  45. data/lib/opal/sprockets/environment.rb +21 -0
  46. data/lib/opal/sprockets/erb.rb +30 -0
  47. data/lib/opal/sprockets/processor.rb +127 -0
  48. data/lib/opal/sprockets/server.rb +166 -0
  49. data/lib/opal/util.rb +29 -0
  50. data/lib/opal/version.rb +1 -1
  51. data/opal.gemspec +1 -1
  52. data/opal/corelib/array.rb +106 -187
  53. data/opal/corelib/array/inheritance.rb +113 -0
  54. data/opal/corelib/basic_object.rb +6 -2
  55. data/opal/corelib/boolean.rb +4 -0
  56. data/opal/corelib/class.rb +2 -0
  57. data/opal/corelib/complex.rb +3 -0
  58. data/opal/corelib/enumerable.rb +75 -8
  59. data/opal/corelib/enumerator.rb +2 -0
  60. data/opal/corelib/error.rb +23 -23
  61. data/opal/corelib/hash.rb +5 -5
  62. data/opal/corelib/helpers.rb +51 -16
  63. data/opal/corelib/io.rb +7 -24
  64. data/opal/corelib/kernel.rb +23 -11
  65. data/opal/corelib/module.rb +44 -47
  66. data/opal/corelib/nil_class.rb +4 -0
  67. data/opal/corelib/numeric.rb +101 -15
  68. data/opal/corelib/range.rb +2 -0
  69. data/opal/corelib/rational.rb +3 -0
  70. data/opal/corelib/regexp.rb +36 -17
  71. data/opal/corelib/runtime.js +22 -7
  72. data/opal/corelib/string.rb +213 -110
  73. data/opal/corelib/string/inheritance.rb +78 -0
  74. data/opal/corelib/struct.rb +8 -0
  75. data/opal/corelib/time.rb +54 -42
  76. data/opal/corelib/variables.rb +24 -0
  77. data/opal/opal.rb +5 -27
  78. data/spec/cli/compiler_spec.rb +136 -0
  79. data/spec/cli/dependency_resolver_spec.rb +40 -0
  80. data/spec/cli/lexer_spec.rb +110 -0
  81. data/spec/cli/parser/alias_spec.rb +26 -0
  82. data/spec/cli/parser/and_spec.rb +13 -0
  83. data/spec/cli/parser/attrasgn_spec.rb +28 -0
  84. data/spec/cli/parser/begin_spec.rb +42 -0
  85. data/spec/cli/parser/block_spec.rb +12 -0
  86. data/spec/cli/parser/break_spec.rb +17 -0
  87. data/spec/cli/parser/call_spec.rb +139 -0
  88. data/spec/cli/parser/class_spec.rb +35 -0
  89. data/spec/cli/parser/comments_spec.rb +11 -0
  90. data/spec/cli/parser/def_spec.rb +61 -0
  91. data/spec/cli/parser/if_spec.rb +26 -0
  92. data/spec/cli/parser/iter_spec.rb +59 -0
  93. data/spec/cli/parser/lambda_spec.rb +64 -0
  94. data/spec/cli/parser/literal_spec.rb +113 -0
  95. data/spec/cli/parser/masgn_spec.rb +37 -0
  96. data/spec/cli/parser/module_spec.rb +27 -0
  97. data/spec/cli/parser/not_spec.rb +27 -0
  98. data/spec/cli/parser/op_asgn1_spec.rb +23 -0
  99. data/spec/cli/parser/op_asgn2_spec.rb +23 -0
  100. data/spec/cli/parser/or_spec.rb +13 -0
  101. data/spec/cli/parser/return_spec.rb +17 -0
  102. data/spec/cli/parser/sclass_spec.rb +21 -0
  103. data/spec/cli/parser/string_spec.rb +269 -0
  104. data/spec/cli/parser/super_spec.rb +20 -0
  105. data/spec/cli/parser/undef_spec.rb +15 -0
  106. data/spec/cli/parser/unless_spec.rb +13 -0
  107. data/spec/cli/parser/variables_spec.rb +92 -0
  108. data/spec/cli/parser/while_spec.rb +15 -0
  109. data/spec/cli/parser/yield_spec.rb +20 -0
  110. data/spec/cli/spec_helper.rb +31 -11
  111. data/spec/opal/core/array/set_range_to_array_spec.rb +7 -0
  112. data/spec/opal/core/date_spec.rb +122 -0
  113. data/spec/opal/core/language/predefined_spec.rb +1 -1
  114. data/spec/opal/core/runtime/operator_call_spec.rb +13 -0
  115. data/spec/opal/core/runtime/truthy_spec.rb +23 -0
  116. data/spec/opal/filters/bugs/array.rb +96 -87
  117. data/spec/opal/filters/bugs/basic_object.rb +9 -0
  118. data/spec/opal/filters/bugs/class.rb +16 -0
  119. data/spec/opal/filters/bugs/enumerable.rb +54 -0
  120. data/spec/opal/filters/bugs/language.rb +37 -3
  121. data/spec/opal/filters/bugs/math.rb +93 -0
  122. data/spec/opal/filters/bugs/nil.rb +7 -0
  123. data/spec/opal/filters/bugs/numeric.rb +19 -0
  124. data/spec/opal/filters/bugs/opal.rb +12 -0
  125. data/spec/opal/filters/bugs/regexp.rb +0 -2
  126. data/spec/opal/filters/bugs/string.rb +317 -19
  127. data/spec/opal/filters/bugs/struct.rb +29 -0
  128. data/spec/opal/filters/bugs/time.rb +130 -9
  129. data/spec/opal/filters/unsupported/encoding.rb +52 -4
  130. data/spec/opal/filters/unsupported/enumerator.rb +0 -3
  131. data/spec/opal/filters/unsupported/integer_size.rb +7 -0
  132. data/spec/opal/filters/unsupported/method_added.rb +10 -0
  133. data/spec/opal/filters/unsupported/mutable_strings.rb +299 -1
  134. data/spec/opal/filters/unsupported/private_constants.rb +30 -0
  135. data/spec/opal/filters/unsupported/private_methods.rb +16 -0
  136. data/spec/opal/filters/unsupported/random.rb +4 -0
  137. data/spec/opal/filters/unsupported/tainted.rb +53 -0
  138. data/spec/opal/filters/unsupported/trusted.rb +5 -0
  139. data/spec/opal/rubyspecs +167 -234
  140. data/spec/opal/spec_helper.rb +3 -0
  141. data/spec/opal/stdlib/promise/error_spec.rb +15 -0
  142. data/spec/opal/stdlib/promise/rescue_spec.rb +35 -0
  143. data/spec/opal/stdlib/promise/then_spec.rb +54 -0
  144. data/spec/opal/stdlib/promise/trace_spec.rb +35 -0
  145. data/spec/opal/stdlib/promise/value_spec.rb +15 -0
  146. data/spec/opal/stdlib/promise/when_spec.rb +34 -0
  147. data/stdlib/base64.rb +152 -0
  148. data/stdlib/date.rb +82 -49
  149. data/{opal/corelib → stdlib}/encoding.rb +3 -1
  150. data/stdlib/erb.rb +0 -1
  151. data/stdlib/json.rb +10 -26
  152. data/stdlib/math.rb +370 -0
  153. data/stdlib/native.rb +40 -33
  154. data/stdlib/opal-parser.rb +7 -4
  155. data/stdlib/promise.rb +292 -0
  156. data/stdlib/strscan.rb +1 -1
  157. data/stdlib/template.rb +1 -3
  158. data/stdlib/time.rb +9 -0
  159. metadata +143 -204
  160. data/doc/compiler.md +0 -42
  161. data/doc/compiler_options.md +0 -5
  162. data/doc/examples/node_http_server.rb +0 -49
  163. data/doc/external_libraries.md +0 -9
  164. data/doc/generated_javascript.md +0 -272
  165. data/doc/home.md +0 -17
  166. data/doc/method_missing.md +0 -58
  167. data/doc/static_applications.md +0 -60
  168. data/doc/using_ruby_from_javascript.md +0 -18
  169. data/doc/using_sprockets.md +0 -65
  170. data/spec/opal/core/numeric/abs_spec.rb +0 -12
  171. data/spec/opal/core/numeric/downto_spec.rb +0 -19
  172. data/spec/opal/core/numeric/equal_value_spec.rb +0 -9
  173. data/spec/opal/core/numeric/even_spec.rb +0 -21
  174. data/spec/opal/core/numeric/magnitude_spec.rb +0 -12
  175. data/spec/opal/core/numeric/odd_spec.rb +0 -21
  176. data/spec/opal/core/string/chop_spec.rb +0 -10
  177. data/spec/opal/core/string/chr_spec.rb +0 -13
  178. data/spec/opal/core/string/clone_spec.rb +0 -8
  179. data/spec/opal/core/string/comparison_spec.rb +0 -13
  180. data/spec/opal/core/string/dup_spec.rb +0 -8
  181. data/spec/opal/core/string/element_reference_spec.rb +0 -96
  182. data/spec/opal/core/string/fixtures/classes.rb +0 -49
  183. data/spec/opal/core/string/format_spec.rb +0 -9
  184. data/spec/opal/core/string/freeze_spec.rb +0 -15
  185. data/spec/opal/core/string/gsub_spec.rb +0 -31
  186. data/spec/opal/core/string/lines_spec.rb +0 -9
  187. data/spec/opal/core/string/ljust_spec.rb +0 -32
  188. data/spec/opal/core/string/lstrip_spec.rb +0 -7
  189. data/spec/opal/core/string/match_spec.rb +0 -49
  190. data/spec/opal/core/string/next_spec.rb +0 -10
  191. data/spec/opal/core/string/ord_spec.rb +0 -9
  192. data/spec/opal/core/string/partition_spec.rb +0 -10
  193. data/spec/opal/core/string/rindex_spec.rb +0 -50
  194. data/spec/opal/core/string/rjust_spec.rb +0 -32
  195. data/spec/opal/core/string/rstrip_spec.rb +0 -7
  196. data/spec/opal/core/string/scan_spec.rb +0 -66
  197. data/spec/opal/core/string/slice_spec.rb +0 -74
  198. data/spec/opal/core/string/split_spec.rb +0 -5
  199. data/spec/opal/core/string/strip_spec.rb +0 -6
  200. data/spec/opal/core/string/sub_spec.rb +0 -38
  201. data/spec/opal/core/string/succ_spec.rb +0 -10
  202. data/spec/opal/core/string/sum_spec.rb +0 -5
  203. data/spec/opal/core/string/to_f_spec.rb +0 -14
  204. data/spec/opal/core/string/to_i_spec.rb +0 -25
  205. data/spec/opal/core/string/tr_s_spec.rb +0 -31
  206. data/spec/opal/core/string/tr_spec.rb +0 -31
  207. data/spec/opal/filters/bugs/parser.rb +0 -10
  208. data/spec/opal/filters/unsupported/immutable_strings.rb +0 -24
  209. data/spec/opal/filters/unsupported/string_subclasses.rb +0 -8
  210. data/spec/opal/parser/alias_spec.rb +0 -26
  211. data/spec/opal/parser/and_spec.rb +0 -13
  212. data/spec/opal/parser/array_spec.rb +0 -22
  213. data/spec/opal/parser/attrasgn_spec.rb +0 -28
  214. data/spec/opal/parser/begin_spec.rb +0 -42
  215. data/spec/opal/parser/block_spec.rb +0 -12
  216. data/spec/opal/parser/break_spec.rb +0 -17
  217. data/spec/opal/parser/call_spec.rb +0 -131
  218. data/spec/opal/parser/class_spec.rb +0 -35
  219. data/spec/opal/parser/const_spec.rb +0 -13
  220. data/spec/opal/parser/cvar_spec.rb +0 -11
  221. data/spec/opal/parser/def_spec.rb +0 -61
  222. data/spec/opal/parser/false_spec.rb +0 -17
  223. data/spec/opal/parser/file_spec.rb +0 -7
  224. data/spec/opal/parser/gvar_spec.rb +0 -13
  225. data/spec/opal/parser/hash_spec.rb +0 -17
  226. data/spec/opal/parser/heredoc_spec.rb +0 -30
  227. data/spec/opal/parser/iasgn_spec.rb +0 -9
  228. data/spec/opal/parser/if_spec.rb +0 -26
  229. data/spec/opal/parser/int_spec.rb +0 -13
  230. data/spec/opal/parser/iter_spec.rb +0 -59
  231. data/spec/opal/parser/ivar_spec.rb +0 -9
  232. data/spec/opal/parser/lambda_spec.rb +0 -64
  233. data/spec/opal/parser/lasgn_spec.rb +0 -8
  234. data/spec/opal/parser/line_spec.rb +0 -8
  235. data/spec/opal/parser/lvar_spec.rb +0 -38
  236. data/spec/opal/parser/masgn_spec.rb +0 -37
  237. data/spec/opal/parser/module_spec.rb +0 -27
  238. data/spec/opal/parser/nil_spec.rb +0 -17
  239. data/spec/opal/parser/not_spec.rb +0 -27
  240. data/spec/opal/parser/nth_ref_spec.rb +0 -13
  241. data/spec/opal/parser/op_asgn1_spec.rb +0 -23
  242. data/spec/opal/parser/op_asgn2_spec.rb +0 -23
  243. data/spec/opal/parser/or_spec.rb +0 -13
  244. data/spec/opal/parser/parse_spec.rb +0 -66
  245. data/spec/opal/parser/regexp_spec.rb +0 -16
  246. data/spec/opal/parser/return_spec.rb +0 -17
  247. data/spec/opal/parser/sclass_spec.rb +0 -21
  248. data/spec/opal/parser/self_spec.rb +0 -17
  249. data/spec/opal/parser/str_spec.rb +0 -107
  250. data/spec/opal/parser/string_spec.rb +0 -8
  251. data/spec/opal/parser/super_spec.rb +0 -20
  252. data/spec/opal/parser/true_spec.rb +0 -17
  253. data/spec/opal/parser/undef_spec.rb +0 -15
  254. data/spec/opal/parser/unless_spec.rb +0 -13
  255. data/spec/opal/parser/while_spec.rb +0 -15
  256. data/spec/opal/parser/xstr_spec.rb +0 -116
  257. data/spec/opal/parser/yield_spec.rb +0 -20
@@ -1,38 +0,0 @@
1
- describe "String#sub with pattern, replacement" do
2
- it "returns a copy of self with all occurrences of pattern replaced with replacement" do
3
- "hello".sub(/[aeiou]/, '*').should == "h*llo"
4
- "hello".sub(//, ".").should == ".hello"
5
- end
6
-
7
- it "ignores a block if supplied" do
8
- "food".sub(/f/, "g") { "w" }.should == "good"
9
- end
10
-
11
- it "supports /i for ignoring case" do
12
- "Hello".sub(/h/i, "j").should == "jello"
13
- "hello".sub(/H/i, "j").should == "jello"
14
- end
15
-
16
- it "converts and supports back references in replacement string" do
17
- "javascript".sub(/(j).*(s).*/, '.\\1\\2').should == '.js'
18
- end
19
- end
20
-
21
- describe "String#sub with pattern and block" do
22
- it "returns a copy of self with the first occurences of pattern replaces with block's return value" do
23
- "hi".sub(/./) { |s| s + ' ' }.should == "h i"
24
- "hi!".sub(/(.)(.)/) { |*a| a.inspect }.should == '["hi"]!'
25
- end
26
-
27
- it "should set the global match variable $~ inside block" do
28
- match_datas = []
29
- "hello".sub(/(.)./) { match_datas << $~; $~[1].succ }.should == "illo"
30
- match_datas.length.should == 1
31
- match_datas[0].length.should == 2
32
- match_datas[0].should == ["he", "h"]
33
- end
34
-
35
- it "should set the global match variable $& inside block" do
36
- "hello".sub(/./) { "#{$&} " }.should == "h ello"
37
- end
38
- end
@@ -1,10 +0,0 @@
1
- describe "String#succ" do
2
- it "returns an empty string for empty strings" do
3
- "".succ.should == ""
4
- end
5
-
6
- it "returns the successor by increasing the rightmost alphanumeric" do
7
- "abcd".succ.should == "abce"
8
- "THX1138".succ.should == "THX1139"
9
- end
10
- end
@@ -1,5 +0,0 @@
1
- describe "String#sum" do
2
- it "returns a basic n-bit checksum of the characters in self" do
3
- "ruby".sum.should == 450
4
- end
5
- end
@@ -1,14 +0,0 @@
1
- describe "String#to_f" do
2
- it "treats leading characters of self as a floating point number" do
3
- "45.67 degress".to_f.should == 45.67
4
- "0".to_f.should == 0.0
5
-
6
- ".5".to_f.should == 0.5
7
- "5e".to_f.should == 5.0
8
- "5E".to_f.should == 5.0
9
- end
10
-
11
- it "treats special float value strings as characters" do
12
- "NaN".to_f.should == 0
13
- end
14
- end
@@ -1,25 +0,0 @@
1
- describe "String#to_i" do
2
- it "returns 0 for strings with leading underscores" do
3
- "_123".to_i.should == 0
4
- end
5
-
6
- it "ignores subsequent invalid characters" do
7
- "123asdf".to_i.should == 123
8
- "123#123".to_i.should == 123
9
- "123 456".to_i.should == 123
10
- end
11
-
12
- it "interprets leading characters as a number in the given base" do
13
- "10110010010".to_i(2).should == 1426
14
- "100110201001".to_i(3).should == 186409
15
- "103110201001".to_i(4).should == 5064769
16
- "103110241001".to_i(5).should == 55165126
17
- "153110241001".to_i(6).should == 697341529
18
- "153160241001".to_i(7).should == 3521513430
19
- "153160241701".to_i(8).should == 14390739905
20
- "853160241701".to_i(9).should == 269716550518
21
- "853160241791".to_i(10).should == 853160241791
22
-
23
- "5e10".to_i.should == 5
24
- end
25
- end
@@ -1,31 +0,0 @@
1
- describe "String#tr_s" do
2
- it "replaces occurrences of character with substitute, dropping repeating substitutes" do
3
- # identity checks (no substitution)
4
- 'abc'.tr_s('', 'a').should == 'abc'
5
- 'aabbcc'.tr_s('', 'a').should == 'aabbcc'
6
-
7
- # single char substitutions
8
- 'a'.tr_s('a', 'b').should == 'b'
9
- 'aa'.tr_s('a', 'b').should == 'b'
10
- 'bbabcbb'.tr_s('b', 'z').should == 'zazcz'
11
- 'hello'.tr_s('l', 'r').should == 'hero'
12
-
13
- # multiple char substitutions
14
- 'aabbcc'.tr_s('abc', 'abc').should == 'abc'
15
- 'hello'.tr_s('el', '*').should == 'h*o'
16
- 'hello'.tr_s('el', 'hx').should == 'hhxo'
17
-
18
- # inverted substitutions
19
- 'hello'.tr_s('^aeiou', '*').should == '*e*o'
20
-
21
- # range substitutions
22
- 'abc'.tr_s('a-c', '*').should == '*'
23
- 'hello'.tr_s('e-lo', 'rb').should == 'brb'
24
- 'hello'.tr_s('a-y', 'b-z').should == 'ifmp'
25
-
26
- # truncation
27
- 'abcd'.tr_s('a', '').should == 'bcd'
28
- 'abcd'.tr_s('abc', '').should == 'd'
29
- 'abcd'.tr_s('b-d', '').should == 'a'
30
- end
31
- end
@@ -1,31 +0,0 @@
1
- describe "String#tr" do
2
- it "replaces occurances of character with substitute" do
3
- # identity checks (no substitution)
4
- 'abc'.tr('', 'z').should == 'abc'
5
- 'abc'.tr('a', 'a').should == 'abc'
6
- 'abc'.tr('a', 'az').should == 'abc'
7
-
8
- # single char substitutions
9
- 'a'.tr('a', 'b').should == 'b'
10
- 'aa'.tr('a', 'b').should == 'bb'
11
- 'abc'.tr('b', 'z').should == 'azc'
12
- 'hello'.tr('e', 'ip').should == 'hillo'
13
-
14
- # multiple char substitutions
15
- 'hello'.tr('el', 'ip').should == 'hippo'
16
- 'hello'.tr('aeiou', '*').should == 'h*ll*'
17
-
18
- # inverted substitutions
19
- 'hello'.tr('^aeiou', '*').should == '*e**o'
20
-
21
- # range substitutions
22
- 'abc'.tr('a-c', '*').should == '***'
23
- 'hello'.tr('e-lo', 'ab').should == 'babbb'
24
- 'hello'.tr('a-y', 'b-z').should == 'ifmmp'
25
-
26
- # truncation
27
- 'abcd'.tr('a', '').should == 'bcd'
28
- 'abcd'.tr('abc', '').should == 'd'
29
- 'abcd'.tr('b-d', '').should == 'a'
30
- end
31
- end
@@ -1,10 +0,0 @@
1
- opal_filter "Opal::Parser" do
2
- fails "Singleton classes returns an empty s(:scope) when given an empty body"
3
- fails "Singleton classes should accept any expressions for singleton part"
4
- fails "Strings from %Q construction should match '{' and '}' pairs used to start string before ending match"
5
- fails "Strings from %Q construction should match '(' and ')' pairs used to start string before ending match"
6
- fails "Strings from %Q construction should match '[' and ']' pairs used to start string before ending match"
7
- fails "x-strings created using %x notation should match '{' and '}' pairs used to start string before ending match"
8
- fails "x-strings created using %x notation should match '(' and ')' pairs used to start string before ending match"
9
- fails "x-strings created using %x notation should match '[' and ']' pairs used to start string before ending match"
10
- end
@@ -1,24 +0,0 @@
1
- opal_filter "immutable strings" do
2
- fails "Array#fill does not replicate the filler"
3
-
4
- fails "Hash literal freezes string keys on initialization"
5
-
6
- fails "Time#strftime formats time according to the directives in the given format string"
7
- fails "Time#strftime with %z formats a local time with positive UTC offset as '+HHMM'"
8
- fails "Time#strftime with %z formats a local time with negative UTC offset as '-HHMM'"
9
-
10
- fails "String#chomp when passed no argument returns a copy of the String when it is not modified"
11
-
12
- fails "String#chop returns a new string when applied to an empty string"
13
-
14
- fails "String#chop! removes the final character"
15
- fails "String#chop! removes the final carriage return"
16
- fails "String#chop! removes the final newline"
17
- fails "String#chop! removes the final carriage return, newline"
18
- fails "String#chop! removes the carrige return, newline if they are the only characters"
19
- fails "String#chop! does not remove more than the final carriage return, newline"
20
- fails "String#chop! returns self if modifications were made"
21
- fails "String#chop! returns nil when called on an empty string"
22
- fails "String#chop! raises a RuntimeError on a frozen instance that is modified"
23
- fails "String#chop! raises a RuntimeError on a frozen instance that would not be modified"
24
- end
@@ -1,8 +0,0 @@
1
- opal_filter "String subclasses" do
2
- fails "String#upcase returns a subclass instance for subclasses"
3
- fails "String#swapcase returns subclass instances when called on a subclass"
4
- fails "String#downcase returns a subclass instance for subclasses"
5
- fails "String#capitalize returns subclass instances when called on a subclass"
6
- fails "String#center with length, padding returns subclass instances when called on subclasses"
7
- fails "String#chomp when passed no argument returns subclass instances when called on a subclass"
8
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "The alias keyword" do
4
- describe "with fitem" do
5
- it "should return an s(:alias) with s(:sym)" do
6
- opal_parse("alias a b").should == [:alias, [:sym, :a], [:sym, :b]]
7
- opal_parse("alias == equals").should == [:alias, [:sym, :==], [:sym, :equals]]
8
- end
9
-
10
- it "should accept symbols as names" do
11
- opal_parse("alias :foo :bar").should == [:alias, [:sym, :foo], [:sym, :bar]]
12
- end
13
- end
14
-
15
- describe "with gvar" do
16
- it "should return a s(:valias) with two gvars as arguments" do
17
- opal_parse("alias $foo $bar").should == [:valias, :$foo, :$bar]
18
- end
19
- end
20
-
21
- describe "with gvar and nth ref" do
22
- it "should return a s(:valias) with two values as arguments" do
23
- opal_parse("alias $foo $1").should == [:valias, :$foo, :"1"]
24
- end
25
- end
26
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "The and statement" do
4
- it "should always return s(:and)" do
5
- opal_parse("1 and 2").should == [:and, [:int, 1], [:int, 2]]
6
- end
7
- end
8
-
9
- describe "The && expression" do
10
- it "should always return s(:and)" do
11
- opal_parse("1 && 2").should == [:and, [:int, 1], [:int, 2]]
12
- end
13
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Arrays" do
4
- it "should parse empty arrays as s(:array)" do
5
- opal_parse("[]").should == [:array]
6
- end
7
-
8
- it "should append regular args onto end of array sexp" do
9
- opal_parse("[1]").should == [:array, [:int, 1]]
10
- opal_parse("[1, 2]").should == [:array, [:int, 1], [:int, 2]]
11
- opal_parse("[1, 2, 3]").should == [:array, [:int, 1], [:int, 2], [:int, 3]]
12
- end
13
-
14
- it "should return a single item s(:array) with given splat if no norm args" do
15
- opal_parse("[*1]").should == [:array, [:splat, [:int, 1]]]
16
- end
17
-
18
- it "should allow splats combined with any number of norm args" do
19
- opal_parse("[1, *2]").should == [:array, [:int, 1], [:splat, [:int, 2]]]
20
- opal_parse("[1, 2, *3]").should == [:array, [:int, 1], [:int, 2], [:splat, [:int, 3]]]
21
- end
22
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Attribute assignments" do
4
- it "should return a s(:attrasgn) for simple assignments" do
5
- opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
6
- opal_parse('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:int, 1]]]
7
- opal_parse('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:int, 1]]]
8
- end
9
-
10
- it "accepts both '.' and '::' for method call operators" do
11
- opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
12
- opal_parse('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
13
- end
14
-
15
- it "can accept a constant as assignable name when using '.'" do
16
- opal_parse('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:int, 1]]]
17
- end
18
-
19
- describe "when setting element reference" do
20
- it "uses []= as the method call" do
21
- opal_parse('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2]]]
22
- end
23
-
24
- it "supports multiple arguments inside brackets" do
25
- opal_parse('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2], [:int, 3]]]
26
- end
27
- end
28
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "The begin keyword" do
4
- it "should be removed when used without a resuce or enusre body" do
5
- opal_parse('begin; 1; end').should == [:int, 1]
6
- opal_parse('begin; 1; 2; end').should == [:block, [:int, 1], [:int, 2]]
7
- end
8
-
9
- describe "with 'rescue' bodies" do
10
- it "should create a s(:rescue) sexp" do
11
- opal_parse('begin; 1; rescue; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
12
- end
13
-
14
- it "allows multiple rescue bodies" do
15
- opal_parse('begin 1; rescue; 2; rescue; 3; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]], [:resbody, [:array], [:int, 3]]]
16
- end
17
-
18
- it "accepts a list of classes used to match against the exception" do
19
- opal_parse('begin 1; rescue Klass; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass]], [:int, 2]]]
20
- end
21
-
22
- it "accepts an identifier to assign exception to" do
23
- opal_parse('begin 1; rescue => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
24
- opal_parse('begin 1; rescue Klass => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
25
- end
26
-
27
- it "accepts an ivar to assign exception to" do
28
- opal_parse('begin 1; rescue => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
29
- opal_parse('begin 1; rescue Klass => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
30
- end
31
-
32
- it "should parse newline right after rescue" do
33
- opal_parse("begin; 1; rescue\n 2; end").should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
34
- end
35
- end
36
-
37
- describe "with an 'ensure' block" do
38
- it "should propagate into single s(:ensure) statement when no rescue block given" do
39
- opal_parse('begin; 1; ensure; 2; end').should == [:ensure, [:int, 1], [:int, 2]]
40
- end
41
- end
42
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Block statements" do
4
- it "should return the direct expression if only one expresssion in block" do
5
- opal_parse("42").should == [:int, 42]
6
- end
7
-
8
- it "should return an s(:block) with all expressions appended for > 1 expression" do
9
- opal_parse("42; 43").should == [:block, [:int, 42], [:int, 43]]
10
- opal_parse("42; 43\n44").should == [:block, [:int, 42], [:int, 43], [:int, 44]]
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "The break keyword" do
4
- it "should return s(:break) when given no args" do
5
- opal_parse("break").should == [:break]
6
- end
7
-
8
- it "returns s(:break) with a single arg not wrapped in s(:array)" do
9
- opal_parse("break 1").should == [:break, [:int, 1]]
10
- opal_parse("break *1").should == [:break, [:splat, [:int, 1]]]
11
- end
12
-
13
- it "returns s(:break) with an s(:array) for args size > 1" do
14
- opal_parse("break 1, 2").should == [:break, [:array, [:int, 1], [:int, 2]]]
15
- opal_parse("break 1, *2").should == [:break, [:array, [:int, 1], [:splat, [:int, 2]]]]
16
- end
17
- end
@@ -1,131 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Method calls" do
4
- it "should use 'nil' for calls without a receiver" do
5
- opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
6
- opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
7
- end
8
-
9
- it "should always have an arglist when not passed any arguments" do
10
- opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
11
- opal_parse("self.foo").should == [:call, [:self], :foo, [:arglist]]
12
- opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
13
- opal_parse("self.foo()").should == [:call, [:self], :foo, [:arglist]]
14
- end
15
-
16
- it "appends all arguments onto arglist" do
17
- opal_parse("foo 1").should == [:call, nil, :foo, [:arglist, [:int, 1]]]
18
- opal_parse("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:int, 2]]]
19
- opal_parse("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:splat, [:int, 2]]]]
20
- end
21
-
22
- it "supports leading dots on newline" do
23
- opal_parse("foo\n.bar").should == [:call, [:call, nil, :foo, [:arglist]], :bar, [:arglist]]
24
- lambda { opal_parse("foo\n..bar") }.should raise_error(Exception)
25
- end
26
- end
27
-
28
- describe "Operator calls" do
29
- it "should parse all other operators into method calls" do
30
- opal_parse("1 % 2").should == [:call, [:int, 1], :%, [:arglist, [:int, 2]]]
31
- opal_parse("1 ** 2").should == [:call, [:int, 1], :**, [:arglist, [:int, 2]]]
32
-
33
- opal_parse("+self").should == [:call, [:self], :+@, [:arglist]]
34
- opal_parse("-self").should == [:call, [:self], :-@, [:arglist]]
35
-
36
- opal_parse("1 | 2").should == [:call, [:int, 1], :|, [:arglist, [:int, 2]]]
37
- opal_parse("1 ^ 2").should == [:call, [:int, 1], :^, [:arglist, [:int, 2]]]
38
- opal_parse("1 & 2").should == [:call, [:int, 1], :&, [:arglist, [:int, 2]]]
39
- opal_parse("1 <=> 2").should == [:call, [:int, 1], :<=>, [:arglist, [:int, 2]]]
40
-
41
- opal_parse("1 < 2").should == [:call, [:int, 1], :<, [:arglist, [:int, 2]]]
42
- opal_parse("1 <= 2").should == [:call, [:int, 1], :<=, [:arglist, [:int, 2]]]
43
- opal_parse("1 > 2").should == [:call, [:int, 1], :>, [:arglist, [:int, 2]]]
44
- opal_parse("1 >= 2").should == [:call, [:int, 1], :>=, [:arglist, [:int, 2]]]
45
-
46
- opal_parse("1 == 2").should == [:call, [:int, 1], :==, [:arglist, [:int, 2]]]
47
- opal_parse("1 === 2").should == [:call, [:int, 1], :===, [:arglist, [:int, 2]]]
48
- opal_parse("1 =~ 2").should == [:call, [:int, 1], :=~, [:arglist, [:int, 2]]]
49
-
50
- opal_parse("~1").should == [:call, [:int, 1], :~, [:arglist]]
51
- opal_parse("1 << 2").should == [:call, [:int, 1], :<<, [:arglist, [:int, 2]]]
52
- opal_parse("1 >> 2").should == [:call, [:int, 1], :>>, [:arglist, [:int, 2]]]
53
- end
54
-
55
- it "optimizes +@ and -@ on numerics" do
56
- opal_parse("+1").should == [:int, 1]
57
- opal_parse("-1").should == [:int, -1]
58
- end
59
- end
60
-
61
- describe "Optional paren calls" do
62
- it "should correctly parse - and -@" do
63
- opal_parse("x - 1").should == [:call, [:call, nil, :x, [:arglist]], :-, [:arglist, [:int, 1]]]
64
- opal_parse("x -1").should == [:call, nil, :x, [:arglist, [:int, -1]]]
65
- end
66
-
67
- it "should correctly parse + and +@" do
68
- opal_parse("x + 1").should == [:call, [:call, nil, :x, [:arglist]], :+, [:arglist, [:int, 1]]]
69
- opal_parse("x +1").should == [:call, nil, :x, [:arglist, [:int, 1]]]
70
- end
71
-
72
- it "should correctly parse / and regexps" do
73
- opal_parse("x / 500").should == [:call, [:call, nil, :x, [:arglist]], :/, [:arglist, [:int, 500]]]
74
- opal_parse("x /foo/").should == [:call, nil, :x, [:arglist, [:regexp, /foo/]]]
75
- end
76
-
77
- it "should parse LPAREN_ARG correctly" do
78
- opal_parse("x (1).y").should == [:call, nil, :x, [:arglist, [:call, [:int, 1], :y, [:arglist]]]]
79
- opal_parse("x(1).y").should == [:call, [:call, nil, :x, [:arglist, [:int, 1]]], :y, [:arglist]]
80
- end
81
- end
82
-
83
- describe "Operator precedence" do
84
- it "should be raised with parentheses" do
85
- opal_parse("(1 + 2) + (3 - 4)").should == [:call,
86
- [:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
87
- :+,
88
- [:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
89
- ]
90
- opal_parse("(1 + 2) - (3 - 4)").should == [:call,
91
- [:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
92
- :-,
93
- [:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
94
- ]
95
- opal_parse("(1 + 2) * (3 - 4)").should == [:call,
96
- [:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
97
- :*,
98
- [:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
99
- ]
100
- opal_parse("(1 + 2) / (3 - 4)").should == [:call,
101
- [:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
102
- :/,
103
- [:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
104
- ]
105
- end
106
- end
107
-
108
- describe "Calls with keywords as method names" do
109
-
110
- keywords = %w[class module defined? def undef end do if unless else elsif self true false
111
- nil __LINE__ __FILE__ begin rescue ensure case when or and not return next
112
- redo break super then while until yield alias]
113
-
114
- it "should correctly parse the keyword as a method name when after a '.'" do
115
- keywords.each do |kw|
116
- opal_parse("self.#{kw}").should == [:call, [:self], kw.to_sym, [:arglist]]
117
- end
118
- end
119
- end
120
-
121
- describe "Calls with operators as method names" do
122
- operators = %w[+ - * / & ** | ^ & <=> > >= < <= << >>]
123
-
124
- it "should correctly parse the operator as method name after '.'" do
125
- operators.each do |op|
126
- opal_parse("self.#{op}").should == [:call, [:self], op.to_sym, [:arglist]]
127
- opal_parse("self.#{op}(1)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1]]]
128
- opal_parse("self.#{op}(1, 2)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1], [:int, 2]]]
129
- end
130
- end
131
- end