diff options
Diffstat (limited to 'js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js')
-rw-r--r-- | js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js new file mode 100644 index 0000000000..7f3105086f --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js @@ -0,0 +1,40 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// 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) +features: [Intl.DurationFormat] +---*/ + +const df = new Intl.DurationFormat(); +const testOptions = [ "years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]; + +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(RangeError, () => { df.formatToParts("bad string")}, "bad string"); + +testOptions.forEach( option => { + assert.throws(RangeError, () => { df.formatToParts({ [option]: 2.5 })}, " duration properties must be integers"); +}); + +testOptions.forEach( option => { + assert.throws(RangeError, () => { df.formatToParts({ [option]: -Infinity })}, " duration properties must be integers"); +}); + +reportCompare(0, 0); |