Increase the Intl.DurationFormat Coverage (#3592)

Co-authored-by: Ms2ger <Ms2ger@gmail.com>
This commit is contained in:
Romulo Cintra 2022-07-13 12:23:57 +02:00 committed by GitHub
parent 67160e94a9
commit 6432c9df20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 152 additions and 13 deletions

View File

@ -0,0 +1,22 @@
// Copyright 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.format
description: Verifies the branding check for the "format" function of the DurationFormat prototype object.
features: [Intl.DurationFormat]
---*/
const format = Intl.DurationFormat.prototype.format;
assert.sameValue(typeof format, "function");
assert.throws(TypeError, () => format.call(undefined, { years : 2 }), "undefined");
assert.throws(TypeError, () => format.call(null, { years : 2 }), "null");
assert.throws(TypeError, () => format.call(true, { years : 2 }), "true");
assert.throws(TypeError, () => format.call("", { years : 2 }), "empty string");
assert.throws(TypeError, () => format.call(Symbol(), { years : 2 }), "symbol");
assert.throws(TypeError, () => format.call(1, { years : 2 }), "1");
assert.throws(TypeError, () => format.call({}, { years : 2 }), "plain object");
assert.throws(TypeError, () => format.call(Intl.DurationFormat, { years : 2 } ), "Intl.DurationFormat");
assert.throws(TypeError, () => format.call(Intl.DurationFormat.prototype, { years : 2 }), "Intl.DurationFormat.prototype");

View File

@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.format
description: >
"format" basic tests for invalid arguments that should throw TypeError exception.
info: |
Intl.DurationFormat.prototype.format(duration)
(...)
3. Let record be ? ToDurationRecord(duration)
---*/
const df = new Intl.DurationFormat();
assert.throws(TypeError, () => { df.format(undefined) }, "undefined" );
assert.throws(TypeError, () => { df.format(null) }, "null");
assert.throws(TypeError, () => { df.format(true) }, "true");
assert.throws(TypeError, () => { df.format(-12) }, "-12");
assert.throws(TypeError, () => { df.format(-12n) }, "-12n");
assert.throws(TypeError, () => { df.format(1) }, "1");
assert.throws(TypeError, () => { df.format(2n) }, "2n");
assert.throws(TypeError, () => { df.format({}) }, "plain object");
assert.throws(TypeError, () => { df.format({ year: 1 }) }, "unsuported property");
assert.throws(TypeError, () => { df.format({ years: undefined }) }, "supported property set undefined");
assert.throws(TypeError, () => { df.format(Symbol())}, "symbol");
assert.throws(TypeError, () => { df.format("bad string")}, "bad string");

View File

@ -2,9 +2,9 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.datetimeformat.prototype.format
esid: sec-Intl.DurationFormat.prototype.format
description: >
Intl.DateTimeFormat.prototype.format.length is 1.
Intl.DurationFormat.prototype.format.length is 1.
info: |
Intl.DurationFormat.prototype.format ( duration )
@ -25,8 +25,6 @@ features: [Intl.DurationFormat]
includes: [propertyHelper.js]
---*/
assert.sameValue(Intl.DateTimeFormat.prototype.format.length, 1);
verifyProperty(Intl.DurationFormat.prototype.format, "length", {
value: 1,
writable: false,

View File

@ -0,0 +1,21 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.format
description: >
Intl.DurationFormat.prototype.format does not implement [[Construct]], is not new-able
info: |
Built-in function objects that are not identified as constructors do not implement the
[[Construct]] internal method unless otherwise specified in the description of a particular
function.
includes: [isConstructor.js]
features: [Reflect.construct, Intl.DurationFormat]
---*/
assert.throws(TypeError, () => {
new Intl.DurationFormat.prototype.format();
}, "Calling as constructor");
assert.sameValue(isConstructor(Intl.DurationFormat.prototype.format), false,
"isConstructor(Intl.DurationFormat.prototype.format)");

View File

@ -13,9 +13,9 @@ features: [Intl.DurationFormat]
const df = new Intl.DurationFormat();
// Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
let f = df['format'];
assert.sameValue(typeof f, 'function');
assert.throws(TypeError, () => { f('PT12.3456S') });
let f = df["format"];
assert.sameValue(typeof f, "function");
assert.throws(TypeError, () => {
f({ hours: 1, minutes: 46, seconds: 40 });
});

View File

@ -0,0 +1,22 @@
// Copyright 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.formatToParts
description: Verifies the branding check for the "formatToParts" function of the DurationFormat prototype object.
features: [Intl.DurationFormat]
---*/
const formatToParts = Intl.DurationFormat.prototype.formatToParts;
assert.sameValue(typeof formatToParts, "function");
assert.throws(TypeError, () => formatToParts.call(undefined, { years : 2 }), "undefined");
assert.throws(TypeError, () => formatToParts.call(null, { years : 2 }), "null");
assert.throws(TypeError, () => formatToParts.call(true, { years : 2 }), "true");
assert.throws(TypeError, () => formatToParts.call("", { years : 2 }), "empty string");
assert.throws(TypeError, () => formatToParts.call(Symbol(), { years : 2 }), "symbol");
assert.throws(TypeError, () => formatToParts.call(1, { years : 2 }), "1");
assert.throws(TypeError, () => formatToParts.call({}, { years : 2 }), "plain object");
assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat, { years : 2 } ), "Intl.DurationFormat");
assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat.prototype, { years : 2 }), "Intl.DurationFormat.prototype");

View File

@ -0,0 +1,27 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.formatToParts
description: >
"formatToParts" basic tests for invalid arguments that should throw TypeError exception.
info: |
Intl.DurationFormat.prototype.formatToParts(duration)
(...)
3. Let record be ? ToDurationRecord(duration)
---*/
const df = new Intl.DurationFormat();
assert.throws(TypeError, () => { df.formatToParts(undefined) }, "undefined" );
assert.throws(TypeError, () => { df.formatToParts(null) }, "null");
assert.throws(TypeError, () => { df.formatToParts(true) }, "true");
assert.throws(TypeError, () => { df.formatToParts(-12) }, "-12");
assert.throws(TypeError, () => { df.formatToParts(-12n) }, "-12n");
assert.throws(TypeError, () => { df.formatToParts(1) }, "1");
assert.throws(TypeError, () => { df.formatToParts(2n) }, "2n");
assert.throws(TypeError, () => { df.formatToParts({}) }, "plain object");
assert.throws(TypeError, () => { df.formatToParts({ year: 1 }) }, "unsuported property");
assert.throws(TypeError, () => { df.formatToParts({ years: undefined }) }, "supported property set undefined");
assert.throws(TypeError, () => { df.formatToParts(Symbol())}, "symbol");
assert.throws(TypeError, () => { df.formatToParts("bad string")}, "bad string");

View File

@ -0,0 +1,21 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.formatToParts
description: >
Intl.DurationFormat.prototype.formatToParts does not implement [[Construct]], is not new-able
info: |
Built-in function objects that are not identified as constructors do not implement the
[[Construct]] internal method unless otherwise specified in the description of a particular
function.
includes: [isConstructor.js]
features: [Reflect.construct, Intl.DurationFormat]
---*/
assert.throws(TypeError, () => {
new Intl.DurationFormat.prototype.formatToParts();
}, "Calling as constructor");
assert.sameValue(isConstructor(Intl.DurationFormat.prototype.formatToParts), false,
"isConstructor(Intl.DurationFormat.prototype.formatToParts)");

View File

@ -14,8 +14,9 @@ features: [Intl.DurationFormat]
const df = new Intl.DurationFormat();
// Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
let f = df['formatToParts'];
assert.sameValue(typeof f, 'function');
assert.throws(TypeError, () => { f('PT12.3456S') });
let f = df["formatToParts"];
assert.sameValue(typeof f, "function");
assert.throws(TypeError, () => {
f({ hours: 1, minutes: 46, seconds: 40 });
});