opal 0.8.1 → 0.9.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (331) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.gitmodules +3 -3
  4. data/.jshintrc +17 -20
  5. data/.travis.yml +22 -11
  6. data/CHANGELOG.md +51 -1
  7. data/CODE_OF_CONDUCT.md +15 -0
  8. data/CONTRIBUTING.md +125 -9
  9. data/Gemfile +1 -1
  10. data/Guardfile +2 -2
  11. data/README.md +95 -29
  12. data/Rakefile +1 -1
  13. data/benchmark/benchmarks +103 -0
  14. data/benchmark/bm_array_flatten.rb +9 -0
  15. data/benchmark/bm_array_intersection_numbers.rb +7 -0
  16. data/benchmark/bm_array_intersection_objects.rb +7 -0
  17. data/benchmark/bm_array_intersection_strings.rb +7 -0
  18. data/benchmark/bm_array_join_ary.rb +9 -0
  19. data/benchmark/bm_array_minus_numbers.rb +7 -0
  20. data/benchmark/bm_array_minus_objects.rb +7 -0
  21. data/benchmark/bm_array_minus_strings.rb +7 -0
  22. data/benchmark/bm_array_union_numbers.rb +7 -0
  23. data/benchmark/bm_array_union_objects.rb +7 -0
  24. data/benchmark/bm_array_union_strings.rb +7 -0
  25. data/benchmark/bm_array_uniq_bang_numbers.rb +5 -0
  26. data/benchmark/bm_array_uniq_bang_objects.rb +5 -0
  27. data/benchmark/bm_array_uniq_bang_strings.rb +5 -0
  28. data/benchmark/bm_array_uniq_numbers.rb +5 -0
  29. data/benchmark/bm_array_uniq_objects.rb +5 -0
  30. data/benchmark/bm_array_uniq_strings.rb +5 -0
  31. data/benchmark/bm_dispatch_bind_table.rb +57 -0
  32. data/benchmark/bm_dispatch_code_gen.rb +65 -0
  33. data/benchmark/bm_dispatch_code_gen_if.rb +64 -0
  34. data/benchmark/bm_dispatch_hardcoded.rb +44 -0
  35. data/benchmark/bm_dispatch_send.rb +38 -0
  36. data/benchmark/bm_dispatch_send_table.rb +57 -0
  37. data/benchmark/bm_hash_assoc_object.rb +11 -0
  38. data/benchmark/bm_hash_assoc_string.rb +9 -0
  39. data/benchmark/bm_hash_clone_object.rb +9 -0
  40. data/benchmark/bm_hash_clone_string.rb +9 -0
  41. data/benchmark/bm_hash_delete_object.rb +11 -0
  42. data/benchmark/bm_hash_delete_string.rb +9 -0
  43. data/benchmark/bm_hash_each_key_object.rb +9 -0
  44. data/benchmark/bm_hash_each_key_string.rb +9 -0
  45. data/benchmark/bm_hash_each_object.rb +9 -0
  46. data/benchmark/bm_hash_each_string.rb +9 -0
  47. data/benchmark/bm_hash_each_value_object.rb +9 -0
  48. data/benchmark/bm_hash_each_value_string.rb +9 -0
  49. data/benchmark/bm_hash_element_reference_object.rb +11 -0
  50. data/benchmark/bm_hash_element_reference_string.rb +9 -0
  51. data/benchmark/bm_hash_element_set_object.rb +5 -0
  52. data/benchmark/bm_hash_element_set_string.rb +5 -0
  53. data/benchmark/bm_hash_equal_value_object.rb +14 -0
  54. data/benchmark/bm_hash_equal_value_string.rb +11 -0
  55. data/benchmark/bm_hash_fetch_object.rb +11 -0
  56. data/benchmark/bm_hash_fetch_string.rb +9 -0
  57. data/benchmark/bm_hash_flatten_object.rb +9 -0
  58. data/benchmark/bm_hash_flatten_string.rb +9 -0
  59. data/benchmark/bm_hash_has_key_object.rb +11 -0
  60. data/benchmark/bm_hash_has_key_string.rb +9 -0
  61. data/benchmark/bm_hash_has_value_object.rb +9 -0
  62. data/benchmark/bm_hash_has_value_string.rb +9 -0
  63. data/benchmark/bm_hash_hash_object.rb +9 -0
  64. data/benchmark/bm_hash_hash_string.rb +9 -0
  65. data/benchmark/bm_hash_inspect_object.rb +9 -0
  66. data/benchmark/bm_hash_inspect_string.rb +9 -0
  67. data/benchmark/bm_hash_invert_object.rb +9 -0
  68. data/benchmark/bm_hash_invert_string.rb +9 -0
  69. data/benchmark/bm_hash_keep_if_object.rb +9 -0
  70. data/benchmark/bm_hash_keep_if_string.rb +9 -0
  71. data/benchmark/bm_hash_key_object.rb +9 -0
  72. data/benchmark/bm_hash_key_string.rb +9 -0
  73. data/benchmark/bm_hash_keys_object.rb +9 -0
  74. data/benchmark/bm_hash_keys_string.rb +9 -0
  75. data/benchmark/bm_hash_literal_mixed_large.rb +3 -0
  76. data/benchmark/bm_hash_literal_mixed_small.rb +3 -0
  77. data/benchmark/bm_hash_literal_object_large.rb +4 -0
  78. data/benchmark/bm_hash_literal_object_small.rb +3 -0
  79. data/benchmark/bm_hash_literal_string_large.rb +4 -0
  80. data/benchmark/bm_hash_literal_string_small.rb +3 -0
  81. data/benchmark/bm_hash_merge_object.rb +22 -0
  82. data/benchmark/bm_hash_merge_string.rb +18 -0
  83. data/benchmark/bm_hash_rassoc_object.rb +9 -0
  84. data/benchmark/bm_hash_rassoc_string.rb +9 -0
  85. data/benchmark/bm_hash_rehash_object.rb +9 -0
  86. data/benchmark/bm_hash_rehash_string.rb +9 -0
  87. data/benchmark/bm_hash_reject_bang_object.rb +9 -0
  88. data/benchmark/bm_hash_reject_bang_string.rb +9 -0
  89. data/benchmark/bm_hash_reject_object.rb +9 -0
  90. data/benchmark/bm_hash_reject_string.rb +9 -0
  91. data/benchmark/bm_hash_replace_object.rb +18 -0
  92. data/benchmark/bm_hash_replace_string.rb +14 -0
  93. data/benchmark/bm_hash_select_bang_object.rb +9 -0
  94. data/benchmark/bm_hash_select_bang_string.rb +9 -0
  95. data/benchmark/bm_hash_select_object.rb +9 -0
  96. data/benchmark/bm_hash_select_string.rb +9 -0
  97. data/benchmark/bm_hash_shift_object.rb +10 -0
  98. data/benchmark/bm_hash_shift_string.rb +10 -0
  99. data/benchmark/bm_hash_to_a_object.rb +9 -0
  100. data/benchmark/bm_hash_to_a_string.rb +9 -0
  101. data/benchmark/bm_hash_to_h_object.rb +10 -0
  102. data/benchmark/bm_hash_to_h_string.rb +10 -0
  103. data/benchmark/bm_hash_values_object.rb +9 -0
  104. data/benchmark/bm_hash_values_string.rb +9 -0
  105. data/benchmark/run.rb +48 -0
  106. data/bin/opal-mspec +1 -1
  107. data/bin/opal-repl +4 -4
  108. data/docs/compiled_ruby.md +214 -56
  109. data/docs/configuring_gems.md +2 -2
  110. data/docs/faq.md +2 -2
  111. data/docs/getting_started.md +19 -2
  112. data/docs/jquery.md +5 -5
  113. data/docs/opal_parser.md +53 -0
  114. data/docs/unsupported_features.md +2 -2
  115. data/docs/upgrading.md +22 -0
  116. data/docs/using_sprockets.md +15 -0
  117. data/examples/rack/config.ru +13 -0
  118. data/examples/sinatra/config.ru +4 -5
  119. data/lib/mspec/opal/runner.rb +54 -11
  120. data/lib/opal.rb +1 -1
  121. data/lib/opal/builder.rb +1 -1
  122. data/lib/opal/builder_processors.rb +1 -1
  123. data/lib/opal/cli.rb +17 -13
  124. data/lib/opal/cli_options.rb +1 -1
  125. data/lib/opal/compiler.rb +12 -0
  126. data/lib/opal/config.rb +4 -0
  127. data/lib/opal/nodes/arglist.rb +5 -7
  128. data/lib/opal/nodes/call.rb +6 -1
  129. data/lib/opal/nodes/call_special.rb +74 -0
  130. data/lib/opal/nodes/def.rb +35 -28
  131. data/lib/opal/nodes/definitions.rb +3 -5
  132. data/lib/opal/nodes/for.rb +13 -0
  133. data/lib/opal/nodes/helpers.rb +15 -1
  134. data/lib/opal/nodes/if.rb +5 -5
  135. data/lib/opal/nodes/iter.rb +6 -1
  136. data/lib/opal/nodes/literal.rb +1 -1
  137. data/lib/opal/nodes/logic.rb +2 -2
  138. data/lib/opal/nodes/masgn.rb +1 -2
  139. data/lib/opal/nodes/module.rb +2 -1
  140. data/lib/opal/nodes/rescue.rb +10 -1
  141. data/lib/opal/nodes/scope.rb +8 -2
  142. data/lib/opal/nodes/singleton_class.rb +1 -1
  143. data/lib/opal/nodes/top.rb +11 -0
  144. data/lib/opal/nodes/variables.rb +4 -4
  145. data/lib/opal/parser.rb +21 -3
  146. data/lib/opal/parser/grammar.rb +3115 -2961
  147. data/lib/opal/parser/grammar.y +29 -6
  148. data/lib/opal/parser/lexer.rb +18 -8
  149. data/lib/opal/sprockets.rb +85 -0
  150. data/lib/opal/sprockets/processor.rb +11 -35
  151. data/lib/opal/sprockets/server.rb +3 -15
  152. data/lib/opal/version.rb +2 -2
  153. data/opal.gemspec +4 -4
  154. data/opal/README.md +9 -0
  155. data/opal/corelib/array.rb +433 -181
  156. data/opal/corelib/basic_object.rb +48 -4
  157. data/opal/corelib/boolean.rb +15 -6
  158. data/opal/corelib/class.rb +6 -5
  159. data/opal/corelib/comparable.rb +12 -0
  160. data/opal/corelib/complex.rb +282 -0
  161. data/opal/corelib/constants.rb +9 -0
  162. data/opal/corelib/enumerable.rb +83 -34
  163. data/opal/corelib/enumerator.rb +3 -1
  164. data/opal/corelib/error.rb +49 -10
  165. data/opal/corelib/file.rb +1 -0
  166. data/opal/corelib/hash.rb +353 -577
  167. data/opal/corelib/helpers.rb +20 -0
  168. data/opal/corelib/kernel.rb +114 -59
  169. data/opal/corelib/math.rb +470 -0
  170. data/opal/corelib/method.rb +11 -2
  171. data/opal/corelib/module.rb +96 -96
  172. data/opal/corelib/{nil_class.rb → nil.rb} +20 -1
  173. data/opal/corelib/number.rb +751 -0
  174. data/opal/corelib/numeric.rb +77 -437
  175. data/opal/corelib/proc.rb +81 -1
  176. data/opal/corelib/process.rb +27 -0
  177. data/opal/corelib/rational.rb +358 -0
  178. data/opal/corelib/regexp.rb +156 -27
  179. data/opal/corelib/runtime.js +724 -335
  180. data/opal/corelib/string.rb +93 -104
  181. data/opal/corelib/string/encoding.rb +177 -0
  182. data/opal/corelib/string/inheritance.rb +2 -0
  183. data/opal/corelib/struct.rb +105 -18
  184. data/opal/corelib/time.rb +267 -146
  185. data/opal/corelib/unsupported.rb +216 -0
  186. data/opal/corelib/variables.rb +0 -6
  187. data/opal/opal.rb +8 -22
  188. data/opal/opal/base.rb +9 -0
  189. data/opal/opal/mini.rb +17 -0
  190. data/spec/README.md +1 -1
  191. data/spec/filters/bugs/array.rb +38 -136
  192. data/spec/filters/bugs/{basic_object.rb → basicobject.rb} +14 -15
  193. data/spec/filters/bugs/class.rb +6 -12
  194. data/spec/filters/bugs/complex.rb +3 -0
  195. data/spec/filters/bugs/date.rb +162 -10
  196. data/spec/filters/bugs/enumerable.rb +31 -58
  197. data/spec/filters/bugs/enumerator.rb +42 -0
  198. data/spec/filters/bugs/exception.rb +66 -10
  199. data/spec/filters/bugs/float.rb +17 -0
  200. data/spec/filters/bugs/hash.rb +11 -97
  201. data/spec/filters/bugs/inheritance.rb +5 -0
  202. data/spec/filters/bugs/integer.rb +28 -0
  203. data/spec/filters/bugs/kernel.rb +304 -12
  204. data/spec/filters/bugs/language.rb +133 -399
  205. data/spec/filters/bugs/language_opal.rb +88 -0
  206. data/spec/filters/bugs/module.rb +203 -62
  207. data/spec/filters/bugs/numeric.rb +32 -0
  208. data/spec/filters/bugs/proc.rb +39 -0
  209. data/spec/filters/bugs/range.rb +148 -0
  210. data/spec/filters/bugs/regexp.rb +168 -0
  211. data/spec/filters/bugs/set.rb +46 -3
  212. data/spec/filters/bugs/singleton.rb +1 -2
  213. data/spec/filters/bugs/string.rb +59 -90
  214. data/spec/filters/bugs/strscan.rb +80 -0
  215. data/spec/filters/bugs/struct.rb +10 -20
  216. data/spec/filters/bugs/time.rb +17 -184
  217. data/spec/filters/bugs/unboundmethod.rb +22 -0
  218. data/spec/filters/unsupported/array.rb +163 -0
  219. data/spec/filters/unsupported/basicobject.rb +14 -0
  220. data/spec/filters/unsupported/bignum.rb +46 -0
  221. data/spec/filters/unsupported/class.rb +4 -0
  222. data/spec/filters/unsupported/delegator.rb +5 -0
  223. data/spec/filters/unsupported/enumerable.rb +11 -0
  224. data/spec/filters/unsupported/enumerator.rb +8 -9
  225. data/spec/filters/unsupported/fixnum.rb +14 -0
  226. data/spec/filters/unsupported/float.rb +41 -7
  227. data/spec/filters/unsupported/freeze.rb +45 -0
  228. data/spec/filters/unsupported/hash.rb +50 -0
  229. data/spec/filters/unsupported/integer.rb +3 -0
  230. data/spec/filters/unsupported/kernel.rb +31 -0
  231. data/spec/filters/unsupported/language.rb +17 -0
  232. data/spec/filters/unsupported/matchdata.rb +30 -0
  233. data/spec/filters/unsupported/math.rb +3 -0
  234. data/spec/filters/unsupported/module.rb +5 -3
  235. data/spec/filters/unsupported/pathname.rb +3 -0
  236. data/spec/filters/unsupported/privacy.rb +136 -0
  237. data/spec/filters/unsupported/proc.rb +3 -0
  238. data/spec/filters/unsupported/regexp.rb +59 -0
  239. data/spec/filters/unsupported/set.rb +4 -0
  240. data/spec/filters/unsupported/{marshal.rb → singleton.rb} +4 -2
  241. data/spec/filters/unsupported/{mutable_strings.rb → string.rb} +456 -336
  242. data/spec/filters/unsupported/struct.rb +3 -0
  243. data/spec/filters/unsupported/symbol.rb +5 -0
  244. data/spec/filters/unsupported/taint.rb +16 -0
  245. data/spec/filters/unsupported/thread.rb +5 -0
  246. data/spec/filters/unsupported/time.rb +197 -16
  247. data/spec/lib/cli_spec.rb +14 -4
  248. data/spec/lib/compiler_spec.rb +9 -1
  249. data/spec/lib/parser/call_spec.rb +18 -0
  250. data/spec/lib/parser/not_spec.rb +2 -8
  251. data/spec/lib/sprockets_spec.rb +24 -0
  252. data/spec/opal/core/array/intersection_spec.rb +38 -0
  253. data/spec/opal/core/array/minus_spec.rb +38 -0
  254. data/spec/opal/core/array/union_spec.rb +38 -0
  255. data/spec/opal/core/array/uniq_spec.rb +49 -0
  256. data/spec/opal/core/exception_spec.rb +7 -0
  257. data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
  258. data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
  259. data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
  260. data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
  261. data/spec/opal/core/hash/internals_spec.rb +332 -0
  262. data/spec/opal/core/helpers_spec.rb +14 -0
  263. data/spec/opal/core/kernel/freeze_spec.rb +1 -1
  264. data/spec/opal/core/kernel/raise_spec.rb +13 -0
  265. data/spec/opal/core/kernel/require_tree_spec.rb +9 -0
  266. data/spec/opal/core/language/class_spec.rb +55 -0
  267. data/spec/opal/core/language/fixtures/send.rb +1 -0
  268. data/spec/opal/core/language/keyword_arguments_spec.rb +11 -0
  269. data/spec/opal/core/language/send_spec.rb +5 -0
  270. data/spec/opal/core/method/to_proc_spec.rb +28 -0
  271. data/spec/opal/core/module/name_spec.rb +0 -17
  272. data/spec/opal/core/runtime/bridged_classes_spec.rb +2 -2
  273. data/spec/opal/core/runtime/eval_spec.rb +1 -1
  274. data/spec/opal/core/runtime/method_missing_spec.rb +6 -0
  275. data/spec/opal/core/runtime_spec.rb +51 -0
  276. data/spec/opal/stdlib/js_spec.rb +66 -0
  277. data/spec/opal/stdlib/native/hash_spec.rb +36 -0
  278. data/spec/rubyspecs +152 -273
  279. data/spec/spec_helper.rb +10 -11
  280. data/stdlib/base64.rb +9 -9
  281. data/stdlib/benchmark.rb +551 -4
  282. data/stdlib/console.rb +94 -0
  283. data/stdlib/date.rb +1 -1
  284. data/stdlib/encoding.rb +1 -170
  285. data/stdlib/js.rb +56 -0
  286. data/stdlib/json.rb +9 -14
  287. data/stdlib/math.rb +1 -370
  288. data/stdlib/native.rb +133 -63
  289. data/stdlib/nodejs/file.rb +5 -0
  290. data/stdlib/nodejs/fileutils.rb +13 -6
  291. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +1 -1
  292. data/stdlib/opal-parser.rb +1 -2
  293. data/stdlib/ostruct.rb +65 -6
  294. data/stdlib/pp.rb +2 -4
  295. data/stdlib/rbconfig.rb +1 -3
  296. data/stdlib/strscan.rb +164 -28
  297. data/tasks/benchmarking.rake +88 -0
  298. data/tasks/testing.rake +181 -55
  299. data/{lib/mspec/opal/special_calls.rb → tasks/testing/mspec_special_calls.rb} +1 -1
  300. data/{lib/mspec/opal/sprockets.js → tasks/testing/phantomjs1-sprockets.js} +17 -6
  301. data/test/opal/test_keyword.rb +590 -0
  302. data/vendored-minitest/minitest.rb +2 -2
  303. data/vendored-minitest/test/unit.rb +5 -0
  304. metadata +229 -62
  305. data/benchmarks/operators.rb +0 -11
  306. data/benchmarks/prova.js.rb +0 -13
  307. data/docs/libraries.md +0 -36
  308. data/lib/mspec/opal/new.html.erb +0 -1
  309. data/lib/mspec/opal/rake_task.rb +0 -248
  310. data/opal/corelib/match_data.rb +0 -128
  311. data/spec/filters/bugs/math.rb +0 -95
  312. data/spec/filters/bugs/nil.rb +0 -7
  313. data/spec/filters/bugs/opal.rb +0 -9
  314. data/spec/filters/bugs/regular_expressions.rb +0 -41
  315. data/spec/filters/bugs/stringscanner.rb +0 -33
  316. data/spec/filters/unsupported/encoding.rb +0 -102
  317. data/spec/filters/unsupported/frozen.rb +0 -92
  318. data/spec/filters/unsupported/hash_compare_by_identity.rb +0 -16
  319. data/spec/filters/unsupported/integer_size.rb +0 -59
  320. data/spec/filters/unsupported/method_added.rb +0 -10
  321. data/spec/filters/unsupported/private_constants.rb +0 -30
  322. data/spec/filters/unsupported/private_methods.rb +0 -55
  323. data/spec/filters/unsupported/random.rb +0 -4
  324. data/spec/filters/unsupported/rational_numbers.rb +0 -4
  325. data/spec/filters/unsupported/regular_expressions.rb +0 -137
  326. data/spec/filters/unsupported/ruby_exe.rb +0 -5
  327. data/spec/filters/unsupported/symbols.rb +0 -17
  328. data/spec/filters/unsupported/tainted.rb +0 -180
  329. data/spec/filters/unsupported/trusted.rb +0 -88
  330. data/stdlib/process.rb +0 -10
  331. data/tasks/documenting.rake +0 -37
@@ -1,11 +0,0 @@
1
- require "benchmark"
2
-
3
- time = Benchmark.measure do
4
- a = 0
5
- 100000.times do
6
- a = a + 1
7
- end
8
- puts a
9
- end
10
-
11
- puts time
@@ -1,13 +0,0 @@
1
- # 'asdf' =~ /(a)./
2
- #
3
- # p $'
4
- # p $1
5
- # p $2
6
- # `console.log(2, $opal.gvars['1'])`
7
- # b = $1
8
- # `console.log(1, b)`
9
- # nil
10
-
11
- puts [*1..3].to_s
12
- puts [*(1..3)].to_s
13
- puts [*Object.new].to_s
data/docs/libraries.md DELETED
@@ -1,36 +0,0 @@
1
- # Using external libraries in your Opal app
2
-
3
- As described in the getting started docs, opal uses a load path which works
4
- with sprockets to create a set of locations which opal can require files
5
- from. If you want to add a directory to this load path, you can add it to
6
- either the global environment, or a sprockets instance.
7
-
8
- ### Global Environment
9
-
10
- In the `Opal` module, a property `paths` is used to hold the load paths which
11
- `Opal` uses to require files from. You can add a directory to this:
12
-
13
- ```ruby
14
- Opal.append_path '../my_lib'
15
- ```
16
-
17
- Now, any ruby files in this directory can be discovered.
18
-
19
- ### Sprockets instances
20
-
21
- `Opal::Environment` is a subclass of the sprockets environment class which
22
- can have instance specific paths added to it. This class will inherit all
23
- global paths, but you can also add your instance paths as:
24
-
25
- ```ruby
26
- env = Opal::Environment.new
27
- env.append_path '../my_lib'
28
- ```
29
-
30
- ## with Opal::Builder
31
-
32
- _WIP_
33
-
34
- ## With opal-sprockets
35
-
36
- _WIP_
@@ -1 +0,0 @@
1
-
@@ -1,248 +0,0 @@
1
- require 'opal'
2
- require 'rack'
3
- require 'webrick'
4
- require 'mspec/opal/special_calls'
5
-
6
- module MSpec
7
- module Opal
8
- DEFAULT_BASEDIR = 'spec'
9
-
10
- require 'rake'
11
- require 'rake/tasklib'
12
- class RakeTask < ::Rake::TaskLib
13
- include ::Rake::DSL if defined?(::Rake::DSL)
14
-
15
- def initialize(name, &task_block)
16
- namespace name do
17
- desc 'Run MSpec::Opal code examples' unless ::Rake.application.last_comment
18
- task :default do
19
- puts 'Starting MSpec Runner...'
20
- runner = Runner.new(&task_block)
21
- runner.run
22
- end
23
-
24
- desc 'Build specs to build/specs.js and build/specs.min.js'
25
- task :build do
26
- require 'opal/util'
27
- path = './build/specs.js'
28
- min_path = './build/specs.min.js'
29
- Environment.new.build_specs(path)
30
- min = ::Opal::Util.uglify File.read(path)
31
- File.open(min_path, 'w') { |f| f << min_path }
32
- end
33
- end
34
-
35
- task name => "#{name}:default"
36
- end
37
- end
38
-
39
- class Runner
40
- def initialize &block
41
- @app = Rack::Builder.new do
42
- ::Opal::Processor.arity_check_enabled = true
43
- ::Opal::Processor.dynamic_require_severity = :error
44
-
45
- use Rack::ShowExceptions
46
- use Rack::ShowStatus
47
- use MSpec::Opal::Index
48
- run MSpec::Opal::Environment.new
49
- end
50
-
51
- @port = 9999
52
- end
53
-
54
- attr_reader :app, :server
55
- attr_accessor :port
56
-
57
- def passed?
58
- @passed
59
- end
60
-
61
- def run
62
- start_server
63
- start_phantomjs
64
-
65
- exit 1 unless passed?
66
- rescue => e
67
- puts e.message
68
- ensure
69
- stop_server if server
70
- end
71
-
72
- def stop_server
73
- server.kill
74
- end
75
-
76
- require 'opal/util'
77
- class PhantomJS < ::Opal::Util::Command
78
- require 'shellwords'
79
-
80
- def initialize(runner, url)
81
- runner = runner.shellescape
82
- url = url.shellescape
83
- super 'phantomjs', "#{runner} #{url}", '. Please install PhantomJS'
84
- end
85
-
86
- def run
87
- system "#{command} #{options}"
88
- end
89
- end
90
-
91
- def start_phantomjs
92
- runner = File.expand_path('../sprockets.js', __FILE__).shellescape
93
- url = "http://localhost:#{port}/".shellescape
94
- command = PhantomJS.new(runner, url)
95
- @passed = command.run
96
- end
97
-
98
- def start_server
99
- @server = Thread.new { Rack::Server.start(:app => app, :Port => port) }
100
- end
101
- end
102
-
103
- class Environment < ::Sprockets::Environment
104
- attr_reader :basedir, :pattern
105
-
106
- def initialize(basedir = nil, pattern = nil)
107
- @pattern = pattern
108
- @basedir = basedir = File.expand_path(basedir || DEFAULT_BASEDIR)
109
-
110
- ::Opal.append_path basedir
111
- ::Opal.use_gem 'mspec'
112
-
113
- stubs.each do |asset|
114
- ::Opal::Processor.stub_file asset
115
- end
116
-
117
- ENV['OPAL_SPEC'] ||= files_to_run(pattern).join(',')
118
-
119
- super()
120
-
121
- ::Opal.paths.each { |p| append_path p }
122
- end
123
-
124
- def stubs
125
- # missing stdlib
126
- stubs = %w[fileutils iconv yaml]
127
-
128
- # use x-strings which generate bad javascript
129
- stubs << "mspec/helpers/tmp"
130
- stubs << "mspec/helpers/environment"
131
- stubs << "mspec/guards/block_device"
132
- stubs << "mspec/guards/endian"
133
-
134
- stubs
135
- end
136
-
137
- def specs
138
- @specs ||= self['mspec/opal/main'] || raise("Cannot find mspec/opal/main inside #{paths.inspect}")
139
- end
140
-
141
- def build_min file = "#{basedir}/build/specs.min.js"
142
- require 'opal/util'
143
- build ::Opal::Util.uglify(specs.to_s), file
144
- end
145
-
146
- def files
147
- @files ||= []
148
- end
149
-
150
- def add_files specs, tag = ''
151
- tag = "[#{tag}] "
152
- puts "#{tag}Adding #{specs.size} spec files..."
153
- specs = specs.flatten.map do |path|
154
- dirname = File.join([basedir, path])
155
- if File.directory? dirname
156
- rubyspec_paths_in_dir(dirname, path)
157
- else
158
- path
159
- end
160
- end.flatten
161
- files.concat specs
162
- end
163
-
164
- def paths_from_glob pattern
165
- Dir.glob(File.expand_path(pattern)).map do |s|
166
- s.sub(/\A#{basedir}\//, '').sub(/\.rb\z/, '')
167
- end
168
- end
169
-
170
- def rubyspec_paths_in_dir(dirname, path)
171
- Dir.entries(dirname).select do |spec|
172
- spec.end_with? '.rb'
173
- end.map do |spec|
174
- File.join path, spec
175
- end
176
- end
177
-
178
- def rubyspec_white_list
179
- File.read("#{basedir}/rubyspecs").split("\n").reject do |line|
180
- line.sub(/#.*/, '').strip.empty? ||
181
- (line.start_with?('!') && rubyspec_black_list.push(line.sub('!', '') + '.rb'))
182
- end
183
- end
184
-
185
- def rubyspec_black_list
186
- @rubyspec_black_list ||= []
187
- end
188
-
189
- def files_to_run(pattern=nil)
190
- # add any filters in spec/filters of specs we dont want to run
191
- add_files paths_from_glob("#{basedir}/filters/**/*.rb"), :filters
192
-
193
- if pattern
194
- # add custom opal specs from spec/
195
- add_files paths_from_glob(pattern) & rubyspec_white_list, :rubyspec_custom
196
- add_files paths_from_glob(pattern).grep(/(?!spec\/(corelib|stdlib)\/)/), :other_custom
197
-
198
- else
199
- # add opal specific specs
200
- add_files paths_from_glob("#{basedir}/opal/**/*_spec.rb"), :shared
201
- add_files paths_from_glob("#{basedir}/lib/lexer_spec.rb"), :lexer
202
- add_files paths_from_glob("#{basedir}/lib/parser/**/*_spec.rb"), :parser
203
-
204
- # add any rubyspecs we want to run (defined in spec/rubyspecs)
205
- add_files rubyspec_white_list, :rubyspecs
206
- end
207
-
208
- files - rubyspec_black_list
209
- end
210
-
211
- def build_specs file = "#{basedir}/build/specs.js"
212
- code = specs.to_s
213
- FileUtils.mkdir_p File.dirname(file)
214
- puts "Building #{file}..."
215
- File.open(file, 'w+') { |o| o << code }
216
- end
217
- end
218
-
219
- class Index
220
- HTML = <<-HTML
221
- <!DOCTYPE html>
222
- <html>
223
- <head>
224
- <meta charset="UTF-8" />
225
- <title>Opal Specs</title>
226
- </head>
227
- <body>
228
- <script src="/mspec/opal/main.js"></script>
229
- <script>Opal.load('mspec/opal/main');</script>
230
- </body>
231
- </html>
232
- HTML
233
-
234
- def initialize(app)
235
- @app = app
236
- end
237
-
238
- def call(env)
239
- if %w[/ /index.html].include? env['PATH_INFO']
240
- [200, { 'Content-Type' => 'text/html' }, [HTML]]
241
- else
242
- @app.call env
243
- end
244
- end
245
- end
246
-
247
- end
248
- end
@@ -1,128 +0,0 @@
1
- class MatchData
2
- attr_reader :post_match, :pre_match, :regexp, :string
3
-
4
- def initialize(regexp, match_groups)
5
- $~ = self
6
- @regexp = regexp
7
- @begin = `match_groups.index`
8
- @string = `match_groups.input`
9
- @pre_match = `match_groups.input.slice(0, match_groups.index)`
10
- @post_match = `match_groups.input.slice(match_groups.index + match_groups[0].length)`
11
- @matches = []
12
-
13
- %x{
14
- for (var i = 0, length = match_groups.length; i < length; i++) {
15
- var group = match_groups[i];
16
-
17
- if (group == null) {
18
- #@matches.push(nil);
19
- }
20
- else {
21
- #@matches.push(group);
22
- }
23
- }
24
- }
25
- end
26
-
27
- def [](*args)
28
- @matches[*args]
29
- end
30
-
31
- def offset(n)
32
- %x{
33
- if (n !== 0) {
34
- #{raise ArgumentError, 'MatchData#offset only supports 0th element'}
35
- }
36
- return [self.begin, self.begin + self.matches[n].length];
37
- }
38
- end
39
-
40
- def ==(other)
41
- return false unless MatchData === other
42
-
43
- `self.string == other.string` &&
44
- `self.regexp.toString() == other.regexp.toString()` &&
45
- `self.pre_match == other.pre_match` &&
46
- `self.post_match == other.post_match` &&
47
- `self.begin == other.begin`
48
- end
49
-
50
- alias eql? ==
51
-
52
- def begin(n)
53
- %x{
54
- if (n !== 0) {
55
- #{raise ArgumentError, 'MatchData#begin only supports 0th element'}
56
- }
57
- return self.begin;
58
- }
59
- end
60
-
61
- def end(n)
62
- %x{
63
- if (n !== 0) {
64
- #{raise ArgumentError, 'MatchData#end only supports 0th element'}
65
- }
66
- return self.begin + self.matches[n].length;
67
- }
68
- end
69
-
70
- def captures
71
- `#@matches.slice(1)`
72
- end
73
-
74
- def inspect
75
- %x{
76
- var str = "#<MatchData " + #{`#@matches[0]`.inspect};
77
-
78
- for (var i = 1, length = #@matches.length; i < length; i++) {
79
- str += " " + i + ":" + #{`#@matches[i]`.inspect};
80
- }
81
-
82
- return str + ">";
83
- }
84
- end
85
-
86
- def length
87
- `#@matches.length`
88
- end
89
-
90
- alias size length
91
-
92
- def to_a
93
- @matches
94
- end
95
-
96
- def to_s
97
- `#@matches[0]`
98
- end
99
-
100
- def values_at(*args)
101
- %x{
102
- var i, a, index, values = [];
103
-
104
- for (i = 0; i < args.length; i++) {
105
-
106
- if (args[i].$$is_range) {
107
- a = #{`args[i]`.to_a};
108
- a.unshift(i, 1);
109
- Array.prototype.splice.apply(args, a);
110
- }
111
-
112
- index = #{Opal.coerce_to!(`args[i]`, Integer, :to_int)};
113
-
114
- if (index < 0) {
115
- index += #@matches.length;
116
- if (index < 0) {
117
- values.push(nil);
118
- continue;
119
- }
120
- }
121
-
122
- values.push(#@matches[index]);
123
- }
124
-
125
- return values;
126
- }
127
- end
128
- end
@@ -1,95 +0,0 @@
1
- opal_filter "Math" do
2
- fails "Math.erf returns a float"
3
- fails "Math.erf returns the error function of the argument"
4
- fails "Math.erf raises a TypeError if the argument cannot be coerced with Float()"
5
- fails "Math.erf returns NaN given NaN"
6
- fails "Math.erf raises a TypeError if the argument is nil"
7
- fails "Math.erf accepts any argument that can be coerced with Float()"
8
- fails "Math#erf is accessible as a private instance method"
9
-
10
- fails "Math.erfc returns the complementary error function of the argument"
11
-
12
- fails "Math.frexp returns the normalized fraction and exponent"
13
- fails "Math.frexp raises a TypeError if the argument cannot be coerced with Float()"
14
- fails "Math.frexp returns NaN given NaN"
15
- fails "Math.frexp raises a TypeError if the argument is nil"
16
- fails "Math.frexp accepts any argument that can be coerced with Float()"
17
- fails "Math#frexp is accessible as a private instance method"
18
-
19
- fails "Math.erfc returns a float"
20
- fails "Math.erfc returns the complimentary error function of the argument"
21
- fails "Math.erfc raises a TypeError if the argument cannot be coerced with Float()"
22
- fails "Math.erfc returns NaN given NaN"
23
- fails "Math.erfc raises a TypeError if the argument is nil"
24
- fails "Math.erfc accepts any argument that can be coerced with Float()"
25
- fails "Math#erfc is accessible as a private instance method"
26
-
27
- fails "Math.ldexp returns a float"
28
- fails "Math.ldexp returns the argument multiplied by 2**n"
29
- fails "Math.ldexp raises a TypeError if the first argument cannot be coerced with Float()"
30
- fails "Math.ldexp returns NaN given NaN"
31
- fails "Math.ldexp raises RangeError if NaN is given as the second arg"
32
- fails "Math.ldexp raises a TypeError if the second argument cannot be coerced with Integer()"
33
- fails "Math.ldexp raises a TypeError if the first argument is nil"
34
- fails "Math.ldexp raises a TypeError if the second argument is nil"
35
- fails "Math.ldexp accepts any first argument that can be coerced with Float()"
36
- fails "Math.ldexp accepts any second argument that can be coerced with Integer()"
37
- fails "Math#ldexp is accessible as a private instance method"
38
-
39
- fails "Math.cbrt returns a float"
40
- fails "Math.cbrt returns the cubic root of the argument"
41
- fails "Math.cbrt raises a TypeError if the argument cannot be coerced with Float()"
42
- fails "Math.cbrt raises a TypeError if the argument is nil"
43
- fails "Math.cbrt accepts any argument that can be coerced with Float()"
44
-
45
- fails "Math.gamma returns +infinity given 0"
46
- fails "Math.gamma returns -infinity given -0.0"
47
- fails "Math.gamma returns Math.sqrt(Math::PI) given 0.5"
48
- fails "Math.gamma returns exactly 1! given 2"
49
- fails "Math.gamma returns exactly 2! given 3"
50
- fails "Math.gamma returns exactly 3! given 4"
51
- fails "Math.gamma returns exactly 4! given 5"
52
- fails "Math.gamma returns exactly 5! given 6"
53
- fails "Math.gamma returns exactly 6! given 7"
54
- fails "Math.gamma returns exactly 7! given 8"
55
- fails "Math.gamma returns exactly 8! given 9"
56
- fails "Math.gamma returns exactly 9! given 10"
57
- fails "Math.gamma returns exactly 10! given 11"
58
- fails "Math.gamma returns exactly 11! given 12"
59
- fails "Math.gamma returns exactly 12! given 13"
60
- fails "Math.gamma returns exactly 13! given 14"
61
- fails "Math.gamma returns exactly 14! given 15"
62
- fails "Math.gamma returns exactly 15! given 16"
63
- fails "Math.gamma returns exactly 16! given 17"
64
- fails "Math.gamma returns exactly 17! given 18"
65
- fails "Math.gamma returns exactly 18! given 19"
66
- fails "Math.gamma returns exactly 19! given 20"
67
- fails "Math.gamma returns exactly 20! given 21"
68
- fails "Math.gamma returns exactly 21! given 22"
69
- fails "Math.gamma returns exactly 22! given 23"
70
- fails "Math.gamma returns approximately 23! given 24"
71
- fails "Math.gamma returns approximately 24! given 25"
72
- fails "Math.gamma returns approximately 25! given 26"
73
- fails "Math.gamma returns approximately 26! given 27"
74
- fails "Math.gamma returns approximately 27! given 28"
75
- fails "Math.gamma returns approximately 28! given 29"
76
- fails "Math.gamma returns approximately 29! given 30"
77
- fails "Math.gamma returns good numerical approximation for gamma(3.2)"
78
- fails "Math.gamma returns good numerical approximation for gamma(-2.15)"
79
- fails "Math.gamma returns good numerical approximation for gamma(0.00001)"
80
- fails "Math.gamma returns good numerical approximation for gamma(-0.00001)"
81
- fails "Math.gamma raises Math::DomainError given -1"
82
- fails "Math.gamma returns +infinity given +infinity"
83
- fails "Math.gamma raises Math::DomainError given negative infinity"
84
- fails "Math.gamma returns NaN given NaN"
85
-
86
- fails "Math.lgamma returns [Infinity, 1] when passed 0"
87
- fails "Math.lgamma returns [Infinity, 1] when passed -1"
88
- fails "Math.lgamma returns [log(sqrt(PI)), 1] when passed 0.5"
89
- fails "Math.lgamma returns [log(2/3*PI, 1] when passed 6.0"
90
- fails "Math.lgamma returns an approximate value when passed -0.5"
91
- fails "Math.lgamma returns an approximate value when passed -1.5"
92
- fails "Math.lgamma raises Math::DomainError when passed -Infinity"
93
- fails "Math.lgamma returns [Infinity, 1] when passed Infinity"
94
- fails "Math.lgamma returns [NaN, 1] when passed NaN"
95
- end