opal 1.1.0.rc1 → 1.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +4 -4
  3. data/.github/ISSUE_TEMPLATE/bug-report.md +47 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/workflows/build.yml +11 -5
  6. data/.gitignore +1 -0
  7. data/.jshintrc +1 -1
  8. data/CHANGELOG.md +42 -1
  9. data/Gemfile +0 -4
  10. data/HACKING.md +1 -1
  11. data/LICENSE +1 -1
  12. data/README.md +20 -16
  13. data/UNRELEASED.md +32 -95
  14. data/benchmark-ips/bm_array_unshift.rb +7 -0
  15. data/benchmark-ips/bm_js_symbols_vs_strings.rb +7 -2
  16. data/bin/build-browser-source-map-support +2 -3
  17. data/bin/opal-mspec +2 -0
  18. data/docs/compiler.md +1 -1
  19. data/examples/rack/Gemfile +0 -1
  20. data/examples/rack/Gemfile.lock +0 -4
  21. data/lib/opal/cli.rb +1 -0
  22. data/lib/opal/cli_options.rb +4 -0
  23. data/lib/opal/cli_runners/nodejs.rb +5 -1
  24. data/lib/opal/cli_runners/source-map-support-browser.js +8 -2
  25. data/lib/opal/cli_runners/source-map-support-node.js +3706 -0
  26. data/lib/opal/cli_runners/source-map-support.js +3 -1
  27. data/lib/opal/compiler.rb +2 -2
  28. data/lib/opal/nodes/args/arity_check.rb +1 -0
  29. data/lib/opal/nodes/args/parameters.rb +6 -0
  30. data/lib/opal/nodes/class.rb +1 -13
  31. data/lib/opal/nodes/literal.rb +14 -7
  32. data/lib/opal/nodes/module.rb +13 -9
  33. data/lib/opal/nodes/variables.rb +13 -4
  34. data/lib/opal/nodes/while.rb +54 -17
  35. data/lib/opal/parser.rb +1 -5
  36. data/lib/opal/parser/patch.rb +34 -0
  37. data/lib/opal/repl.rb +7 -0
  38. data/lib/opal/rewriter.rb +2 -0
  39. data/lib/opal/rewriters/arguments.rb +4 -1
  40. data/lib/opal/rewriters/forward_args.rb +54 -0
  41. data/lib/opal/rewriters/logical_operator_assignment.rb +5 -2
  42. data/lib/opal/rewriters/opal_engine_check.rb +5 -7
  43. data/lib/opal/version.rb +1 -1
  44. data/opal.gemspec +1 -1
  45. data/opal/corelib/array.rb +42 -20
  46. data/opal/corelib/array/pack.rb +6 -1
  47. data/opal/corelib/complex.rb +2 -0
  48. data/opal/corelib/constants.rb +3 -3
  49. data/opal/corelib/hash.rb +36 -38
  50. data/opal/corelib/module.rb +2 -7
  51. data/opal/corelib/number.rb +2 -180
  52. data/opal/corelib/numeric.rb +156 -0
  53. data/opal/corelib/object_space.rb +102 -0
  54. data/opal/corelib/random.rb +31 -66
  55. data/opal/corelib/random/formatter.rb +122 -0
  56. data/opal/corelib/range.rb +50 -19
  57. data/opal/corelib/runtime.js +82 -21
  58. data/opal/corelib/string.rb +86 -52
  59. data/opal/corelib/string/encoding.rb +140 -25
  60. data/opal/corelib/string/unpack.rb +26 -40
  61. data/opal/opal.rb +1 -0
  62. data/opal/opal/full.rb +1 -0
  63. data/package.json +1 -1
  64. data/spec/filters/bugs/array.rb +0 -22
  65. data/spec/filters/bugs/basicobject.rb +3 -0
  66. data/spec/filters/bugs/encoding.rb +0 -2
  67. data/spec/filters/bugs/exception.rb +1 -0
  68. data/spec/filters/bugs/float.rb +0 -2
  69. data/spec/filters/bugs/hash.rb +2 -7
  70. data/spec/filters/bugs/integer.rb +0 -2
  71. data/spec/filters/bugs/kernel.rb +16 -3
  72. data/spec/filters/bugs/language.rb +6 -14
  73. data/spec/filters/bugs/marshal.rb +1 -3
  74. data/spec/filters/bugs/module.rb +16 -1
  75. data/spec/filters/bugs/numeric.rb +4 -12
  76. data/spec/filters/bugs/objectspace.rb +67 -0
  77. data/spec/filters/bugs/pack_unpack.rb +0 -9
  78. data/spec/filters/bugs/pathname.rb +1 -0
  79. data/spec/filters/bugs/proc.rb +8 -0
  80. data/spec/filters/bugs/random.rb +3 -6
  81. data/spec/filters/bugs/range.rb +83 -113
  82. data/spec/filters/bugs/set.rb +2 -0
  83. data/spec/filters/bugs/string.rb +31 -70
  84. data/spec/filters/bugs/struct.rb +2 -0
  85. data/spec/filters/bugs/time.rb +8 -2
  86. data/spec/filters/unsupported/float.rb +3 -0
  87. data/spec/filters/unsupported/freeze.rb +1 -0
  88. data/spec/filters/unsupported/integer.rb +3 -0
  89. data/spec/filters/unsupported/refinements.rb +5 -0
  90. data/spec/filters/unsupported/string.rb +100 -95
  91. data/spec/filters/unsupported/time.rb +4 -0
  92. data/spec/lib/compiler_spec.rb +16 -0
  93. data/spec/lib/rewriters/forward_args_spec.rb +61 -0
  94. data/spec/lib/rewriters/logical_operator_assignment_spec.rb +1 -1
  95. data/spec/lib/rewriters/numblocks_spec.rb +44 -0
  96. data/spec/lib/rewriters/opal_engine_check_spec.rb +49 -4
  97. data/spec/opal/core/language/forward_args_spec.rb +53 -0
  98. data/spec/opal/core/language/infinite_range_spec.rb +13 -0
  99. data/spec/opal/core/language/memoization_spec.rb +16 -0
  100. data/spec/opal/core/module_spec.rb +38 -2
  101. data/spec/opal/core/number/to_i_spec.rb +28 -0
  102. data/spec/opal/core/runtime/bridged_classes_spec.rb +16 -0
  103. data/spec/opal/core/runtime/constants_spec.rb +20 -1
  104. data/spec/opal/core/string/subclassing_spec.rb +16 -0
  105. data/spec/opal/core/string/unpack_spec.rb +22 -0
  106. data/spec/opal/core/string_spec.rb +4 -4
  107. data/spec/ruby_specs +4 -1
  108. data/stdlib/json.rb +3 -1
  109. data/stdlib/securerandom.rb +55 -35
  110. data/tasks/testing.rake +6 -3
  111. data/test/nodejs/test_string.rb +25 -0
  112. data/vendored-minitest/minitest/assertions.rb +2 -0
  113. metadata +35 -12
  114. data/lib/opal/parser/with_c_lexer.rb +0 -15
@@ -6,22 +6,24 @@ class Encoding
6
6
  ascii = options[:ascii] || false
7
7
  dummy = options[:dummy] || false
8
8
 
9
- encoding = new(name, names, ascii, dummy)
10
- encoding.instance_eval(&block)
9
+ if options[:inherits]
10
+ encoding = options[:inherits].clone
11
+ encoding.initialize(name, names, ascii, dummy)
12
+ else
13
+ encoding = new(name, names, ascii, dummy)
14
+ end
15
+ encoding.instance_eval(&block) if block_given?
11
16
 
12
17
  register = `Opal.encodings`
13
18
  names.each do |encoding_name|
14
- const_set encoding_name.sub('-', '_'), encoding
19
+ const_set encoding_name.tr('-', '_'), encoding
15
20
  register.JS[encoding_name] = encoding
16
21
  end
17
22
  end
18
23
 
19
24
  def self.find(name)
20
25
  return default_external if name == :default_external
21
- register = `Opal.encodings`
22
- encoding = register.JS[name] || register.JS[name.upcase]
23
- raise ArgumentError, "unknown encoding name - #{name}" unless encoding
24
- encoding
26
+ `return Opal.find_encoding(name)`
25
27
  end
26
28
 
27
29
  singleton_class.attr_accessor :default_external
@@ -43,6 +45,10 @@ class Encoding
43
45
  @dummy
44
46
  end
45
47
 
48
+ def binary?
49
+ false
50
+ end
51
+
46
52
  def to_s
47
53
  @name
48
54
  end
@@ -52,6 +58,41 @@ class Encoding
52
58
  end
53
59
 
54
60
  # methods to implement per encoding
61
+ def charsize(string)
62
+ %x{
63
+ var len = 0;
64
+ for (var i = 0, length = string.length; i < length; i++) {
65
+ var charcode = string.charCodeAt(i);
66
+ if (!(charcode >= 0xD800 && charcode <= 0xDBFF)) {
67
+ len++;
68
+ }
69
+ }
70
+ return len;
71
+ }
72
+ end
73
+
74
+ def each_char(string, &block)
75
+ %x{
76
+ var low_surrogate = "";
77
+ for (var i = 0, length = string.length; i < length; i++) {
78
+ var charcode = string.charCodeAt(i);
79
+ var chr = string.charAt(i);
80
+ if (charcode >= 0xDC00 && charcode <= 0xDFFF) {
81
+ low_surrogate = chr;
82
+ continue;
83
+ }
84
+ else if (charcode >= 0xD800 && charcode <= 0xDBFF) {
85
+ chr = low_surrogate + chr;
86
+ }
87
+ if (string.encoding.name != "UTF-8") {
88
+ chr = new String(chr);
89
+ chr.encoding = string.encoding;
90
+ }
91
+ Opal.yield1(block, chr);
92
+ }
93
+ }
94
+ end
95
+
55
96
  def each_byte(*)
56
97
  raise NotImplementedError
57
98
  end
@@ -173,11 +214,11 @@ Encoding.register 'UTF-16LE' do
173
214
  end
174
215
 
175
216
  def bytesize(string)
176
- string.bytes.length
217
+ `string.length * 2`
177
218
  end
178
219
  end
179
220
 
180
- Encoding.register 'UTF-16BE' do
221
+ Encoding.register 'UTF-16BE', inherits: Encoding::UTF_16LE do
181
222
  def each_byte(string, &block)
182
223
  %x{
183
224
  for (var i = 0, length = string.length; i < length; i++) {
@@ -188,10 +229,6 @@ Encoding.register 'UTF-16BE' do
188
229
  }
189
230
  }
190
231
  end
191
-
192
- def bytesize(string)
193
- string.bytes.length
194
- end
195
232
  end
196
233
 
197
234
  Encoding.register 'UTF-32LE' do
@@ -202,31 +239,68 @@ Encoding.register 'UTF-32LE' do
202
239
 
203
240
  #{yield `code & 0xff`};
204
241
  #{yield `code >> 8`};
242
+ #{yield 0};
243
+ #{yield 0};
205
244
  }
206
245
  }
207
246
  end
208
247
 
209
248
  def bytesize(string)
210
- string.bytes.length
249
+ `string.length * 4`
211
250
  end
212
251
  end
213
252
 
214
- Encoding.register 'ASCII-8BIT', aliases: ['BINARY', 'US-ASCII', 'ASCII'], ascii: true, dummy: true do
253
+ Encoding.register 'UTF-32BE', inherits: Encoding::UTF_32LE do
215
254
  def each_byte(string, &block)
216
255
  %x{
217
256
  for (var i = 0, length = string.length; i < length; i++) {
218
257
  var code = string.charCodeAt(i);
219
- #{yield `code & 0xff`};
258
+
259
+ #{yield 0};
260
+ #{yield 0};
220
261
  #{yield `code >> 8`};
262
+ #{yield `code & 0xff`};
263
+ }
264
+ }
265
+ end
266
+ end
267
+
268
+ Encoding.register 'ASCII-8BIT', aliases: ['BINARY'], ascii: true do
269
+ def each_char(string, &block)
270
+ %x{
271
+ for (var i = 0, length = string.length; i < length; i++) {
272
+ var chr = new String(string.charAt(i));
273
+ chr.encoding = string.encoding;
274
+ #{yield `chr`};
275
+ }
276
+ }
277
+ end
278
+
279
+ def charsize(string)
280
+ `string.length`
281
+ end
282
+
283
+ def each_byte(string, &block)
284
+ %x{
285
+ for (var i = 0, length = string.length; i < length; i++) {
286
+ var code = string.charCodeAt(i);
287
+ #{yield `code & 0xff`};
221
288
  }
222
289
  }
223
290
  end
224
291
 
225
292
  def bytesize(string)
226
- string.bytes.length
293
+ `string.length`
294
+ end
295
+
296
+ def binary?
297
+ true
227
298
  end
228
299
  end
229
300
 
301
+ Encoding.register 'ISO-8859-1', aliases: ['ISO8859-1'], ascii: true, inherits: Encoding::ASCII_8BIT
302
+ Encoding.register 'US-ASCII', aliases: ['ASCII'], ascii: true, inherits: Encoding::ASCII_8BIT
303
+
230
304
  class String
231
305
  attr_reader :encoding
232
306
  attr_reader :internal_encoding
@@ -234,9 +308,8 @@ class String
234
308
  `Opal.defineProperty(String.prototype, 'encoding', #{Encoding::UTF_8})`
235
309
  `Opal.defineProperty(String.prototype, 'internal_encoding', #{Encoding::UTF_8})`
236
310
 
237
- def bytes
238
- @bytes ||= each_byte.to_a
239
- @bytes.dup
311
+ def b
312
+ dup.force_encoding('binary')
240
313
  end
241
314
 
242
315
  def bytesize
@@ -244,13 +317,40 @@ class String
244
317
  end
245
318
 
246
319
  def each_byte(&block)
247
- return enum_for :each_byte unless block_given?
320
+ return enum_for(:each_byte) { bytesize } unless block_given?
248
321
 
249
322
  @internal_encoding.each_byte(self, &block)
250
323
 
251
324
  self
252
325
  end
253
326
 
327
+ def bytes
328
+ # REMIND: required when running in strict mode, otherwise the following error will be thrown:
329
+ # Cannot create property 'bytes' on string 'abc'
330
+ %x{
331
+ if (typeof self === 'string') {
332
+ return #{`new String(self)`.each_byte.to_a};
333
+ }
334
+ }
335
+
336
+ @bytes ||= each_byte.to_a
337
+ @bytes.dup
338
+ end
339
+
340
+ def each_char(&block)
341
+ return enum_for(:each_char) { length } unless block_given?
342
+
343
+ @encoding.each_char(self, &block)
344
+
345
+ self
346
+ end
347
+
348
+ def chars(&block)
349
+ return each_char.to_a unless block
350
+
351
+ each_char(&block)
352
+ end
353
+
254
354
  def each_codepoint(&block)
255
355
  return enum_for :each_codepoint unless block_given?
256
356
  %x{
@@ -273,16 +373,18 @@ class String
273
373
 
274
374
  def force_encoding(encoding)
275
375
  %x{
276
- if (encoding === self.encoding) { return self; }
376
+ var str = self;
377
+
378
+ if (encoding === str.encoding) { return str; }
277
379
 
278
380
  encoding = #{Opal.coerce_to!(encoding, String, :to_s)};
279
381
  encoding = #{Encoding.find(encoding)};
280
382
 
281
- if (encoding === self.encoding) { return self; }
383
+ if (encoding === str.encoding) { return str; }
282
384
 
283
- Opal.set_encoding(self, encoding);
385
+ str = Opal.set_encoding(str, encoding);
284
386
 
285
- return self;
387
+ return str;
286
388
  }
287
389
  end
288
390
 
@@ -294,6 +396,19 @@ class String
294
396
  string_bytes[idx]
295
397
  end
296
398
 
399
+ def initialize_copy(other)
400
+ %{
401
+ self.encoding = other.encoding;
402
+ self.internal_encoding = other.internal_encoding;
403
+ }
404
+ end
405
+
406
+ def length
407
+ `self.length`
408
+ end
409
+
410
+ alias size length
411
+
297
412
  # stub
298
413
  def valid_encoding?
299
414
  true
@@ -42,38 +42,6 @@ class String
42
42
  }
43
43
  }
44
44
 
45
- function utf16LEToBytes(string) {
46
- var utf8 = [];
47
- for (var i=0; i < string.length; i++) {
48
- var charcode = string.charCodeAt(i);
49
- if (charcode < 0x100) utf8.push(charcode);
50
- else if (charcode < 0x800) {
51
- utf8.push(0xc0 | (charcode >> 6),
52
- 0x80 | (charcode & 0x3f));
53
- }
54
- else if (charcode < 0xd800 || charcode >= 0xe000) {
55
- utf8.push(0xe0 | (charcode >> 12),
56
- 0x80 | ((charcode>>6) & 0x3f),
57
- 0x80 | (charcode & 0x3f));
58
- }
59
- // surrogate pair
60
- else {
61
- i++;
62
- // UTF-16 encodes 0x10000-0x10FFFF by
63
- // subtracting 0x10000 and splitting the
64
- // 20 bits of 0x0-0xFFFFF into two halves
65
- charcode = 0x10000 + (((charcode & 0x3ff)<<10)
66
- | (string.charCodeAt(i) & 0x3ff))
67
- utf8.push(0xf0 | (charcode >>18),
68
- 0x80 | ((charcode>>12) & 0x3f),
69
- 0x80 | ((charcode>>6) & 0x3f),
70
- 0x80 | (charcode & 0x3f));
71
- }
72
- }
73
-
74
- return utf8;
75
- }
76
-
77
45
  function toNByteSigned(bytesCount, callback) {
78
46
  return function(data) {
79
47
  var unsignedBits = callback(data),
@@ -321,9 +289,11 @@ class String
321
289
  }
322
290
 
323
291
  function readUnicodeCharChunk(bytes) {
292
+ var currentByteIndex = 0;
293
+ var bytesLength = bytes.length;
324
294
  function readByte() {
325
- var result = bytes[0];
326
- bytes = bytes.slice(1, bytes.length);
295
+ var result = bytes[currentByteIndex++];
296
+ bytesLength = bytes.length - currentByteIndex;
327
297
  return result;
328
298
  }
329
299
 
@@ -331,7 +301,7 @@ class String
331
301
 
332
302
  if (c >> 7 == 0) {
333
303
  // 0xxx xxxx
334
- return { chunk: [c], rest: bytes };
304
+ return { chunk: [c], rest: bytes.slice(currentByteIndex) };
335
305
  }
336
306
 
337
307
  if (c >> 6 == 0x02) {
@@ -357,10 +327,10 @@ class String
357
327
  #{raise 'malformed UTF-8 character'}
358
328
  }
359
329
 
360
- if (extraLength > bytes.length) {
330
+ if (extraLength > bytesLength) {
361
331
  #{
362
332
  expected = `extraLength + 1`
363
- given = `bytes.length + 1`
333
+ given = `bytesLength + 1`
364
334
  raise ArgumentError, "malformed UTF-8 character (expected #{expected} bytes, given #{given} bytes)"
365
335
  }
366
336
  }
@@ -380,12 +350,12 @@ class String
380
350
  }
381
351
 
382
352
  if (result <= 0xffff) {
383
- return { chunk: [result], rest: bytes };
353
+ return { chunk: [result], rest: bytes.slice(currentByteIndex) };
384
354
  } else {
385
355
  result -= 0x10000;
386
356
  var high = ((result >> 10) & 0x3ff) + 0xd800,
387
357
  low = (result & 0x3ff) + 0xdc00;
388
- return { chunk: [high, low], rest: bytes };
358
+ return { chunk: [high, low], rest: bytes.slice(currentByteIndex) };
389
359
  }
390
360
  }
391
361
 
@@ -711,7 +681,23 @@ class String
711
681
  %x{
712
682
  var output = [];
713
683
 
714
- var buffer = utf16LEToBytes(self);
684
+ // A very optimized handler for U*.
685
+ if (format == "U*" &&
686
+ self.internal_encoding.name === "UTF-8" &&
687
+ typeof self.codePointAt === "function") {
688
+
689
+ var cp, j = 0;
690
+
691
+ output = new Array(self.length);
692
+ for (var i = 0; i < self.length; i++) {
693
+ cp = output[j++] = self.codePointAt(i);
694
+ if (cp > 0xffff) i++;
695
+ }
696
+ return output.slice(0, j);
697
+ }
698
+
699
+ var buffer = self.$bytes();
700
+
715
701
 
716
702
  // optimization
717
703
  var optimizedHandler = optimized[format];
data/opal/opal.rb CHANGED
@@ -13,6 +13,7 @@ require 'corelib/main'
13
13
  require 'corelib/dir'
14
14
  require 'corelib/file'
15
15
  require 'corelib/process'
16
+ require 'corelib/random/formatter'
16
17
  require 'corelib/random'
17
18
  require 'corelib/random/mersenne_twister'
18
19
 
data/opal/opal/full.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'corelib/marshal'
2
2
  require 'corelib/string/unpack'
3
3
  require 'corelib/array/pack'
4
+ require 'corelib/object_space'
data/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "benchmark": "^2.1.4",
6
6
  "browserify": "^17.0.0",
7
7
  "jshint": "^2.11.0-rc1",
8
- "source-map-support": "^0.5.16",
8
+ "source-map-support": "0.5.19",
9
9
  "uglify-js": "^3.7.2"
10
10
  },
11
11
  "devDependencies": {},
@@ -1,6 +1,5 @@
1
1
  # NOTE: run bin/format-filters after changing this file
2
2
  opal_filter "Array" do
3
- fails "Array#* with an integer with a subclass of Array returns an Array instance" # Expected [] (ArraySpecs::MyArray) to be an instance of Array
4
3
  fails "Array#== compares with an equivalent Array-like object using #to_ary" # Expected false to be true
5
4
  fails "Array#== returns true for [NaN] == [NaN] because Array#== first checks with #equal? and NaN.equal?(NaN) is true" # Expected [NaN] to equal [NaN]
6
5
  fails "Array#[] can accept beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
@@ -9,12 +8,6 @@ opal_filter "Array" do
9
8
  fails "Array#[] raises TypeError if to_int returns non-integer" # Expected TypeError but no exception was raised ([1, 2, 3, 4] was returned)
10
9
  fails "Array#[] raises a RangeError if passed a range with a bound that is too large" # Expected RangeError but no exception was raised (nil was returned)
11
10
  fails "Array#[] raises a type error if a range is passed with a length" # Expected TypeError but no exception was raised ([2, 3] was returned)
12
- fails "Array#[] with a subclass of Array returns a Array instance with [-n, m]" # Expected [3, 4] (ArraySpecs::MyArray) to be an instance of Array
13
- fails "Array#[] with a subclass of Array returns a Array instance with [-n..-m]" # Expected [3, 4, 5] (ArraySpecs::MyArray) to be an instance of Array
14
- fails "Array#[] with a subclass of Array returns a Array instance with [-n...-m]" # Expected [3, 4] (ArraySpecs::MyArray) to be an instance of Array
15
- fails "Array#[] with a subclass of Array returns a Array instance with [n, m]" # Expected [1, 2] (ArraySpecs::MyArray) to be an instance of Array
16
- fails "Array#[] with a subclass of Array returns a Array instance with [n...m]" # Expected [2, 3] (ArraySpecs::MyArray) to be an instance of Array
17
- fails "Array#[] with a subclass of Array returns a Array instance with [n..m]" # Expected [2, 3, 4] (ArraySpecs::MyArray) to be an instance of Array
18
11
  fails "Array#[]= with [..n] and [...n] inserts at the beginning if n < negative the array size" # Opal::SyntaxError: undefined method `type' for nil
19
12
  fails "Array#[]= with [..n] and [...n] just sets the section defined by range to nil even if the rhs is nil" # Opal::SyntaxError: undefined method `type' for nil
20
13
  fails "Array#[]= with [..n] and [...n] just sets the section defined by range to nil if n < 0 and the rhs is nil" # Opal::SyntaxError: undefined method `type' for nil
@@ -27,9 +20,6 @@ opal_filter "Array" do
27
20
  fails "Array#[]= with [m..] replaces the section defined by range" # Opal::SyntaxError: undefined method `type' for nil
28
21
  fails "Array#[]= with [m..] replaces the section if m and n < 0" # Opal::SyntaxError: undefined method `type' for nil
29
22
  fails "Array#deconstruct returns self" # NoMethodError: undefined method `deconstruct' for [1]
30
- fails "Array#difference accepts multiple arguments" # NoMethodError: undefined method `difference' for [1, 2, 3, 1]
31
- fails "Array#difference does not return subclass instances for Array subclasses" # NoMethodError: undefined method `difference' for [1, 2, 3]
32
- fails "Array#difference returns a copy when called without any parameter" # NoMethodError: undefined method `difference' for [1, 2, 3, 2]
33
23
  fails "Array#drop raises a TypeError when the passed argument can't be coerced to Integer" # Expected TypeError but no exception was raised ([1, 2] was returned)
34
24
  fails "Array#drop raises a TypeError when the passed argument isn't an integer and #to_int returns non-Integer" # Expected TypeError but no exception was raised ([1, 2] was returned)
35
25
  fails "Array#drop tries to convert the passed argument to an Integer using #to_int" # Expected [1, 2, 3] == [3] to be truthy but was false
@@ -40,10 +30,8 @@ opal_filter "Array" do
40
30
  fails "Array#filter returns a new array of elements for which block is true" # NoMethodError: undefined method `filter' for [1, 3, 4, 5, 6, 9]
41
31
  fails "Array#flatten does not call #to_ary on elements beyond the given level"
42
32
  fails "Array#flatten performs respond_to? and method_missing-aware checks when coercing elements to array"
43
- fails "Array#flatten returns Array instance for Array subclasses" # Expected [] (ArraySpecs::MyArray) to be an instance of Array
44
33
  fails "Array#flatten with a non-Array object in the Array calls #method_missing if defined"
45
34
  fails "Array#inspect does not call #to_str on the object returned from #to_s when it is not a String" # Exception: Cannot convert object to primitive value
46
- fails "Array#intersection accepts multiple arguments" # NoMethodError: undefined method `intersection' for [1, 2, 3, 4]
47
35
  fails "Array#join raises a NoMethodError if an element does not respond to #to_str, #to_ary, or #to_s"
48
36
  fails "Array#partition returns in the left array values for which the block evaluates to true"
49
37
  fails "Array#rassoc calls elem == obj on the second element of each contained array"
@@ -55,21 +43,11 @@ opal_filter "Array" do
55
43
  fails "Array#slice raises TypeError if to_int returns non-integer" # Expected TypeError but no exception was raised ([1, 2, 3, 4] was returned)
56
44
  fails "Array#slice raises a RangeError if passed a range with a bound that is too large" # Expected RangeError but no exception was raised (nil was returned)
57
45
  fails "Array#slice raises a type error if a range is passed with a length" # Expected TypeError but no exception was raised ([2, 3] was returned)
58
- fails "Array#slice with a subclass of Array returns a Array instance with [-n, m]" # Expected [3, 4] (ArraySpecs::MyArray) to be an instance of Array
59
- fails "Array#slice with a subclass of Array returns a Array instance with [-n..-m]" # Expected [3, 4, 5] (ArraySpecs::MyArray) to be an instance of Array
60
- fails "Array#slice with a subclass of Array returns a Array instance with [-n...-m]" # Expected [3, 4] (ArraySpecs::MyArray) to be an instance of Array
61
- fails "Array#slice with a subclass of Array returns a Array instance with [n, m]" # Expected [1, 2] (ArraySpecs::MyArray) to be an instance of Array
62
- fails "Array#slice with a subclass of Array returns a Array instance with [n...m]" # Expected [2, 3] (ArraySpecs::MyArray) to be an instance of Array
63
- fails "Array#slice with a subclass of Array returns a Array instance with [n..m]" # Expected [2, 3, 4] (ArraySpecs::MyArray) to be an instance of Array
64
46
  fails "Array#slice! works with beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
65
47
  fails "Array#slice! works with endless ranges" # Opal::SyntaxError: undefined method `type' for nil
66
48
  fails "Array#to_h with block does not coerce returned pair to Array with #to_a" # Expected TypeError (/wrong element type MockObject at 0/) but got: TypeError (wrong element type NilClass at 0 (expected array))
67
49
  fails "Array#to_h with block raises TypeError if block returns something other than Array" # Expected TypeError (/wrong element type String at 0/) but got: TypeError (wrong element type NilClass at 0 (expected array))
68
50
  fails "Array#to_s does not call #to_str on the object returned from #to_s when it is not a String" # Exception: Cannot convert object to primitive value
69
- fails "Array#union accepts multiple arguments" # NoMethodError: undefined method `union' for [1, 2, 3]
70
- fails "Array#union does not return subclass instances for Array subclasses"
71
- fails "Array#union returns unique elements when given no argument" # NoMethodError: undefined method `union' for [1, 2, 3, 2]
72
- fails "Array#uniq returns Array instance on Array subclasses" # Expected [1, 2, 3] (ArraySpecs::MyArray) to be an instance of Array
73
51
  fails "Array#uniq! properly handles recursive arrays"
74
52
  fails "Array#values_at works when given beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
75
53
  fails "Array#values_at works when given endless ranges" # Opal::SyntaxError: undefined method `type' for nil