mirror of https://github.com/tc39/test262.git
Merge pull request #1626 from Ms2ger/RelativeTimeFormat-options
Add some more tests for the options argument to the RelativeTimeForm…
This commit is contained in:
commit
47f9008bd3
|
@ -0,0 +1,29 @@
|
|||
// 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
|
||||
description: Checks handling of invalid value for the localeMatcher option to the RelativeTimeFormat constructor.
|
||||
info: |
|
||||
InitializeRelativeTimeFormat (relativeTimeFormat, locales, options)
|
||||
7. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit").
|
||||
features: [Intl.RelativeTimeFormat]
|
||||
---*/
|
||||
|
||||
const invalidOptions = [
|
||||
null,
|
||||
1,
|
||||
"",
|
||||
"Lookup",
|
||||
"LOOKUP",
|
||||
"lookup\0",
|
||||
"Best fit",
|
||||
"BEST FIT",
|
||||
"best\u00a0fit",
|
||||
];
|
||||
|
||||
for (const invalidOption of invalidOptions) {
|
||||
assert.throws(RangeError, function() {
|
||||
new Intl.RelativeTimeFormat([], {"localeMatcher": invalidOption});
|
||||
}, `${invalidOption} is an invalid localeMatcher option value`);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
// 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
|
||||
description: Checks handling of invalid value for the numeric option to the RelativeTimeFormat constructor.
|
||||
info: |
|
||||
InitializeRelativeTimeFormat (relativeTimeFormat, locales, options)
|
||||
16. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always").
|
||||
features: [Intl.RelativeTimeFormat]
|
||||
---*/
|
||||
|
||||
const invalidOptions = [
|
||||
null,
|
||||
1,
|
||||
"",
|
||||
"Always",
|
||||
"ALWAYS",
|
||||
"always\0",
|
||||
"Auto",
|
||||
"AUTO",
|
||||
"auto\0",
|
||||
];
|
||||
|
||||
for (const invalidOption of invalidOptions) {
|
||||
assert.throws(RangeError, function() {
|
||||
new Intl.RelativeTimeFormat([], {"numeric": invalidOption});
|
||||
}, `${invalidOption} is an invalid numeric option value`);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// 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
|
||||
description: Checks handling of valid values for the numeric option to the RelativeTimeFormat constructor.
|
||||
info: |
|
||||
InitializeRelativeTimeFormat (relativeTimeFormat, locales, options)
|
||||
16. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always").
|
||||
17. Set relativeTimeFormat.[[Numeric]] to numeric.
|
||||
features: [Intl.RelativeTimeFormat]
|
||||
---*/
|
||||
|
||||
const validOptions = [
|
||||
[undefined, "always"],
|
||||
["always", "always"],
|
||||
["auto", "auto"],
|
||||
[{ toString() { return "auto"; } }, "auto"],
|
||||
];
|
||||
|
||||
for (const [validOption, expected] of validOptions) {
|
||||
const tf = new Intl.RelativeTimeFormat([], {"numeric": validOption});
|
||||
const resolvedOptions = tf.resolvedOptions();
|
||||
assert.sameValue(resolvedOptions.numeric, expected);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// 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
|
||||
description: Checks handling of invalid value for the style option to the RelativeTimeFormat constructor.
|
||||
info: |
|
||||
InitializeRelativeTimeFormat (relativeTimeFormat, locales, options)
|
||||
14. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long").
|
||||
features: [Intl.RelativeTimeFormat]
|
||||
---*/
|
||||
|
||||
const invalidOptions = [
|
||||
null,
|
||||
1,
|
||||
"",
|
||||
"Long",
|
||||
"LONG",
|
||||
"long\0",
|
||||
"Short",
|
||||
"SHORT",
|
||||
"short\0",
|
||||
"Narrow",
|
||||
"NARROW",
|
||||
"narrow\0",
|
||||
];
|
||||
|
||||
for (const invalidOption of invalidOptions) {
|
||||
assert.throws(RangeError, function() {
|
||||
new Intl.RelativeTimeFormat([], {"style": invalidOption});
|
||||
}, `${invalidOption} is an invalid style option value`);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// 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
|
||||
description: Checks handling of valid values for the style option to the RelativeTimeFormat constructor.
|
||||
info: |
|
||||
InitializeRelativeTimeFormat (relativeTimeFormat, locales, options)
|
||||
14. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long").
|
||||
15. Set relativeTimeFormat.[[Style]] to s.
|
||||
features: [Intl.RelativeTimeFormat]
|
||||
---*/
|
||||
|
||||
const validOptions = [
|
||||
[undefined, "long"],
|
||||
["long", "long"],
|
||||
["short", "short"],
|
||||
["narrow", "narrow"],
|
||||
[{ toString() { return "narrow"; } }, "narrow"],
|
||||
];
|
||||
|
||||
for (const [validOption, expected] of validOptions) {
|
||||
const tf = new Intl.RelativeTimeFormat([], {"style": validOption});
|
||||
const resolvedOptions = tf.resolvedOptions();
|
||||
assert.sameValue(resolvedOptions.style, expected);
|
||||
}
|
Loading…
Reference in New Issue