opal 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/.rspec +3 -0
  2. data/.travis.yml +0 -4
  3. data/README.md +6 -0
  4. data/Rakefile +30 -6
  5. data/bin/opal +6 -82
  6. data/corelib/{opal/array.rb → array.rb} +40 -56
  7. data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
  8. data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
  9. data/corelib/class.rb +47 -0
  10. data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
  11. data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
  12. data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
  13. data/corelib/{opal/error.rb → error.rb} +1 -0
  14. data/corelib/{opal/hash.rb → hash.rb} +67 -56
  15. data/corelib/io.rb +39 -0
  16. data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
  17. data/corelib/{opal/class.rb → module.rb} +29 -57
  18. data/corelib/native.rb +148 -0
  19. data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
  20. data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
  21. data/corelib/opal.rb +42 -25
  22. data/corelib/{opal/proc.rb → proc.rb} +3 -3
  23. data/corelib/{opal/range.rb → range.rb} +5 -1
  24. data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
  25. data/corelib/{opal/runtime.js → runtime.js} +96 -188
  26. data/corelib/{opal/string.rb → string.rb} +20 -15
  27. data/corelib/struct.rb +139 -0
  28. data/corelib/{opal/time.rb → time.rb} +0 -0
  29. data/lib/opal.rb +4 -0
  30. data/lib/opal/cli.rb +79 -32
  31. data/lib/opal/cli_options.rb +91 -0
  32. data/lib/opal/erb.rb +41 -8
  33. data/lib/opal/grammar.rb +24 -10
  34. data/lib/opal/grammar.y +15 -4
  35. data/lib/opal/grammar_helpers.rb +4 -0
  36. data/lib/opal/lexer.rb +214 -143
  37. data/lib/opal/parser.rb +596 -562
  38. data/lib/opal/require_parser.rb +1 -1
  39. data/lib/opal/source_map.rb +15 -30
  40. data/lib/opal/target_scope.rb +24 -5
  41. data/lib/opal/version.rb +1 -1
  42. data/mri_spec/cli_spec.rb +18 -0
  43. data/mri_spec/fixtures/opal_file.rb +2 -0
  44. data/mri_spec/spec_helper.rb +17 -0
  45. data/opal.gemspec +5 -2
  46. data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
  47. data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
  48. data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
  49. data/spec/filters/bugs/array/combination.rb +11 -0
  50. data/spec/filters/bugs/array/count.rb +3 -0
  51. data/spec/filters/bugs/array/delete_if.rb +3 -0
  52. data/spec/filters/bugs/array/drop.rb +3 -0
  53. data/spec/filters/bugs/array/drop_while.rb +5 -0
  54. data/spec/filters/bugs/array/eql.rb +3 -0
  55. data/spec/filters/bugs/array/flatten.rb +9 -0
  56. data/spec/filters/bugs/array/minus.rb +5 -0
  57. data/spec/filters/bugs/array/multipliy.rb +9 -0
  58. data/spec/filters/bugs/array/new.rb +3 -0
  59. data/spec/filters/bugs/array/pop.rb +6 -0
  60. data/spec/filters/bugs/array/rassoc.rb +4 -0
  61. data/spec/filters/bugs/array/rindex.rb +6 -0
  62. data/spec/filters/bugs/array/select.rb +3 -0
  63. data/spec/filters/bugs/array/shift.rb +7 -0
  64. data/spec/filters/bugs/array/shuffle.rb +11 -0
  65. data/spec/filters/bugs/array/slice.rb +7 -0
  66. data/spec/filters/bugs/array/take.rb +3 -0
  67. data/spec/filters/bugs/array/to_a.rb +3 -0
  68. data/spec/filters/bugs/array/try_convert.rb +7 -0
  69. data/spec/filters/bugs/array/uniq.rb +10 -0
  70. data/spec/filters/bugs/array/zip.rb +4 -0
  71. data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
  72. data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
  73. data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
  74. data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
  75. data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
  76. data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
  77. data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
  78. data/spec/filters/bugs/case.rb +4 -0
  79. data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
  80. data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
  81. data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
  82. data/spec/filters/bugs/kernel/rand.rb +4 -0
  83. data/spec/filters/bugs/language/array.rb +3 -0
  84. data/spec/filters/bugs/language/block.rb +6 -0
  85. data/spec/filters/bugs/language/break.rb +3 -0
  86. data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
  87. data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
  88. data/spec/filters/bugs/language/def.rb +27 -0
  89. data/spec/filters/bugs/language/defined.rb +3 -0
  90. data/spec/filters/bugs/language/ensure.rb +4 -0
  91. data/spec/filters/bugs/language/execution.rb +4 -0
  92. data/spec/filters/bugs/language/for.rb +18 -0
  93. data/spec/filters/bugs/language/if.rb +13 -0
  94. data/spec/filters/bugs/language/loop.rb +4 -0
  95. data/spec/filters/bugs/language/metaclass.rb +14 -0
  96. data/spec/filters/bugs/language/module.rb +6 -0
  97. data/spec/filters/bugs/language/next.rb +3 -0
  98. data/spec/filters/bugs/language/or.rb +3 -0
  99. data/spec/filters/bugs/language/order.rb +4 -0
  100. data/spec/filters/bugs/language/precedence.rb +10 -0
  101. data/spec/filters/bugs/language/proc.rb +24 -0
  102. data/spec/filters/bugs/language/redo.rb +5 -0
  103. data/spec/filters/bugs/language/rescue.rb +9 -0
  104. data/spec/filters/bugs/language/retry.rb +5 -0
  105. data/spec/filters/bugs/language/send.rb +10 -0
  106. data/spec/filters/bugs/language/super.rb +9 -0
  107. data/spec/filters/bugs/language/until.rb +8 -0
  108. data/spec/filters/bugs/language/variables.rb +37 -0
  109. data/spec/filters/bugs/language/while.rb +6 -0
  110. data/spec/filters/bugs/language/yield.rb +5 -0
  111. data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
  112. data/spec/filters/bugs/module/method_defined.rb +6 -0
  113. data/spec/filters/bugs/parser.rb +10 -0
  114. data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
  115. data/spec/filters/bugs/return.rb +7 -0
  116. data/spec/filters/bugs/singleton/instance.rb +4 -0
  117. data/spec/filters/bugs/source_map.rb +3 -0
  118. data/spec/filters/bugs/string/center.rb +4 -0
  119. data/spec/filters/bugs/string/lines.rb +3 -0
  120. data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
  121. data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
  122. data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
  123. data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
  124. data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
  125. data/spec/filters/unsupported/frozen.rb +32 -0
  126. data/spec/filters/unsupported/immutable_strings.rb +3 -0
  127. data/spec/filters/unsupported/tainted.rb +17 -0
  128. data/spec/filters/unsupported/trusted.rb +15 -0
  129. data/spec/opal/class/constants_spec.rb +7 -0
  130. data/spec/opal/erb/erb_spec.rb +7 -1
  131. data/spec/opal/erb/inline_block.opalerb +3 -0
  132. data/spec/opal/hash/allocate_spec.rb +16 -0
  133. data/spec/opal/hash/new_spec.rb +10 -0
  134. data/spec/opal/hash/to_s_spec.rb +9 -0
  135. data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
  136. data/spec/opal/kernel/rand_spec.rb +5 -5
  137. data/spec/opal/kernel/respond_to_spec.rb +14 -1
  138. data/spec/opal/language/block_spec.rb +13 -0
  139. data/spec/opal/language/rescue_spec.rb +27 -0
  140. data/spec/opal/language/return_spec.rb +38 -0
  141. data/spec/opal/language/singleton_class_spec.rb +13 -0
  142. data/spec/opal/language/super_spec.rb +99 -0
  143. data/spec/opal/language/variables_spec.rb +20 -0
  144. data/spec/opal/module/attr_accessor_spec.rb +8 -0
  145. data/spec/opal/module/constants_spec.rb +2 -2
  146. data/spec/opal/native/alias_native_spec.rb +18 -0
  147. data/spec/opal/native/each_spec.rb +14 -0
  148. data/spec/opal/native/element_reference_spec.rb +14 -0
  149. data/spec/opal/native/method_missing_spec.rb +39 -0
  150. data/spec/opal/native/new_spec.rb +19 -0
  151. data/spec/opal/native/nil_spec.rb +14 -0
  152. data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
  153. data/spec/opal/source_map_spec.rb +3 -7
  154. data/spec/ospec/main.rb.erb +2 -5
  155. data/spec/parser/alias_spec.rb +4 -4
  156. data/spec/parser/and_spec.rb +2 -2
  157. data/spec/parser/array_spec.rb +6 -6
  158. data/spec/parser/attrasgn_spec.rb +8 -8
  159. data/spec/parser/begin_spec.rb +11 -11
  160. data/spec/parser/block_spec.rb +3 -3
  161. data/spec/parser/break_spec.rb +4 -4
  162. data/spec/parser/call_spec.rb +50 -48
  163. data/spec/parser/class_spec.rb +2 -2
  164. data/spec/parser/const_spec.rb +1 -1
  165. data/spec/parser/cvar_spec.rb +1 -1
  166. data/spec/parser/def_spec.rb +5 -5
  167. data/spec/parser/gvar_spec.rb +2 -2
  168. data/spec/parser/hash_spec.rb +4 -4
  169. data/spec/parser/iasgn_spec.rb +3 -3
  170. data/spec/parser/if_spec.rb +6 -6
  171. data/spec/parser/iter_spec.rb +6 -6
  172. data/spec/parser/lambda_spec.rb +5 -5
  173. data/spec/parser/lasgn_spec.rb +2 -2
  174. data/spec/parser/line_spec.rb +2 -2
  175. data/spec/parser/lvar_spec.rb +5 -5
  176. data/spec/parser/masgn_spec.rb +1 -1
  177. data/spec/parser/module_spec.rb +2 -2
  178. data/spec/parser/not_spec.rb +4 -4
  179. data/spec/parser/op_asgn1_spec.rb +2 -2
  180. data/spec/parser/op_asgn2_spec.rb +2 -2
  181. data/spec/parser/or_spec.rb +2 -2
  182. data/spec/parser/parse_spec.rb +66 -0
  183. data/spec/parser/parser_spec.rb +32 -38
  184. data/spec/parser/regexp_spec.rb +4 -4
  185. data/spec/parser/return_spec.rb +4 -4
  186. data/spec/parser/sclass_spec.rb +4 -4
  187. data/spec/parser/str_spec.rb +3 -3
  188. data/spec/parser/super_spec.rb +6 -6
  189. data/spec/parser/undef_spec.rb +3 -3
  190. data/spec/parser/unless_spec.rb +4 -4
  191. data/spec/parser/while_spec.rb +3 -3
  192. data/spec/parser/xstr_spec.rb +3 -3
  193. data/spec/parser/yield_spec.rb +6 -6
  194. data/spec/rubyspec/core/array/drop_spec.rb +1 -1
  195. data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
  196. data/spec/rubyspec/core/array/length_spec.rb +1 -3
  197. data/spec/rubyspec/core/array/map_spec.rb +2 -6
  198. data/spec/rubyspec/core/array/minus_spec.rb +3 -3
  199. data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
  200. data/spec/rubyspec/core/array/new_spec.rb +3 -5
  201. data/spec/rubyspec/core/array/plus_spec.rb +2 -2
  202. data/spec/rubyspec/core/array/pop_spec.rb +4 -4
  203. data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
  204. data/spec/rubyspec/core/array/reject_spec.rb +2 -6
  205. data/spec/rubyspec/core/array/replace_spec.rb +1 -3
  206. data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
  207. data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
  208. data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
  209. data/spec/rubyspec/core/array/select_spec.rb +3 -7
  210. data/spec/rubyspec/core/array/shared/collect.rb +7 -0
  211. data/spec/rubyspec/core/array/shared/index.rb +1 -1
  212. data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
  213. data/spec/rubyspec/core/array/shared/length.rb +3 -0
  214. data/spec/rubyspec/core/array/shared/replace.rb +3 -0
  215. data/spec/rubyspec/core/array/shared/slice.rb +3 -0
  216. data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
  217. data/spec/rubyspec/core/array/size_spec.rb +1 -3
  218. data/spec/rubyspec/core/array/slice_spec.rb +4 -6
  219. data/spec/rubyspec/core/array/sort_spec.rb +2 -2
  220. data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
  221. data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
  222. data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
  223. data/spec/rubyspec/core/array/zip_spec.rb +1 -1
  224. data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
  225. data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
  226. data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
  227. data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
  228. data/spec/rubyspec/core/hash/each_spec.rb +13 -7
  229. data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
  230. data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
  231. data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
  232. data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
  233. data/spec/rubyspec/core/string/center_spec.rb +43 -65
  234. data/spec/rubyspec/core/string/lines_spec.rb +1 -1
  235. data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
  236. data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
  237. data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
  238. data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
  239. data/spec/rubyspec/core/struct/new_spec.rb +24 -0
  240. data/spec/rubyspec/fixtures/constants.rb +7 -0
  241. data/spec/rubyspec/language/break_spec.rb +1 -1
  242. data/spec/rubyspec/language/case_spec.rb +30 -30
  243. data/spec/rubyspec/language/def_spec.rb +34 -34
  244. data/spec/rubyspec/language/defined_spec.rb +2 -2
  245. data/spec/rubyspec/language/ensure_spec.rb +2 -2
  246. data/spec/rubyspec/language/execution_spec.rb +2 -2
  247. data/spec/rubyspec/language/for_spec.rb +17 -17
  248. data/spec/rubyspec/language/hash_spec.rb +3 -3
  249. data/spec/rubyspec/language/if_spec.rb +11 -11
  250. data/spec/rubyspec/language/loop_spec.rb +3 -3
  251. data/spec/rubyspec/language/metaclass_spec.rb +14 -14
  252. data/spec/rubyspec/language/module_spec.rb +6 -6
  253. data/spec/rubyspec/language/next_spec.rb +5 -5
  254. data/spec/rubyspec/language/not_spec.rb +1 -1
  255. data/spec/rubyspec/language/or_spec.rb +1 -1
  256. data/spec/rubyspec/language/order_spec.rb +3 -5
  257. data/spec/rubyspec/language/precedence_spec.rb +19 -19
  258. data/spec/rubyspec/language/proc_spec.rb +29 -29
  259. data/spec/rubyspec/language/redo_spec.rb +3 -5
  260. data/spec/rubyspec/language/rescue_spec.rb +7 -7
  261. data/spec/rubyspec/language/retry_spec.rb +2 -2
  262. data/spec/rubyspec/language/return_spec.rb +12 -12
  263. data/spec/rubyspec/language/send_spec.rb +9 -9
  264. data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
  265. data/spec/rubyspec/language/super_spec.rb +7 -11
  266. data/spec/rubyspec/language/until_spec.rb +10 -10
  267. data/spec/rubyspec/language/variables_spec.rb +59 -67
  268. data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
  269. data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
  270. data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
  271. data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
  272. data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
  273. data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
  274. data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
  275. data/spec/rubyspec/language/while_spec.rb +4 -4
  276. data/spec/rubyspec/language/yield_spec.rb +3 -3
  277. data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
  278. data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
  279. data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
  280. data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
  281. data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
  282. data/spec/spec_helper.rb +214 -0
  283. data/stdlib/buffer.rb +40 -0
  284. data/stdlib/buffer/array.rb +66 -0
  285. data/stdlib/buffer/view.rb +70 -0
  286. data/stdlib/erb.rb +11 -20
  287. data/stdlib/forwardable.rb +71 -0
  288. data/stdlib/json.rb +78 -0
  289. data/stdlib/ostruct.rb +69 -0
  290. data/stdlib/rbconfig.rb +1 -0
  291. data/stdlib/singleton.rb +40 -0
  292. data/stdlib/stringio.rb +173 -0
  293. data/stdlib/template.rb +44 -0
  294. metadata +285 -79
  295. data/corelib/opal/native.rb +0 -31
  296. data/spec/opal/class/bridge_class_spec.rb +0 -39
  297. data/spec/opal/native_spec.rb +0 -209
  298. data/spec/ospec/runner.rb +0 -223
  299. data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
  300. data/spec/rubyspec/filters/bugs/case.rb +0 -8
  301. data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
  302. data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
  303. data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -1,31 +0,0 @@
1
- class Native
2
- def self.try_convert(value)
3
- %x{
4
- if (value == null) {
5
- return null;
6
- }
7
-
8
- if (value.$to_n) {
9
- return value.$to_n()
10
- }
11
- else if (!value.$object_id) {
12
- return value;
13
- }
14
- else {
15
- return null;
16
- }
17
- }
18
- end
19
-
20
- def initialize(native)
21
- if (native = Native.try_convert(native)).nil?
22
- raise ArgumentError, "the passed value isn't a native"
23
- end
24
-
25
- @native = native
26
- end
27
-
28
- def to_n
29
- @native
30
- end
31
- end
@@ -1,39 +0,0 @@
1
- %x{
2
- var BridgeClassProto = function() {
3
- this.foo = 200;
4
- };
5
-
6
- BridgeClassProto.prototype = {
7
- bar: 300,
8
- baz: 400
9
- };
10
- }
11
-
12
- Class.bridge_class :BridgeClassSpec, `BridgeClassProto`
13
-
14
- class BridgeClassSpec
15
- def get_foo
16
- `#{self}.foo`
17
- end
18
-
19
- def say_it
20
- "hello world"
21
- end
22
- end
23
-
24
- describe "Class#bridge_class" do
25
- it "should have a superclass of Object" do
26
- BridgeClassSpec.superclass.should == Object
27
- end
28
-
29
- it "should report instances as kind of bridged class" do
30
- obj = `new BridgeClassProto()`
31
- obj.class.should == BridgeClassSpec
32
- end
33
-
34
- it "should have defined instance methods present on prototype" do
35
- obj = `new BridgeClassProto()`
36
- obj.get_foo.should == 200
37
- obj.say_it.should == "hello world"
38
- end
39
- end
@@ -1,209 +0,0 @@
1
- require 'spec_helper'
2
-
3
- %x{
4
- var obj = {
5
- property: 42,
6
-
7
- simple: function() {
8
- return 'foo';
9
- },
10
-
11
- context_check: function() {
12
- return this === obj;
13
- },
14
-
15
- check_args: function(a, b, c) {
16
- return [a, b, c];
17
- },
18
-
19
- array: [1, 2, 3, 4],
20
-
21
- child_object: {
22
- grand_child: 100
23
- },
24
-
25
- func_returning_null: function() {
26
- return null;
27
- },
28
-
29
- func_returning_undefined: function() {
30
- return undefined;
31
- }
32
- };
33
- }
34
-
35
- NATIVE_OBJECT_SPEC = `obj`
36
-
37
- describe "Native objects" do
38
- before do
39
- @obj = NATIVE_OBJECT_SPEC
40
- end
41
-
42
- describe "accessing a null/undefined property" do
43
- it "returns nil" do
44
- @obj.doesnt_exist.should == nil
45
- end
46
- end
47
-
48
- describe "with a mid ending with '='" do
49
- it "sets the value on the property" do
50
- @obj.set_property = 100
51
- @obj.set_property.should == 100
52
-
53
- @obj.set_property = [1, 2, 3]
54
- @obj.set_property.should == [1, 2, 3]
55
- end
56
- end
57
-
58
- describe "accessing a property" do
59
- it "returns values from the native object" do
60
- @obj.property.should == 42
61
- end
62
-
63
- it "returns an array without wrapping" do
64
- @obj.array.should == [1, 2, 3, 4]
65
- end
66
-
67
- end
68
-
69
- describe "accessing a function property" do
70
- it "forwards methods to wrapped object as native function calls" do
71
- @obj.simple.should == "foo"
72
- end
73
-
74
- it "calls functions with native object as context" do
75
- @obj.context_check.should be_true
76
- end
77
-
78
- it "passes each argument to native function" do
79
- @obj.check_args(1, 2, 3).should == [1, 2, 3]
80
- end
81
-
82
- it "tries to convert each argument with to_n if defined" do
83
- obj, obj2, obj3 = Object.new, Object.new, Object.new
84
- def obj.to_n; "foo"; end
85
- def obj2.to_n; 42; end
86
-
87
- @obj.check_args(obj, obj2, obj3).should == ["foo", 42, obj3]
88
- end
89
-
90
- it "converts null/undefined values to nil from function" do
91
- @obj.func_returning_null.should be_nil
92
- @obj.func_returning_undefined.should be_nil
93
- end
94
- end
95
-
96
- describe "#[]" do
97
- before do
98
- @native = %x{
99
- {
100
- foo: 'FOO',
101
-
102
- str: 'LOL',
103
- num: 42,
104
- on: true,
105
- off: false
106
- };
107
- }
108
- end
109
-
110
- it "returns a value from the native object" do
111
- @native['foo'].should == "FOO"
112
- end
113
-
114
- it "returns nil for a key not existing on native object" do
115
- @native['bar'].should be_nil
116
- end
117
-
118
- it "returns direct values for strings, numerics and booleans" do
119
- @native['str'].should == 'LOL'
120
- @native['num'].should == 42
121
- @native['on'].should == true
122
- @native['off'].should == false
123
- end
124
- end
125
-
126
- describe "#[]=" do
127
- it "sets values on the receiver object" do
128
- object = `{}`
129
-
130
- object["foo"] = 42
131
- object["foo"].should == 42
132
- end
133
-
134
- it "sets null on the object when nil given as value" do
135
- object = `{}`
136
-
137
- object["foo"] = nil
138
- `(object.foo === null)`.should be_true
139
- end
140
- end
141
-
142
- describe "==" do
143
- it "returns true if the wrapped objects are `===` to each other" do
144
- %x{
145
- var obj1 = {}, obj2 = {};
146
- }
147
-
148
- a = `obj1`
149
- b = `obj1`
150
- c = `obj2`
151
-
152
- (a == b).should be_true
153
- (a == c).should be_false
154
- end
155
- end
156
-
157
- describe "each" do
158
- describe "with an array-like object" do
159
- it "yields each element to block" do
160
- object = `{ "0": 3.142, "1": 42, "length": 2 }`
161
- result = []
162
-
163
- object.each { |obj| result << obj }
164
- result.should == [3.142, 42]
165
- end
166
-
167
- it "yields null and undefined values as nil" do
168
- object = `{length: 3, 0: null, 1: undefined}`
169
- result = []
170
-
171
- object.each { |obj| result << obj }
172
- result.should == [nil, nil, nil]
173
- end
174
- end
175
-
176
- describe "with a normal js object" do
177
- it "yields each key-value pair to the block" do
178
- object = `{"foo": 3.142, "bar": 42}`
179
- result = []
180
-
181
- object.each { |k, v| result << [k, v] }
182
- result.should == [["foo", 3.142], ["bar", 42]]
183
- end
184
-
185
- it "yields null and undefined values as nil" do
186
- object = `{"foo": null, "bar": undefined}`
187
- result = []
188
-
189
- object.each { |k, v| result << v }
190
- result.should == [nil, nil]
191
- end
192
- end
193
- end
194
-
195
- describe "#to_h" do
196
- it "converts a simple js object into a ruby hash" do
197
- object = `{"foo": true, "bar": 42}`
198
- hash = object.to_h
199
-
200
- hash.should be_kind_of(Hash)
201
- hash.should == {"foo" => true, "bar" => 42}
202
- end
203
-
204
- it "converts all null and undefined values to nil" do
205
- object = `{"a": null, "b": undefined}`
206
- object.to_h.should == {"a" => nil, "b" => nil}
207
- end
208
- end
209
- end
data/spec/ospec/runner.rb DELETED
@@ -1,223 +0,0 @@
1
- # stdlib
2
- require 'date'
3
- require 'observer'
4
-
5
- ENV['MSPEC_RUNNER'] = true
6
-
7
- class OSpecFilter
8
- def self.main
9
- @main ||= self.new
10
- end
11
-
12
- def initialize
13
- @filters = {}
14
- end
15
-
16
- def register
17
- MSpec.register :exclude, self
18
- end
19
-
20
- def ===(description)
21
- @filters.has_key? description
22
- end
23
-
24
- def register_filters(description, block)
25
- instance_eval(&block)
26
- end
27
-
28
- def fails(description)
29
- @filters[description] = true
30
- end
31
- end
32
-
33
- class Object
34
- def opal_filter(description, &block)
35
- OSpecFilter.main.register_filters(description, block)
36
- end
37
- end
38
-
39
- class PhantomFormatter
40
- def initialize(out=nil)
41
- @exception = @failure = false
42
- @exceptions = []
43
- @count = 0
44
- @examples = 0
45
-
46
- @current_state = nil
47
- end
48
-
49
- def register
50
- MSpec.register :exception, self
51
- MSpec.register :before, self
52
- MSpec.register :after, self
53
- MSpec.register :start, self
54
- MSpec.register :finish, self
55
- MSpec.register :abort, self
56
- MSpec.register :enter, self
57
- end
58
-
59
- def green(str)
60
- `console.log('\\033[32m' + str + '\\033[0m')`
61
- end
62
-
63
- def red(str)
64
- `console.log('\\033[31m' + str + '\\033[0m')`
65
- end
66
-
67
- def log(str)
68
- `console.log(str)`
69
- end
70
-
71
- def exception?
72
- @exception
73
- end
74
-
75
- def failure?
76
- @failure
77
- end
78
-
79
- def enter(describe); end
80
-
81
- def before(state=nil)
82
- @current_state = nil
83
- @failure = @exception = false
84
- end
85
-
86
- def exception(exception)
87
- @count += 1
88
- @failure = @exception ? @failure && exception.failure? : exception.failure?
89
- @exception = true
90
- @exceptions << exception
91
- end
92
-
93
- def after(state = nil)
94
- @current_state = nil
95
- @examples += 1
96
- end
97
-
98
- def start
99
- @start_time = Time.now.to_f
100
- end
101
-
102
- def finish
103
- time = Time.now.to_f - @start_time
104
-
105
- if @exceptions.empty?
106
- log "\nFinished"
107
- green "#{@examples} examples, #{@count} failures (time taken: #{time})"
108
-
109
- finish_with_code 0
110
- else
111
- log "\nFailures:"
112
-
113
- @exceptions.each_with_index do |exception, idx|
114
- log "\n #{idx + 1}. #{exception.description}"
115
- red "\n #{exception.message}"
116
- end
117
-
118
- log "\nFinished"
119
- red "#{@examples} examples, #{@count} failures (time taken: #{time})"
120
-
121
- finish_with_code(1)
122
- end
123
- end
124
-
125
- def finish_with_code(code)
126
- %x{
127
- if (typeof(phantom) !== 'undefined') {
128
- return phantom.exit(code);
129
- }
130
- else {
131
- window.OPAL_SPEC_CODE = code;
132
- }
133
- }
134
- end
135
- end
136
-
137
- class File
138
- def self.expand_path(*a); nil; end
139
- end
140
-
141
- class ExceptionState
142
- def initialize(state, location, exception)
143
- @exception = exception
144
-
145
- @description = location ? ["An exception occurred during: #{location}"] : []
146
- if state
147
- @description << "\n" unless @description.empty?
148
- @description << state.description
149
- @describe = state.describe
150
- @it = state.it
151
- @description = @description.join ""
152
- else
153
- @describe = @it = ""
154
- end
155
- end
156
- end
157
-
158
- module Kernel
159
- def opal_eval(str)
160
- code = Opal::Parser.new.parse str
161
- `eval(#{code})`
162
- end
163
-
164
- def opal_parse(str, file='(string)')
165
- Opal::Grammar.new.parse str, file
166
- end
167
-
168
- def opal_eval_compiled(javascript)
169
- `eval(javascript)`
170
- end
171
-
172
- def eval(str)
173
- opal_eval str
174
- end
175
- end
176
-
177
- module Kernel
178
- # FIXME: remove
179
- def ruby_version_is(*); end
180
- def pending(*); end
181
- def language_version(*); end
182
- end
183
-
184
- module MSpec
185
- def self.opal_runner
186
- @env = Object.new
187
- @env.extend MSpec
188
- end
189
- end
190
-
191
- class OSpecRunner
192
- def self.main
193
- @main ||= self.new
194
- end
195
-
196
- def initialize
197
- register
198
- run
199
- end
200
-
201
- def register
202
- formatter = PhantomFormatter.new
203
- formatter.register
204
-
205
- OSpecFilter.main.register
206
- end
207
-
208
- def run
209
- MSpec.opal_runner
210
- end
211
-
212
- def will_start
213
- MSpec.actions :start
214
- end
215
-
216
- def did_finish
217
- MSpec.actions :finish
218
- end
219
- end
220
-
221
- # As soon as this file loads, tell the runner the specs are starting
222
- OSpecRunner.main.will_start
223
-