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.format coverage #3510

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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
description: >
Throws a TypeError if Intl.DurationFormat is called as a function.
info: |
Intl.DurationFormat ([ locales [ , options ]])
1. If NewTarget is undefined, throw a TypeError exception.
features: [Intl.DurationFormat]
---*/

assert.throws(TypeError, function() {
Intl.DurationFormat();
});

assert.throws(TypeError, function() {
Intl.DurationFormat('en');
});

assert.throws(TypeError, function() {
Intl.DurationFormat(['en']);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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
description: Checks error cases for the options argument to the DurationFormat constructor when using invalid localeMatcher.
info: |
Intl.DurationFormat ( [ locales [ , options ] ] )
(...)
5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
features: [Intl.DurationFormat]
---*/

const invalidLocaleMatcherOptions = [
null,
1,
"",
"001",
"latn--",
"Lookup",
"LOOKUP",
"lookup\0",
"Best fit",
"BEST FIT",
"best\u00a0fit",
];

for (const localeMatcher of invalidLocaleMatcherOptions) {
assert.throws(
RangeError,
function () {
new Intl.DurationFormat("en", { localeMatcher });
},
`new Intl.DurationFormat("en", { localeMatcher: "${localeMatcher}"}) throws RangeError`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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
description: >
Checks error cases for the options argument to the DurationFormat constructor when using invalid numberingSystem.
info: |
Intl.DurationFormat ( [ locales [ , options ] ] )
(...)
6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
7. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
features: [Intl.DurationFormat]
---*/

const invalidNumberingSystemOptions = [
"",
"a",
"ab",
"abcdefghi",
"abc-abcdefghi",
"!invalid!",
"-latn-",
"latn-",
"latn--",
"latn-ca",
"latn-ca-",
"latn-ca-gregory",
"latné",
"latn编号",
];

for (const numberingSystem of invalidNumberingSystemOptions) {
assert.throws(
RangeError,
function () {
new Intl.DurationFormat("en", { numberingSystem });
},
`new Intl.DurationFormat("en", {numberingSystem: "${numberingSystem}"}) throws RangeError`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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
description: >
Checks error cases for the options argument to the DurationFormat constructor when using invalid numberingSystem.
info: |
Intl.DurationFormat ( [ locales [ , options ] ] )
(...)
13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long").
features: [Intl.DurationFormat]
---*/

const invalidStyleOptions = [
null,
1,
"",
"Long",
"LONG",
"long\0",
"Short",
"SHORT",
"short\0",
"Narrow",
"NARROW",
"narrow\0",
"Digital",
"DIGITAL",
"digital\0",
];

for (const style of invalidStyleOptions) {
assert.throws(RangeError, function() {
new Intl.DurationFormat("en", {style});
}, `new Intl.DurationFormat("en", { style : "${style}"}) throws RangeError`);
}




Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 Google Inc. All rights reserved.
// Copyright 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
Expand Down
23 changes: 23 additions & 0 deletions test/intl402/DurationFormat/prototype/format/branding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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");
romulocintra marked this conversation as resolved.
Show resolved Hide resolved
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");
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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(RangeError, () => { df.format({
hours : -1,
minutes: 10
}), "Throws when mixing negative positive options" });

assert.throws(RangeError, () => { df.format({
hours : 2,
minutes: -10
}), "Throws when mixing negative positive options" });

assert.throws(RangeError, () => { df.format({
hours : -1,
minutes: 10
}), "Throws when mixing negative positive options" });
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 });
});
23 changes: 23 additions & 0 deletions test/intl402/DurationFormat/prototype/formatToParts/branding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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");
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
Expand Up @@ -17,5 +17,6 @@ const df = new Intl.DurationFormat();
let f = df['formatToParts'];

assert.sameValue(typeof f, 'function');
assert.throws(TypeError, () => { f('PT12.3456S') });

assert.throws(TypeError, () => {
f({ hours: 1, minutes: 46, seconds: 40 });
});
19 changes: 19 additions & 0 deletions test/intl402/DurationFormat/supportedLocalesOf/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.supportedLocalesOf
description: Tests that Intl.DurationFormat has a supportedLocalesOf property, and it works as expected.
features: [Intl.DurationFormat]
---*/

assert.sameValue(typeof Intl.DurationFormat.supportedLocalesOf, "function",
"supportedLocalesOf should be supported.");

const defaultLocale = new Intl.DurationFormat().resolvedOptions().locale;
const notSupported = 'zxx'; // "no linguistic content"
const requestedLocales = [defaultLocale, notSupported];

const supportedLocales = Intl.DurationFormat.supportedLocalesOf(requestedLocales);
assert.sameValue(supportedLocales.length, 1, 'The length of supported locales list is not 1.');
assert.sameValue(supportedLocales[0], defaultLocale, 'The default locale is not returned in the supported list.');
Loading