diff --git a/test/intl402/RelativeTimeFormat/prototype/format/unit-plural.js b/test/intl402/RelativeTimeFormat/prototype/format/unit-plural.js new file mode 100644 index 0000000000000000000000000000000000000000..7c1713bdd924290d444ddb132c5cc8a61d6436a0 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/format/unit-plural.js @@ -0,0 +1,40 @@ +// 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 plural unit arguments to Intl.RelativeTimeFormat.prototype.format(). +info: | + SingularRelativeTimeUnit ( unit ) + + 2. If unit is "seconds", return "second". + 3. If unit is "minutes", return "minute". + 4. If unit is "hours", return "hour". + 5. If unit is "days", return "day". + 6. If unit is "weeks", return "week". + 7. If unit is "months", return "month". + 8. If unit is "quarters", return "quarter". + 9. If unit is "years", return "year". + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.format, "function", "format should be supported"); + +const units = [ + "second", + "minute", + "hour", + "day", + "week", + "month", + "quarter", + "year", +]; + +for (const unit of units) { + assert.sameValue(rtf.format(3, unit + "s"), rtf.format(3, unit), + `Should support unit ${unit}s as a synonym for ${unit}`) +} diff --git a/test/intl402/RelativeTimeFormat/prototype/format/value-non-finite.js b/test/intl402/RelativeTimeFormat/prototype/format/value-non-finite.js new file mode 100644 index 0000000000000000000000000000000000000000..bc9fa2415804d28dba0cfba3f8a6e53dc9b0a140 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/format/value-non-finite.js @@ -0,0 +1,36 @@ +// 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 value arguments to Intl.RelativeTimeFormat.prototype.format(). +info: | + Intl.RelativeTimeFormat.prototype.format( value, unit ) + + 3. Let value be ? ToNumber(value). + + PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ) + + 4. If isFinite(value) is false, then throw a RangeError exception. + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.format, "function", "format should be supported"); + +const values = [ + [undefined, "undefined"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [-Infinity, "-Infinity"], + ["string", '"string"'], + [{}, "empty object"], + [{ toString() { return NaN; }, valueOf: undefined }, "object with toString"], + [{ valueOf() { return NaN; }, toString: undefined }, "object with valueOf"], +]; + +for (const [value, name] of values) { + assert.throws(RangeError, () => rtf.format(value, "second"), name); +} diff --git a/test/intl402/RelativeTimeFormat/prototype/format/value-symbol.js b/test/intl402/RelativeTimeFormat/prototype/format/value-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..3c49df9438d7e83543a2ed1da0fcc2d16e8ec1f7 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/format/value-symbol.js @@ -0,0 +1,20 @@ +// 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 value arguments to Intl.RelativeTimeFormat.prototype.format(). +info: | + Intl.RelativeTimeFormat.prototype.format( value, unit ) + + 3. Let value be ? ToNumber(value). + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.format, "function", "format should be supported"); + +const symbol = Symbol(); +assert.throws(TypeError, () => rtf.format(symbol, "second")); diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-plural.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-plural.js new file mode 100644 index 0000000000000000000000000000000000000000..69d33e6039c3e2b4f10ad77f56c1b657305e2e0b --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-plural.js @@ -0,0 +1,52 @@ +// 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 plural unit arguments to Intl.RelativeTimeFormat.prototype.formatToParts(). +info: | + SingularRelativeTimeUnit ( unit ) + + 2. If unit is "seconds", return "second". + 3. If unit is "minutes", return "minute". + 4. If unit is "hours", return "hour". + 5. If unit is "days", return "day". + 6. If unit is "weeks", return "week". + 7. If unit is "months", return "month". + 8. If unit is "quarters", return "quarter". + 9. If unit is "years", return "year". + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be supported"); + +const units = [ + "second", + "minute", + "hour", + "day", + "week", + "month", + "quarter", + "year", +]; + +for (const unit of units) { + const plural = rtf.formatToParts(3, unit + "s"); + const singular = rtf.formatToParts(3, unit); + + assert.sameValue(plural.length, singular.length, + `Should support unit ${unit}s as a synonym for ${unit}: length`); + + for (let i = 0; i < plural.length; ++i) { + assert.sameValue(plural[i].type, singular[i].type, + `Should support unit ${unit}s as a synonym for ${unit}: [${i}].type`); + assert.sameValue(plural[i].value, singular[i].value, + `Should support unit ${unit}s as a synonym for ${unit}: [${i}].value`); + assert.sameValue(plural[i].unit, singular[i].unit, + `Should support unit ${unit}s as a synonym for ${unit}: [${i}].unit`); + } +} diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/value-non-finite.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/value-non-finite.js new file mode 100644 index 0000000000000000000000000000000000000000..f07421fd9f815582bfefb343e42cd6b9b9eee479 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/value-non-finite.js @@ -0,0 +1,36 @@ +// 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 value arguments to Intl.RelativeTimeFormat.prototype.formatToParts(). +info: | + Intl.RelativeTimeFormat.prototype.formatToParts( value, unit ) + + 3. Let value be ? ToNumber(value). + + PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ) + + 4. If isFinite(value) is false, then throw a RangeError exception. + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be supported"); + +const values = [ + [undefined, "undefined"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [-Infinity, "-Infinity"], + ["string", '"string"'], + [{}, "empty object"], + [{ toString() { return NaN; }, valueOf: undefined }, "object with toString"], + [{ valueOf() { return NaN; }, toString: undefined }, "object with valueOf"], +]; + +for (const [value, name] of values) { + assert.throws(RangeError, () => rtf.formatToParts(value, "second"), name); +} diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/value-symbol.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/value-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..3823d24fb06599d14287acc2f59f079691063395 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/value-symbol.js @@ -0,0 +1,20 @@ +// 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 value arguments to Intl.RelativeTimeFormat.prototype.formatToParts(). +info: | + Intl.RelativeTimeFormat.prototype.formatToParts( value, unit ) + + 3. Let value be ? ToNumber(value). + +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-US"); + +assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be supported"); + +const symbol = Symbol(); +assert.throws(TypeError, () => rtf.formatToParts(symbol, "second")); diff --git a/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/caching.js b/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/caching.js new file mode 100644 index 0000000000000000000000000000000000000000..c20d0bb3224a49f4af9813b086e915f499e15e95 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/caching.js @@ -0,0 +1,17 @@ +// 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.resolvedOptions +description: Verifies that the return value of Intl.RelativeTimeFormat.prototype.resolvedOptions() is not cached. +info: | + Intl.RelativeTimeFormat.prototype.resolvedOptions () + + 4. Let options be ! ObjectCreate(%ObjectPrototype%). +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-us"); +const options1 = rtf.resolvedOptions(); +const options2 = rtf.resolvedOptions(); +assert.notSameValue(options1, options2, "Should create a new object each time."); diff --git a/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/type.js b/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/type.js new file mode 100644 index 0000000000000000000000000000000000000000..3dd8aa920eb773ee2eae42e788bfd45ffed4771b --- /dev/null +++ b/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/type.js @@ -0,0 +1,40 @@ +// 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.resolvedOptions +description: Checks the properties of the result of Intl.RelativeTimeFormat.prototype.resolvedOptions(). +info: | + Intl.RelativeTimeFormat.prototype.resolvedOptions () + + 4. Let options be ! ObjectCreate(%ObjectPrototype%). + 5. For each row of Table 1, except the header row, do + d. Perform ! CreateDataPropertyOrThrow(options, p, v). +includes: [propertyHelper.js] +features: [Intl.RelativeTimeFormat] +---*/ + +const rtf = new Intl.RelativeTimeFormat("en-us", { "style": "short", "numeric": "auto" }); +const options = rtf.resolvedOptions(); +assert.sameValue(Object.getPrototypeOf(options), Object.prototype, "Prototype"); + +verifyProperty(options, "locale", { + value: "en-US", + writable: true, + enumerable: true, + configurable: true, +}); + +verifyProperty(options, "style", { + value: "short", + writable: true, + enumerable: true, + configurable: true, +}); + +verifyProperty(options, "numeric", { + value: "auto", + writable: true, + enumerable: true, + configurable: true, +});