Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DurationFormat Coverage #3592

Merged
22 changes: 22 additions & 0 deletions test/intl402/DurationFormat/prototype/format/branding.js
Original file line number Diff line number Diff line change
@@ -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), "undefined");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are gonna throw anyway even if there's no brand check, because you're not passing a valid object as the duration argument. Compare 9762bc9.

assert.throws(TypeError, () => format.call(null), "null");
assert.throws(TypeError, () => format.call(true), "true");
assert.throws(TypeError, () => format.call(""), "empty string");
assert.throws(TypeError, () => format.call(Symbol()), "symbol");
assert.throws(TypeError, () => format.call(1), "1");
assert.throws(TypeError, () => format.call({}), "plain object");
assert.throws(TypeError, () => format.call(Intl.DurationFormat), "Intl.DurationFormat");
assert.throws(TypeError, () => format.call(Intl.DurationFormat.prototype), "Intl.DurationFormat.prototype");
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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(Symbol())}, "symbol");
assert.throws(TypeError, () => { df.format("bad string")}, "bad string");
6 changes: 3 additions & 3 deletions test/intl402/DurationFormat/prototype/format/length.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand All @@ -25,7 +25,7 @@ features: [Intl.DurationFormat]
includes: [propertyHelper.js]
---*/

assert.sameValue(Intl.DateTimeFormat.prototype.format.length, 1);
assert.sameValue(Intl.DurationFormat.prototype.format.length, 1);

verifyProperty(Intl.DurationFormat.prototype.format, "length", {
value: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)");
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,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 });
});
22 changes: 22 additions & 0 deletions test/intl402/DurationFormat/prototype/formatToParts/branding.js
Original file line number Diff line number Diff line change
@@ -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), "undefined");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with format

assert.throws(TypeError, () => formatToParts.call(null), "null");
assert.throws(TypeError, () => formatToParts.call(true), "true");
assert.throws(TypeError, () => formatToParts.call(""), "empty string");
assert.throws(TypeError, () => formatToParts.call(Symbol()), "symbol");
assert.throws(TypeError, () => formatToParts.call(1), "1");
assert.throws(TypeError, () => formatToParts.call({}), "plain object");
assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat), "Intl.DurationFormat");
assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat.prototype), "Intl.DurationFormat.prototype");
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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(Symbol())}, "symbol");
assert.throws(TypeError, () => { df.formatToParts("bad string")}, "bad string");
Original file line number Diff line number Diff line change
@@ -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.formatToParts();
}, "Calling as constructor");

assert.sameValue(isConstructor(Intl.DurationFormat.prototype.formatToParts), false,
"isConstructor(Intl.DurationFormat.prototype.formatToParts)");
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});