From 0216e80a13bf092d4e078585a6dcce769b48ee2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 3 Jul 2025 08:38:34 +0200 Subject: [PATCH] Test options processing for zip and zipKeyed --- test/built-ins/Iterator/zip/options-mode.js | 88 +++++++++++++++++++ .../built-ins/Iterator/zip/options-padding.js | 54 ++++++++++++ test/built-ins/Iterator/zip/options.js | 50 +++++++++++ .../Iterator/zipKeyed/options-mode.js | 88 +++++++++++++++++++ .../Iterator/zipKeyed/options-padding.js | 54 ++++++++++++ test/built-ins/Iterator/zipKeyed/options.js | 50 +++++++++++ 6 files changed, 384 insertions(+) create mode 100644 test/built-ins/Iterator/zip/options-mode.js create mode 100644 test/built-ins/Iterator/zip/options-padding.js create mode 100644 test/built-ins/Iterator/zip/options.js create mode 100644 test/built-ins/Iterator/zipKeyed/options-mode.js create mode 100644 test/built-ins/Iterator/zipKeyed/options-padding.js create mode 100644 test/built-ins/Iterator/zipKeyed/options.js diff --git a/test/built-ins/Iterator/zip/options-mode.js b/test/built-ins/Iterator/zip/options-mode.js new file mode 100644 index 0000000000..b73aac997f --- /dev/null +++ b/test/built-ins/Iterator/zip/options-mode.js @@ -0,0 +1,88 @@ +// Copyright (C) 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-iterator.zip +description: > + The "mode" option must be undefined or a valid string mode. +info: | + Iterator.zip ( iterables [ , options ] ) + ... + 3. Let mode be ? Get(options, "mode"). + 4. If mode is undefined, set mode to "shortest". + 5. If mode is not one of "shortest", "longest", or "strict", throw a TypeError exception. + ... +features: [joint-iteration] +---*/ + +var validModes = [ + undefined, + "shortest", + "longest", + "strict", +]; + +var invalidModes = [ + null, + false, + "", + "short", + "long", + "loose", + Symbol(), + 123, + 123n, + {}, +]; + +// Absent "mode" option. +Iterator.zip([], {}); + +// All valid mode values are accepted. +for (var mode of validModes) { + Iterator.zip([], {mode}); +} + +// Throws a TypeError for invalid mode options. +for (var mode of invalidModes) { + assert.throws(TypeError, function() { + Iterator.zip([], {mode}); + }); +} + +// "padding" option is not retrieved when "mode" option is invalid. +for (var mode of invalidModes) { + var options = { + mode, + get padding() { + throw new Test262Error(); + } + }; + assert.throws(TypeError, function() { + Iterator.zip([], options); + }); +} + +// String wrappers are not accepted. +for (var mode of validModes) { + var options = {mode: new String(mode)}; + assert.throws(TypeError, function() { + Iterator.zip([], options); + }); +} + +// Does not call any of `toString`, `valueOf`, `Symbol.toPrimitive`. +var badMode = { + toString() { + throw new Test262Error(); + }, + valueOf() { + throw new Test262Error(); + }, + [Symbol.toPrimitive]() { + throw new Test262Error(); + }, +}; +assert.throws(TypeError, function() { + Iterator.zip([], {mode: badMode}); +}); diff --git a/test/built-ins/Iterator/zip/options-padding.js b/test/built-ins/Iterator/zip/options-padding.js new file mode 100644 index 0000000000..de6434d06c --- /dev/null +++ b/test/built-ins/Iterator/zip/options-padding.js @@ -0,0 +1,54 @@ +// Copyright (C) 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-iterator.zip +description: > + The "padding" option must be undefined or an object. +info: | + Iterator.zip ( iterables [ , options ] ) + ... + 6. Let paddingOption be undefined. + 7. If mode is "longest", then + a. Set paddingOption to ? Get(options, "padding"). + b. If paddingOption is not undefined and paddingOption is not an Object, throw a TypeError exception. + ... +features: [joint-iteration] +---*/ + +var validPadding = [ + undefined, + [], +]; + +var invalidPadding = [ + null, + false, + "", + Symbol(), + 123, + 123n, +]; + +// Absent "padding" option. +Iterator.zip([], {mode: "longest"}); + +// All valid padding values are accepted. +for (var padding of validPadding) { + Iterator.zip([], {mode: "longest", padding}); +} + +// Throws a TypeError for invalid padding options. +for (var padding of invalidPadding) { + assert.throws(TypeError, function() { + Iterator.zip([], {mode: "longest", padding}); + }); +} + +// Invalid padding options are ignored when mode is not "longest". +for (var padding of invalidPadding) { + Iterator.zip([], {padding}); + Iterator.zip([], {mode: undefined, padding}); + Iterator.zip([], {mode: "shortest", padding}); + Iterator.zip([], {mode: "strict", padding}); +} diff --git a/test/built-ins/Iterator/zip/options.js b/test/built-ins/Iterator/zip/options.js new file mode 100644 index 0000000000..d523a65e00 --- /dev/null +++ b/test/built-ins/Iterator/zip/options.js @@ -0,0 +1,50 @@ +// Copyright (C) 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-iterator.zip +description: > + The "options" argument can either be undefined or an object. +info: | + Iterator.zip ( iterables [ , options ] ) + ... + 2. Set options to ? GetOptionsObject(options). + ... + + GetOptionsObject ( options ) + 1. If options is undefined, then + a. Return OrdinaryObjectCreate(null). + 2. If options is an Object, then + a. Return options. + 3. Throw a TypeError exception. +features: [joint-iteration] +---*/ + +var validOptions = [ + undefined, + {}, +]; + +var invalidOptions = [ + null, + true, + "", + Symbol(), + 0, + 0n, +]; + +// The "options" argument can also be absent. +Iterator.zip([]); + +// All valid option values are accepted. +for (var options of validOptions) { + Iterator.zip([], options); +} + +// Throws a TypeError for invalid option values. +for (var options of invalidOptions) { + assert.throws(TypeError, function() { + Iterator.zip([], options); + }); +} diff --git a/test/built-ins/Iterator/zipKeyed/options-mode.js b/test/built-ins/Iterator/zipKeyed/options-mode.js new file mode 100644 index 0000000000..2649bab692 --- /dev/null +++ b/test/built-ins/Iterator/zipKeyed/options-mode.js @@ -0,0 +1,88 @@ +// Copyright (C) 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-iterator.zipkeyed +description: > + The "mode" option must be undefined or a valid string mode. +info: | + Iterator.zipKeyed ( iterables [ , options ] ) + ... + 3. Let mode be ? Get(options, "mode"). + 4. If mode is undefined, set mode to "shortest". + 5. If mode is not one of "shortest", "longest", or "strict", throw a TypeError exception. + ... +features: [joint-iteration] +---*/ + +var validModes = [ + undefined, + "shortest", + "longest", + "strict", +]; + +var invalidModes = [ + null, + false, + "", + "short", + "long", + "loose", + Symbol(), + 123, + 123n, + {}, +]; + +// Absent "mode" option. +Iterator.zipKeyed({}, {}); + +// All valid mode values are accepted. +for (var mode of validModes) { + Iterator.zipKeyed({}, {mode}); +} + +// Throws a TypeError for invalid mode options. +for (var mode of invalidModes) { + assert.throws(TypeError, function() { + Iterator.zipKeyed({}, {mode}); + }); +} + +// "padding" option is not retrieved when "mode" option is invalid. +for (var mode of invalidModes) { + var options = { + mode, + get padding() { + throw new Test262Error(); + } + }; + assert.throws(TypeError, function() { + Iterator.zipKeyed({}, options); + }); +} + +// String wrappers are not accepted. +for (var mode of validModes) { + var options = {mode: new String(mode)}; + assert.throws(TypeError, function() { + Iterator.zipKeyed({}, options); + }); +} + +// Does not call any of `toString`, `valueOf`, `Symbol.toPrimitive`. +var badMode = { + toString() { + throw new Test262Error(); + }, + valueOf() { + throw new Test262Error(); + }, + [Symbol.toPrimitive]() { + throw new Test262Error(); + }, +}; +assert.throws(TypeError, function() { + Iterator.zipKeyed({}, {mode: badMode}); +}); diff --git a/test/built-ins/Iterator/zipKeyed/options-padding.js b/test/built-ins/Iterator/zipKeyed/options-padding.js new file mode 100644 index 0000000000..d7f92ee423 --- /dev/null +++ b/test/built-ins/Iterator/zipKeyed/options-padding.js @@ -0,0 +1,54 @@ +// Copyright (C) 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-iterator.zipkeyed +description: > + The "padding" option must be undefined or an object. +info: | + Iterator.zipKeyed ( iterables [ , options ] ) + ... + 6. Let paddingOption be undefined. + 7. If mode is "longest", then + a. Set paddingOption to ? Get(options, "padding"). + b. If paddingOption is not undefined and paddingOption is not an Object, throw a TypeError exception. + ... +features: [joint-iteration] +---*/ + +var validPadding = [ + undefined, + [], +]; + +var invalidPadding = [ + null, + false, + "", + Symbol(), + 123, + 123n, +]; + +// Absent "padding" option. +Iterator.zipKeyed({}, {mode: "longest"}); + +// All valid padding values are accepted. +for (var padding of validPadding) { + Iterator.zipKeyed({}, {mode: "longest", padding}); +} + +// Throws a TypeError for invalid padding options. +for (var padding of invalidPadding) { + assert.throws(TypeError, function() { + Iterator.zipKeyed({}, {mode: "longest", padding}); + }); +} + +// Invalid padding options are ignored when mode is not "longest". +for (var padding of invalidPadding) { + Iterator.zipKeyed({}, {padding}); + Iterator.zipKeyed({}, {mode: undefined, padding}); + Iterator.zipKeyed({}, {mode: "shortest", padding}); + Iterator.zipKeyed({}, {mode: "strict", padding}); +} diff --git a/test/built-ins/Iterator/zipKeyed/options.js b/test/built-ins/Iterator/zipKeyed/options.js new file mode 100644 index 0000000000..ac518b4520 --- /dev/null +++ b/test/built-ins/Iterator/zipKeyed/options.js @@ -0,0 +1,50 @@ +// Copyright (C) 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-iterator.zipkeyed +description: > + The "options" argument can either be undefined or an object. +info: | + Iterator.zipKeyed ( iterables [ , options ] ) + ... + 2. Set options to ? GetOptionsObject(options). + ... + + GetOptionsObject ( options ) + 1. If options is undefined, then + a. Return OrdinaryObjectCreate(null). + 2. If options is an Object, then + a. Return options. + 3. Throw a TypeError exception. +features: [joint-iteration] +---*/ + +var validOptions = [ + undefined, + {}, +]; + +var invalidOptions = [ + null, + true, + "", + Symbol(), + 0, + 0n, +]; + +// The "options" argument can also be absent. +Iterator.zipKeyed({}); + +// All valid option values are accepted. +for (var options of validOptions) { + Iterator.zipKeyed({}, options); +} + +// Throws a TypeError for invalid option values. +for (var options of invalidOptions) { + assert.throws(TypeError, function() { + Iterator.zipKeyed({}, options); + }); +}