From 764eb4f8b9e261256548333751008fe7103dc1e4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 26 Jun 2018 16:45:34 +0200 Subject: [PATCH] Intl.RelativeTimeFormat: Add tests for invalid units in format/formatToParts. --- .../prototype/format/unit-invalid.js | 43 +++++++++++++++++++ .../prototype/formatToParts/unit-invalid.js | 43 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 test/intl402/RelativeTimeFormat/prototype/format/unit-invalid.js create mode 100644 test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js diff --git a/test/intl402/RelativeTimeFormat/prototype/format/unit-invalid.js b/test/intl402/RelativeTimeFormat/prototype/format/unit-invalid.js new file mode 100644 index 0000000000..53d3729b31 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/format/unit-invalid.js @@ -0,0 +1,43 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat.prototype.format +description: Checks the handling of invalid unit arguments to Intl.RelativeTimeFormat.prototype.format(). +info: | + SingularRelativeTimeUnit ( unit ) + + 10. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", "year", throw a RangeError exception. + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.format, "function"); + +const values = [ + undefined, + null, + true, + 1, + 0.1, + NaN, + {}, + "", + "SECOND", + "MINUTE", + "HOUR", + "DAY", + "WEEK", + "MONTH", + "QUARTER", + "YEAR", +]; + +for (const value of values) { + assert.throws(RangeError, () => rtf.format(0, value), String(value)); +} + +const symbol = Symbol(); +assert.throws(TypeError, () => rtf.format(0, symbol), "symbol"); diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js new file mode 100644 index 0000000000..fa89d07b94 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js @@ -0,0 +1,43 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat.prototype.formatToParts +description: Checks the handling of invalid unit arguments to Intl.RelativeTimeFormat.prototype.formatToParts(). +info: | + SingularRelativeTimeUnit ( unit ) + + 10. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", "year", throw a RangeError exception. + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.formatToParts, "function"); + +const values = [ + undefined, + null, + true, + 1, + 0.1, + NaN, + {}, + "", + "SECOND", + "MINUTE", + "HOUR", + "DAY", + "WEEK", + "MONTH", + "QUARTER", + "YEAR", +]; + +for (const value of values) { + assert.throws(RangeError, () => rtf.formatToParts(0, value), String(value)); +} + +const symbol = Symbol(); +assert.throws(TypeError, () => rtf.formatToParts(0, symbol), "symbol");