Test options processing for zip and zipKeyed

This commit is contained in:
André Bargull 2025-07-03 08:38:34 +02:00 committed by Philip Chimento
parent 59b1a43416
commit 0216e80a13
6 changed files with 384 additions and 0 deletions

View File

@ -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});
});

View File

@ -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});
}

View File

@ -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);
});
}

View File

@ -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});
});

View File

@ -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});
}

View File

@ -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);
});
}