From 6432c9df20ad18f95934c58db4962cde42baf36d Mon Sep 17 00:00:00 2001 From: Romulo Cintra Date: Wed, 13 Jul 2022 12:23:57 +0200 Subject: [PATCH] Increase the Intl.DurationFormat Coverage (#3592) Co-authored-by: Ms2ger --- .../prototype/format/branding.js | 22 +++++++++++++++ .../format/invalid-arguments-throws.js | 27 +++++++++++++++++++ .../DurationFormat/prototype/format/length.js | 6 ++--- .../prototype/format/not-a-constructor.js | 21 +++++++++++++++ .../prototype/format/throw-invoked-as-func.js | 10 +++---- .../prototype/formatToParts/branding.js | 22 +++++++++++++++ .../formatToParts/invalid-arguments-throws.js | 27 +++++++++++++++++++ .../formatToParts/not-a-constructor.js | 21 +++++++++++++++ .../formatToParts/throw-invoked-as-func.js | 9 ++++--- 9 files changed, 152 insertions(+), 13 deletions(-) create mode 100644 test/intl402/DurationFormat/prototype/format/branding.js create mode 100644 test/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js create mode 100644 test/intl402/DurationFormat/prototype/format/not-a-constructor.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/branding.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js diff --git a/test/intl402/DurationFormat/prototype/format/branding.js b/test/intl402/DurationFormat/prototype/format/branding.js new file mode 100644 index 0000000000..282d3fb14a --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/branding.js @@ -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"); diff --git a/test/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js b/test/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js new file mode 100644 index 0000000000..abb124357d --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js @@ -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"); diff --git a/test/intl402/DurationFormat/prototype/format/length.js b/test/intl402/DurationFormat/prototype/format/length.js index 14d7140573..9d9a16fc7f 100644 --- a/test/intl402/DurationFormat/prototype/format/length.js +++ b/test/intl402/DurationFormat/prototype/format/length.js @@ -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, diff --git a/test/intl402/DurationFormat/prototype/format/not-a-constructor.js b/test/intl402/DurationFormat/prototype/format/not-a-constructor.js new file mode 100644 index 0000000000..b5c848c9d6 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/not-a-constructor.js @@ -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)"); diff --git a/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js b/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js index fa075a1f41..6599e10714 100644 --- a/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js +++ b/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js @@ -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 }); +}); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/branding.js b/test/intl402/DurationFormat/prototype/formatToParts/branding.js new file mode 100644 index 0000000000..e75c448112 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/branding.js @@ -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"); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js b/test/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js new file mode 100644 index 0000000000..69c4356cf4 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js @@ -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"); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js b/test/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js new file mode 100644 index 0000000000..f6535313f6 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js @@ -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)"); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js b/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js index 66af26956c..84b07e6e7c 100644 --- a/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js +++ b/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js @@ -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 }); +});