mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 22:15:24 +02:00
Intl.RelativeTimeFormat: Add some tests for format, formatToParts, and resolvedOptions.
This commit is contained in:
parent
8e15f532e1
commit
604df708b3
40
test/intl402/RelativeTimeFormat/prototype/format/unit-plural.js
vendored
Normal file
40
test/intl402/RelativeTimeFormat/prototype/format/unit-plural.js
vendored
Normal file
@ -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}`)
|
||||||
|
}
|
36
test/intl402/RelativeTimeFormat/prototype/format/value-non-finite.js
vendored
Normal file
36
test/intl402/RelativeTimeFormat/prototype/format/value-non-finite.js
vendored
Normal file
@ -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);
|
||||||
|
}
|
20
test/intl402/RelativeTimeFormat/prototype/format/value-symbol.js
vendored
Normal file
20
test/intl402/RelativeTimeFormat/prototype/format/value-symbol.js
vendored
Normal file
@ -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"));
|
52
test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-plural.js
vendored
Normal file
52
test/intl402/RelativeTimeFormat/prototype/formatToParts/unit-plural.js
vendored
Normal file
@ -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`);
|
||||||
|
}
|
||||||
|
}
|
36
test/intl402/RelativeTimeFormat/prototype/formatToParts/value-non-finite.js
vendored
Normal file
36
test/intl402/RelativeTimeFormat/prototype/formatToParts/value-non-finite.js
vendored
Normal file
@ -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);
|
||||||
|
}
|
20
test/intl402/RelativeTimeFormat/prototype/formatToParts/value-symbol.js
vendored
Normal file
20
test/intl402/RelativeTimeFormat/prototype/formatToParts/value-symbol.js
vendored
Normal file
@ -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"));
|
17
test/intl402/RelativeTimeFormat/prototype/resolvedOptions/caching.js
vendored
Normal file
17
test/intl402/RelativeTimeFormat/prototype/resolvedOptions/caching.js
vendored
Normal file
@ -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.");
|
40
test/intl402/RelativeTimeFormat/prototype/resolvedOptions/type.js
vendored
Normal file
40
test/intl402/RelativeTimeFormat/prototype/resolvedOptions/type.js
vendored
Normal file
@ -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,
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user