|
| 1 | +import '../common/index.mjs'; |
| 2 | +import { Readable } from 'stream'; |
| 3 | +import assert from 'assert'; |
| 4 | + |
| 5 | +// These tests are manually ported from the draft PR for the test262 test suite |
| 6 | +// Authored by Rick Waldron in https://github.com/tc39/test262/pull/2818/files |
| 7 | + |
| 8 | +// test262 license: |
| 9 | +// The << Software identified by reference to the Ecma Standard* ("Software)">> |
| 10 | +// is protected by copyright and is being made available under the |
| 11 | +// "BSD License", included below. This Software may be subject to third party |
| 12 | +// rights (rights from parties other than Ecma International), including patent |
| 13 | +// rights, and no licenses under such third party rights are granted under this |
| 14 | +// license even if the third party concerned is a member of Ecma International. |
| 15 | +// SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT |
| 16 | +// http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION |
| 17 | +// REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA |
| 18 | +// INTERNATIONAL STANDARDS* |
| 19 | + |
| 20 | +// Copyright (C) 2012-2013 Ecma International |
| 21 | +// All rights reserved. |
| 22 | + |
| 23 | +// Redistribution and use in source and binary forms, with or without |
| 24 | +// modification, are permitted provided that the following conditions are met: |
| 25 | +// 1. Redistributions of source code must retain the above copyright notice, |
| 26 | +// this list of conditions and the following disclaimer. |
| 27 | +// 2. Redistributions in binary form must reproduce the above copyright |
| 28 | +// notice, this list of conditions and the following disclaimer in the |
| 29 | +// documentation and/or other materials provided with the distribution. |
| 30 | +// 3. Neither the name of the authors nor Ecma International may be used to |
| 31 | +// endorse or promote products derived from this software without specific |
| 32 | +// prior written permission. |
| 33 | + |
| 34 | +// THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS |
| 35 | +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 36 | +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 37 | +// NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 38 | +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 39 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 40 | +// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 41 | +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 42 | +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 43 | +// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 44 | +// |
| 45 | +// * Ecma International Standards hereafter means Ecma International Standards |
| 46 | +// as well as Ecma Technical Reports |
| 47 | + |
| 48 | + |
| 49 | +// Note all the tests that check AsyncIterator's prototype itself and things |
| 50 | +// that happen before stream conversion were not ported. |
| 51 | +{ |
| 52 | + // asIndexedPairs/is-function |
| 53 | + assert.strictEqual(typeof Readable.prototype.asIndexedPairs, 'function'); |
| 54 | + // asIndexedPairs/indexed-pairs.js |
| 55 | + const iterator = Readable.from([0, 1]); |
| 56 | + const indexedPairs = iterator.asIndexedPairs(); |
| 57 | + |
| 58 | + for await (const [i, v] of indexedPairs) { |
| 59 | + assert.strictEqual(i, v); |
| 60 | + } |
| 61 | + // asIndexedPairs/length.js |
| 62 | + assert.strictEqual(Readable.prototype.asIndexedPairs.length, 0); |
| 63 | + // asIndexedPairs/name.js |
| 64 | + assert.strictEqual(Readable.prototype.asIndexedPairs.name, 'asIndexedPairs'); |
| 65 | + const descriptor = Object.getOwnPropertyDescriptor( |
| 66 | + Readable.prototype, |
| 67 | + 'asIndexedPairs' |
| 68 | + ); |
| 69 | + assert.strictEqual(descriptor.enumerable, false); |
| 70 | + assert.strictEqual(descriptor.configurable, true); |
| 71 | + assert.strictEqual(descriptor.writable, false); |
| 72 | +} |
| 73 | +{ |
| 74 | + // drop/length |
| 75 | + assert.strictEqual(Readable.prototype.drop.length, 1); |
| 76 | + const descriptor = Object.getOwnPropertyDescriptor( |
| 77 | + Readable.prototype, |
| 78 | + 'drop' |
| 79 | + ); |
| 80 | + assert.strictEqual(descriptor.enumerable, false); |
| 81 | + assert.strictEqual(descriptor.configurable, true); |
| 82 | + assert.strictEqual(descriptor.writable, false); |
| 83 | + // drop/limit-equals-total |
| 84 | + const iterator = Readable.from([1, 2]).drop(2); |
| 85 | + const result = await iterator[Symbol.asyncIterator]().next(); |
| 86 | + assert.deepStrictEqual(result, { done: true, value: undefined }); |
| 87 | + // drop/limit-greater-than-total.js |
| 88 | + const iterator2 = Readable.from([1, 2]).drop(3); |
| 89 | + const result2 = await iterator2[Symbol.asyncIterator]().next(); |
| 90 | + assert.deepStrictEqual(result2, { done: true, value: undefined }); |
| 91 | + // drop/limit-less-than-total.js |
| 92 | + const iterator3 = Readable.from([1, 2]).drop(1); |
| 93 | + const result3 = await iterator3[Symbol.asyncIterator]().next(); |
| 94 | + assert.deepStrictEqual(result3, { done: false, value: 2 }); |
| 95 | + // drop/limit-rangeerror |
| 96 | + assert.throws(() => Readable.from([1]).drop(-1), RangeError); |
| 97 | + assert.throws(() => { |
| 98 | + Readable.from([1]).drop({ |
| 99 | + valueOf() { |
| 100 | + throw new Error('boom'); |
| 101 | + } |
| 102 | + }); |
| 103 | + }, /boom/); |
| 104 | + // drop/limit-tointeger |
| 105 | + const two = await Readable.from([1, 2]).drop({ valueOf: () => 1 }).toArray(); |
| 106 | + assert.deepStrictEqual(two, [2]); |
| 107 | + // drop/name |
| 108 | + assert.strictEqual(Readable.prototype.drop.name, 'drop'); |
| 109 | + // drop/non-constructible |
| 110 | + assert.throws(() => new Readable.prototype.drop(1), TypeError); |
| 111 | + // drop/proto |
| 112 | + const proto = Object.getPrototypeOf(Readable.prototype.drop); |
| 113 | + assert.strictEqual(proto, Function.prototype); |
| 114 | + |
| 115 | +} |
0 commit comments