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
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "The while keyword" do
4
+ it "returns an s(:while) with the given expr, body and true for head" do
5
+ parsed("while 1; 2; end").should == [:while, [:int, 1], [:int, 2]]
6
+ end
7
+
8
+ it "uses an s(:block) if body has more than one statement" do
9
+ parsed("while 1; 2; 3; end").should == [:while, [:int, 1], [:block, [:int, 2], [:int, 3]]]
10
+ end
11
+
12
+ it "treats the prefix while statement just like a regular while statement" do
13
+ parsed("1 while 2").should == [:while, [:int, 2], [:int, 1]]
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "The yield keyword" do
4
+ it "should return s(:yield) when no arguments given" do
5
+ parsed("yield").should == [:yield]
6
+ end
7
+
8
+ it "appends arguments onto end of s(:yield) without an arglist" do
9
+ parsed("yield 1").should == [:yield, [:int, 1]]
10
+ parsed("yield 1, 2").should == [:yield, [:int, 1], [:int, 2]]
11
+ parsed("yield 1, *2").should == [:yield, [:int, 1], [:splat, [:int, 2]]]
12
+ end
13
+
14
+ it "accepts parans for any number of arguments" do
15
+ parsed("yield()").should == [:yield]
16
+ parsed("yield(1)").should == [:yield, [:int, 1]]
17
+ parsed("yield(1, 2)").should == [:yield, [:int, 1], [:int, 2]]
18
+ parsed("yield(1, *2)").should == [:yield, [:int, 1], [:splat, [:int, 2]]]
19
+ end
20
+ end
@@ -1,17 +1,37 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
1
+ require 'opal'
2
+
3
+ module OpalSpecHelpers
4
+ def parsed(source, file='(string)')
5
+ Opal::Parser.new.parse(source, file)
6
+ end
7
+
8
+ def expect_parsed(source)
9
+ expect(parsed(source))
10
+ end
11
+
12
+ def expect_parsed_string(source)
13
+ expect(parsed(source)[1])
14
+ end
15
+
16
+ def expect_lines(source)
17
+ expect(parsed_nodes(source).map { |sexp| sexp.line })
18
+ end
19
+
20
+ def expect_columns(source)
21
+ expect(parsed_nodes(source).map { |sexp| sexp.column })
22
+ end
23
+
24
+ def parsed_nodes(source)
25
+ parsed = Opal::Parser.new.parse(source)
26
+ parsed.type == :block ? parsed.children : [parsed]
27
+ end
28
+ end
29
+
7
30
  RSpec.configure do |config|
8
31
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
32
  config.run_all_when_everything_filtered = true
10
33
  config.filter_run :focus
11
-
12
- # Run specs in random order to surface order dependencies. If you find an
13
- # order dependency and want to debug it, you can fix the order by providing
14
- # the seed, which is printed after each run.
15
- # --seed 1234
16
34
  config.order = 'random'
35
+
36
+ config.include OpalSpecHelpers
17
37
  end
@@ -0,0 +1,7 @@
1
+ describe "Array#[]=" do
2
+ it 'expands the array when assigning another array to a range' do
3
+ a = ['a']
4
+ a[3..4] = ['b', 'c']
5
+ a.should == ['a', nil, nil, 'b', 'c']
6
+ end
7
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ # rubyspec does not have specs for these listed methods
5
+ describe Date do
6
+ describe ".parse" do
7
+ it "parses a date string into a Date instance" do
8
+ Date.parse('2013-10-4').should == Date.new(2013, 10, 4)
9
+ Date.parse('2013-06-02').should == Date.new(2013, 6, 2)
10
+ end
11
+ end
12
+
13
+ describe "#<" do
14
+ it "is true when self is before other" do
15
+ (Date.new(2013, 2, 4) < Date.new(2013, 2, 5)).should == true
16
+ (Date.new(2013, 2, 4) < Date.new(2014, 7, 6)).should == true
17
+ end
18
+
19
+ it "is false when self is not before other" do
20
+ (Date.new(2013, 2, 4) < Date.new(2013, 2, 4)).should == false
21
+ (Date.new(2014, 2, 4) < Date.new(2013, 7, 6)).should == false
22
+ end
23
+ end
24
+
25
+ describe '#<=' do
26
+ it "is true when self is before or the same day as other" do
27
+ (Date.new(2013, 4, 5) <= Date.new(2013, 4, 5)).should == true
28
+ (Date.new(2013, 4, 5) <= Date.new(2013, 4, 9)).should == true
29
+ end
30
+
31
+ it "is false when self is after other" do
32
+ (Date.new(2013, 4, 5) <= Date.new(2013, 4, 2)).should == false
33
+ (Date.new(2013, 4, 5) <= Date.new(2013, 2, 5)).should == false
34
+ end
35
+ end
36
+
37
+ describe "#==" do
38
+ it "returns true if self is equal to other date" do
39
+ (Date.new(2013, 9, 13) == Date.new(2013, 9, 13)).should == true
40
+ end
41
+
42
+ it "returns false if self is not equal to other date" do
43
+ (Date.new(2013, 10, 2) == Date.new(2013, 10, 11)).should == false
44
+ end
45
+ end
46
+
47
+ describe "#clone" do
48
+ it "creates a copy of the current date" do
49
+ orig = Date.new(2013, 10, 15)
50
+ copy = orig.clone
51
+
52
+ orig.should == copy
53
+ orig.object_id.should_not == copy.object_id
54
+ end
55
+ end
56
+
57
+ describe "#day" do
58
+ it "returns the day of the date" do
59
+ Date.new(2013, 2, 10).day.should == 10
60
+ Date.new(2013, 2, 1).day.should == 1
61
+ end
62
+ end
63
+
64
+ describe "#month" do
65
+ it "returns the month of the date" do
66
+ Date.new(2013, 1, 23).month.should == 1
67
+ Date.new(2013, 12, 2).month.should == 12
68
+ end
69
+ end
70
+
71
+ describe "#next" do
72
+ it "returns the next date from self" do
73
+ Date.new(2013, 4, 6).next.should == Date.new(2013, 4, 7)
74
+ Date.new(2013, 6, 30).next.should == Date.new(2013, 7, 1)
75
+ Date.new(2013, 12, 31).next.should == Date.new(2014, 1, 1)
76
+ end
77
+ end
78
+
79
+ describe "#next_month" do
80
+ it "returns the date with the next calendar month to self" do
81
+ Date.new(2013, 2, 5).next_month.should == Date.new(2013, 3, 5)
82
+ Date.new(2013, 5, 31).next_month.should == Date.new(2013, 6, 30)
83
+ Date.new(2013, 12, 5).next_month.should == Date.new(2014, 1, 5)
84
+ end
85
+ end
86
+
87
+ describe "#prev" do
88
+ it "returns the previous date from self" do
89
+ Date.new(2013, 3, 5).prev.should == Date.new(2013, 3, 4)
90
+ Date.new(2013, 6, 1).prev.should == Date.new(2013, 5, 31)
91
+ Date.new(2014, 1, 1).prev.should == Date.new(2013, 12, 31)
92
+ end
93
+ end
94
+
95
+ describe "#prev_month" do
96
+ it "returns the date with the previous calendar month" do
97
+ Date.new(2013, 2, 9).prev_month.should == Date.new(2013, 1, 9)
98
+ Date.new(2013, 7, 31).prev_month.should == Date.new(2013, 6, 30)
99
+ Date.new(2013, 1, 3).prev_month.should == Date.new(2012, 12, 3)
100
+ end
101
+ end
102
+
103
+ describe "#to_s" do
104
+ it "returns an ISO 8601 representation" do
105
+ Date.new(2013, 10, 15).to_s.should == "2013-10-15"
106
+ Date.new(2013, 4, 9).to_s.should == "2013-04-09"
107
+ end
108
+ end
109
+
110
+ describe "#wday" do
111
+ it "returns the day of the week" do
112
+ Date.new(2001, 2, 3).wday.should == 6
113
+ Date.new(2001, 2, 4).wday.should == 0
114
+ end
115
+ end
116
+
117
+ describe "#year" do
118
+ it "returns the year as an integer" do
119
+ Date.new(2013, 2, 9).year.should == 2013
120
+ end
121
+ end
122
+ end
@@ -71,7 +71,7 @@ describe "The predefined global constants" do
71
71
 
72
72
  it "includes RUBY_VERSION" do
73
73
  Object.const_defined?(:RUBY_VERSION).should == true
74
- RUBY_VERSION.should == "1.9.3"
74
+ RUBY_VERSION.should == "2.0.0"
75
75
  end
76
76
 
77
77
  it "includes RUBY_RELEASE_DATE" do
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Operator calls" do
4
+ before { @obj = {:value => 10} }
5
+
6
+ it "compiles as a normal send method call" do
7
+ @obj[:value] += 15
8
+ @obj[:value].should == 25
9
+
10
+ @obj[:value] -= 23
11
+ @obj[:value].should == 2
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ class Boolean
2
+ def self_as_an_object
3
+ self
4
+ end
5
+ end
6
+
7
+ describe "Opal truthyness" do
8
+ it "should evaluate to true using js `true` as an object" do
9
+ if true.self_as_an_object
10
+ called = true
11
+ end
12
+
13
+ called.should be_true
14
+ end
15
+
16
+ it "should evaluate to false using js `false` as an object" do
17
+ if false.self_as_an_object
18
+ called = true
19
+ end
20
+
21
+ called.should be_nil
22
+ end
23
+ end
@@ -1,8 +1,5 @@
1
1
  opal_filter "Array" do
2
2
  fails "Array#clone copies singleton methods"
3
- fails "Array#clone creates a new array containing all elements or the original"
4
-
5
- fails "Array#collect! returns an Enumerator when no block given, and the enumerator can modify the original array"
6
3
 
7
4
  fails "Array#combination generates from a defensive copy, ignoring mutations"
8
5
  fails "Array#combination yields a partition consisting of only singletons"
@@ -17,48 +14,23 @@ opal_filter "Array" do
17
14
  fails "Array#<=> calls <=> left to right and return first non-0 result"
18
15
  fails "Array#<=> returns -1 if the arrays have same length and a pair of corresponding elements returns -1 for <=>"
19
16
  fails "Array#<=> returns +1 if the arrays have same length and a pair of corresponding elements returns +1 for <=>"
20
- fails "Array#<=> properly handles recursive arrays"
21
17
  fails "Array#<=> tries to convert the passed argument to an Array using #to_ary"
22
18
  fails "Array#<=> returns nil when the argument is not array-like"
23
19
 
24
- fails "Array#concat tries to convert the passed argument to an Array using #to_ary"
25
- fails "Array#concat is not infected by the other"
26
-
27
- fails "Array#delete_at tries to convert the passed argument to an Integer using #to_int"
28
-
29
- fails "Array#delete_if returns an Enumerator if no block given, and the enumerator can modify the original array"
30
-
31
20
  fails "Array#delete may be given a block that is executed if no element matches object"
32
21
  fails "Array#delete returns the last element in the array for which object is equal under #=="
33
22
 
34
- fails "Array#dup creates a new array containing all elements or the original"
35
-
36
23
  fails "Array.[] can unpack 2 or more nested referenced array"
37
24
 
38
25
  fails "Array#[]= sets elements in the range arguments when passed ranges"
39
26
 
40
- fails "Array#eql? ignores array class differences"
41
- fails "Array#eql? handles well recursive arrays"
42
- fails "Array#eql? returns true if corresponding elements are #eql?"
43
-
44
- fails "Array#== compares with an equivalent Array-like object using #to_ary"
45
- fails "Array#== handles well recursive arrays"
46
-
47
- fails "Array#fetch tries to convert the passed argument to an Integer using #to_int"
48
- fails "Array#fetch raises a TypeError when the passed argument can't be coerced to Integer"
49
-
50
- fails "Array#first tries to convert the passed argument to an Integer using #to_int"
51
- fails "Array#first raises a TypeError if the passed argument is not numeric"
52
-
53
27
  fails "Array#flatten does not call flatten on elements"
54
- fails "Array#flatten raises an ArgumentError on recursive arrays"
55
28
  fails "Array#flatten with a non-Array object in the Array ignores the return value of #to_ary if it is nil"
56
29
  fails "Array#flatten with a non-Array object in the Array raises a TypeError if the return value of #to_ary is not an Array"
57
30
  fails "Array#flatten raises a TypeError when the passed Object can't be converted to an Integer"
58
31
  fails "Array#flatten tries to convert passed Objects to Integers using #to_int"
59
32
 
60
33
  fails "Array#flatten! does not call flatten! on elements"
61
- fails "Array#flatten! raises an ArgumentError on recursive arrays"
62
34
  fails "Array#flatten! flattens any elements which responds to #to_ary, using the return value of said method"
63
35
  fails "Array#flatten! raises a TypeError when the passed Object can't be converted to an Integer"
64
36
  fails "Array#flatten! tries to convert passed Objects to Integers using #to_int"
@@ -76,35 +48,11 @@ opal_filter "Array" do
76
48
  fails "Array#initialize with (array) calls #to_ary to convert the value to an array"
77
49
  fails "Array#initialize preserves the object's identity even when changing its value"
78
50
 
79
- fails "Array#insert tries to convert the passed position argument to an Integer using #to_int"
80
-
81
- fails "Array#join raises an ArgumentError when the Array is recursive"
82
- fails "Array#join raises a NoMethodError if an element does not respond to #to_str, #to_ary, or #to_s"
83
- fails "Array#join attempts coercion via #to_str first"
84
- fails "Array#join attempts coercion via #to_ary second"
85
- fails "Array#join attempts coercion via #to_s third"
86
- fails "Array#join separates elements with default separator when the passed separator is nil"
87
- fails "Array#join returns a string formed by concatenating each String element separated by $,"
88
- fails "Array#join uses the same separator with nested arrays"
89
- fails "Array#join returns a string formed by concatenating each element.to_str separated by separator"
90
-
91
- fails "Array#& properly handles recursive arrays"
92
- fails "Array#& tries to convert the passed argument to an Array using #to_ary"
93
51
  fails "Array#& determines equivalence between elements in the sense of eql?"
94
52
 
95
- fails "Array#join calls #to_str to convert the separator to a String"
96
- fails "Array#join does not call #to_str on the separator if the array is empty"
97
- fails "Array#join raises a TypeError if the separator cannot be coerced to a String by calling #to_str"
98
- fails "Array#join raises a TypeError if passed false as the separator"
99
-
100
- fails "Array#last tries to convert the passed argument to an Integer usinig #to_int"
101
-
102
- fails "Array#map! returns an Enumerator when no block given, and the enumerator can modify the original array"
103
-
104
53
  fails "Array#- removes an identical item even when its #eql? isn't reflexive"
105
54
  fails "Array#- doesn't remove an item with the same hash but not #eql?"
106
55
  fails "Array#- removes an item identified as equivalent via #hash and #eql?"
107
- fails "Array#- tries to convert the passed arguments to Arrays using #to_ary"
108
56
 
109
57
  fails "Array#* raises a TypeError is the passed argument is nil"
110
58
  fails "Array#* converts the passed argument to a String rather than an Integer"
@@ -120,29 +68,80 @@ opal_filter "Array" do
120
68
  fails "Array.new with (size, object=nil) calls #to_int to convert the size argument to an Integer when object is not given"
121
69
  fails "Array.new with (size, object=nil) raises a TypeError if the size argument is not an Integer type"
122
70
 
123
- fails "Array#+ tries to convert the passed argument to an Array using #to_ary"
124
-
125
- fails "Array#pop passed a number n as an argument raises an ArgumentError if more arguments are passed"
126
- fails "Array#pop passed a number n as an argument raises a TypeError when the passed n can be coerced to Integer"
127
- fails "Array#pop passed a number n as an argument tries to convert n to an Integer using #to_int"
71
+ fails "Array#permutation generates from a defensive copy, ignoring mutations"
72
+ fails "Array#permutation returns an Enumerator which works as expected even when the array was modified"
73
+ fails "Array#permutation truncates Float arguments"
74
+ fails "Array#permutation handles nested Arrays correctly"
75
+ fails "Array#permutation handles duplicate elements correctly"
76
+ fails "Array#permutation returns no permutations when the given length has no permutations"
77
+ fails "Array#permutation returns the empty permutation([]) when called on an empty Array"
78
+ fails "Array#permutation returns the empty permutation ([[]]) when the given length is 0"
79
+ fails "Array#permutation yields all permutations of given length to the block then returns self when called with block and argument"
80
+ fails "Array#permutation yields all permutations to the block then returns self when called with block but no arguments"
81
+ fails "Array#permutation returns an Enumerator of permutations of given length when called with an argument but no block"
82
+ fails "Array#permutation returns an Enumerator of all permutations when called without a block or arguments"
83
+
84
+ fails "Array#product when given an empty block returns self"
85
+ fails "Array#product when given a block will ignore unreasonable numbers of products and yield anyway"
86
+ fails "Array#product when given a block yields all combinations in turn"
87
+ fails "Array#product does not attempt to produce an unreasonable number of products"
88
+ fails "Array#product returns an empty array when the argument is an empty array"
89
+ fails "Array#product has no required argument"
90
+ fails "Array#product returns the expected result"
91
+ fails "Array#product returns converted arguments using :to_ary"
128
92
 
129
93
  fails "Array#rassoc does not check the last element in each contained but speficically the second"
130
94
  fails "Array#rassoc calls elem == obj on the second element of each contained array"
131
95
 
132
- fails "Array#replace tries to convert the passed argument to an Array using #to_ary"
96
+ fails "Array#repeated_combination generates from a defensive copy, ignoring mutations"
97
+ fails "Array#repeated_combination accepts sizes larger than the original array"
98
+ fails "Array#repeated_combination yields a partition consisting of only singletons"
99
+ fails "Array#repeated_combination yields nothing when the array is empty and num is non zero"
100
+ fails "Array#repeated_combination yields [] when length is 0"
101
+ fails "Array#repeated_combination yields the expected repeated_combinations"
102
+ fails "Array#repeated_combination yields nothing for negative length and return self"
103
+ fails "Array#repeated_combination returns self when a block is given"
104
+ fails "Array#repeated_combination returns an enumerator when no block is provided"
105
+
106
+ fails "Array#repeated_permutation generates from a defensive copy, ignoring mutations"
107
+ fails "Array#repeated_permutation allows permutations larger than the number of elements"
108
+ fails "Array#repeated_permutation returns an Enumerator which works as expected even when the array was modified"
109
+ fails "Array#repeated_permutation truncates Float arguments"
110
+ fails "Array#repeated_permutation handles duplicate elements correctly"
111
+ fails "Array#repeated_permutation does not yield when called on an empty Array with a nonzero argument"
112
+ fails "Array#repeated_permutation yields the empty repeated_permutation ([[]]) when the given length is 0"
113
+ fails "Array#repeated_permutation yields all repeated_permutations to the block then returns self when called with block but no arguments"
114
+ fails "Array#repeated_permutation returns an Enumerator of all repeated permutations of given length when called without a block"
133
115
 
134
116
  fails "Array#rindex rechecks the array size during iteration"
135
117
 
136
- fails "Array#select returns a new array of elements for which block is true"
118
+ fails "Array#rotate! with an argument n raises a TypeError if not passed an integer-like argument"
119
+ fails "Array#rotate! with an argument n coerces the argument using to_int"
120
+ fails "Array#rotate! with an argument n moves the first (n % size) elements at the end and returns self"
121
+ fails "Array#rotate! when passed no argument moves the first element to the end and returns self"
122
+ fails "Array#rotate! raises a RuntimeError on a frozen array"
123
+ fails "Array#rotate! does nothing and returns self when the length is zero or one"
124
+ fails "Array#rotate with an argument n raises a TypeError if not passed an integer-like argument"
125
+ fails "Array#rotate with an argument n coerces the argument using to_int"
126
+ fails "Array#rotate with an argument n returns a copy of the array with the first (n % size) elements moved at the end"
127
+ fails "Array#rotate when passed no argument returns a copy of the array with the first element moved at the end"
128
+ fails "Array#rotate does not return subclass instance for Array subclasses"
129
+ fails "Array#rotate does not return self"
130
+ fails "Array#rotate does not mutate the receiver"
131
+ fails "Array#rotate returns a copy of the array when its length is one or zero"
132
+
133
+ fails "Array#sample raises a RangeError if the value is equal to the Array size"
134
+ fails "Array#sample raises a RangeError if the value is less than zero"
135
+ fails "Array#sample calls #to_int on the Object returned by #rand"
136
+ fails "Array#sample ignores an Object passed for the RNG if it does not define #rand"
137
+ fails "Array#sample calls #rand on the Object passed by the :random key in the arguments Hash"
138
+ fails "Array#sample calls #to_int on the first argument and #to_hash on the second when passed Objects"
139
+ fails "Array#sample calls #to_hash to convert the passed Object"
140
+ fails "Array#sample raises ArgumentError when passed a negative count"
141
+ fails "Array#sample calls #to_int to convert the count when passed an Object"
142
+ fails "Array#sample does not return the same value if the Array has unique values"
143
+ fails "Array#sample returns at most the number of elements in the Array"
137
144
 
138
- fails "Array#shift passed a number n as an argument raises an ArgumentError if more arguments are passed"
139
- fails "Array#shift passed a number n as an argument raises a TypeError when the passed n can be coerced to Integer"
140
- fails "Array#shift passed a number n as an argument tries to convert n to an Integer using #to_int"
141
- fails "Array#shift passed a number n as an argument raises an ArgumentError if n is negative"
142
- fails "Array#shift passed a number n as an argument returns a new empty array if there are no more elements"
143
-
144
- fails "Array#shuffle uses given random generator"
145
- fails "Array#shuffle uses default random generator"
146
145
  fails "Array#shuffle attempts coercion via #to_hash"
147
146
  fails "Array#shuffle is not destructive"
148
147
  fails "Array#shuffle returns the same values, in a usually different order"
@@ -155,39 +154,29 @@ opal_filter "Array" do
155
154
 
156
155
  fails "Array#shuffle! returns the same values, in a usually different order"
157
156
 
158
- fails "Array#slice raises a RangeError when the length is out of range of Fixnum"
159
- fails "Array#slice raises a RangeError when the start index is out of range of Fixnum"
160
- fails "Array#slice returns nil if range start is not in the array with [m..n]"
161
- fails "Array#slice tries to convert Range elements to Integers using #to_int with [m..n] and [m...n]"
162
- fails "Array#slice accepts Range instances having a negative m and both signs for n with [m..n] and [m...n]"
163
- fails "Array#slice tries to convert the passed argument to an Integer using #to_int"
164
-
165
157
  fails "Array#slice! does not expand array with negative indices out of bounds"
166
158
  fails "Array#slice! does not expand array with indices out of bounds"
167
159
  fails "Array#slice! calls to_int on range arguments"
168
160
  fails "Array#slice! removes and return elements in range"
169
161
  fails "Array#slice! calls to_int on start and length arguments"
170
162
 
171
- fails "Array#transpose raises a TypeError if the passed Argument does not respond to #to_ary"
172
- fails "Array#transpose tries to convert the passed argument to an Array using #to_ary"
173
-
174
- fails "Array.try_convert does not rescue exceptions raised by #to_ary"
175
- fails "Array.try_convert sends #to_ary to the argument and raises TypeError if it's not a kind of Array"
176
- fails "Array.try_convert sends #to_ary to the argument and returns the result if it's a kind of Array"
177
- fails "Array.try_convert sends #to_ary to the argument and returns the result if it's an Array"
178
- fails "Array.try_convert sends #to_ary to the argument and returns the result if it's nil"
163
+ fails "Array#sort_by! makes some modification even if finished sorting when it would break in the given block"
164
+ fails "Array#sort_by! returns the specified value when it would break in the given block"
165
+ fails "Array#sort_by! raises a RuntimeError on an empty frozen array"
166
+ fails "Array#sort_by! raises a RuntimeError on a frozen array"
167
+ fails "Array#sort_by! completes when supplied a block that always returns the same result"
168
+ fails "Array#sort_by! returns an Enumerator if not given a block"
169
+ fails "Array#sort_by! sorts array in place by passing each element to the given block"
179
170
 
180
171
  fails "Array#uniq compares elements based on the value returned from the block"
181
172
  fails "Array#uniq compares elements with matching hash codes with #eql?"
182
173
  fails "Array#uniq uses eql? semantics"
183
174
 
184
175
  fails "Array#uniq! compares elements based on the value returned from the block"
185
- fails "Array#uniq! properly handles recursive arrays"
186
176
 
187
177
  fails "Array#values_at returns an array of elements at the indexes when passed indexes"
188
178
  fails "Array#values_at calls to_int on its indices"
189
179
  fails "Array#values_at returns an array of elements in the ranges when passes ranges"
190
- fails "Array#values_at properly handles recursive arrays"
191
180
  fails "Array#values_at calls to_int on arguments of ranges when passes ranges"
192
181
  fails "Array#values_at does not return subclass instance on Array subclasses"
193
182
 
@@ -198,12 +187,32 @@ opal_filter "Array" do
198
187
  fails "Array#hash returns same hash code for arrays with the same content"
199
188
  fails "Array#hash ignores array class differences"
200
189
  fails "Array#hash calls to_int on result of calling hash on each element"
201
- fails "Array#hash returns the same hash for equal recursive arrays through hashes"
202
- fails "Array#hash returns the same hash for equal recursive arrays"
203
190
  fails "Array#hash returns the same fixnum for arrays with the same content"
204
191
 
205
- fails "Array#partition properly handles recursive arrays"
206
192
  fails "Array#partition returns in the left array values for which the block evaluates to true"
207
193
  fails "Array#partition returns two arrays"
208
194
  fails "Array#partition does not return subclass instances on Array subclasses"
195
+
196
+ fails "Array#| does not call to_ary on array subclasses"
197
+ fails "Array#| does not return subclass instances for Array subclasses"
198
+ fails "Array#| acts as if using an intermediate hash to collect values"
199
+ fails "Array#| tries to convert the passed argument to an Array using #to_ary"
200
+ fails "Array#| creates an array with elements in order they are first encountered"
201
+ fails "Array#| creates an array with no duplicates"
202
+ fails "Array#| returns an array of elements that appear in either array (union)"
203
+
204
+ # recursive arrays
205
+ fails "Array#join raises an ArgumentError when the Array is recursive"
206
+ fails "Array#uniq! properly handles recursive arrays"
207
+ fails "Array#| properly handles recursive arrays"
208
+ fails "Array#<=> properly handles recursive arrays"
209
+ fails "Array#eql? handles well recursive arrays"
210
+ fails "Array#== handles well recursive arrays"
211
+ fails "Array#flatten raises an ArgumentError on recursive arrays"
212
+ fails "Array#flatten! raises an ArgumentError on recursive arrays"
213
+ fails "Array#partition properly handles recursive arrays"
214
+ fails "Array#& properly handles recursive arrays"
215
+ fails "Array#values_at properly handles recursive arrays"
216
+ fails "Array#hash returns the same hash for equal recursive arrays through hashes"
217
+ fails "Array#hash returns the same hash for equal recursive arrays"
209
218
  end