mirror of
https://github.com/tc39/test262.git
synced 2025-07-24 06:25:30 +02:00
Add tests for the numberingSystem option to RelativeTimeFormat. (#2459)
* Add tests for the numberingSystem option to RelativeTimeFormat. * fixup! Add tests for the numberingSystem option to RelativeTimeFormat.
This commit is contained in:
parent
87ac236324
commit
28b4fcca4b
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2018 André Bargull; 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 error cases for the options argument to the RelativeTimeFormat constructor.
|
||||||
|
info: |
|
||||||
|
InitializeRelativeTimeFormat (relativeTimeFormat, locales, options)
|
||||||
|
|
||||||
|
...
|
||||||
|
8. If numberingSystem is not undefined, then
|
||||||
|
a. If numberingSystem does not match the [(3*8alphanum) *("-" (3*8alphanum))] sequence, throw a RangeError exception.
|
||||||
|
|
||||||
|
features: [Intl.RelativeTimeFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
|
||||||
|
|
||||||
|
/*
|
||||||
|
alphanum = (ALPHA / DIGIT) ; letters and numbers
|
||||||
|
numberingSystem = (3*8alphanum) *("-" (3*8alphanum))
|
||||||
|
*/
|
||||||
|
const invalidNumberingSystemOptions = [
|
||||||
|
"",
|
||||||
|
"a",
|
||||||
|
"ab",
|
||||||
|
"abcdefghi",
|
||||||
|
"abc-abcdefghi",
|
||||||
|
"!invalid!",
|
||||||
|
"-latn-",
|
||||||
|
"latn-",
|
||||||
|
"latn--",
|
||||||
|
"latn-ca",
|
||||||
|
"latn-ca-",
|
||||||
|
"latn-ca-gregory",
|
||||||
|
];
|
||||||
|
for (const numberingSystem of invalidNumberingSystemOptions) {
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
new Intl.RelativeTimeFormat('en', {numberingSystem});
|
||||||
|
}, `new Intl.RelativeTimeFormat("en", {numberingSystem: "${numberingSystem}"}) throws RangeError`);
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2018 André Bargull; 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 valid cases for the options argument to the RelativeTimeFormat constructor.
|
||||||
|
features: [Intl.RelativeTimeFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
|
||||||
|
|
||||||
|
const validNumberingSystemOptions = [
|
||||||
|
"abc",
|
||||||
|
"abcd",
|
||||||
|
"abcde",
|
||||||
|
"abcdef",
|
||||||
|
"abcdefg",
|
||||||
|
"abcdefgh",
|
||||||
|
"12345678",
|
||||||
|
"1234abcd",
|
||||||
|
"1234abcd-abc123",
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const numberingSystem of validNumberingSystemOptions) {
|
||||||
|
const rtf = new Intl.RelativeTimeFormat("en", {numberingSystem});
|
||||||
|
assert.sameValue(rtf.resolvedOptions().numberingSystem, "latn");
|
||||||
|
}
|
@ -34,6 +34,15 @@ new Intl.RelativeTimeFormat([], {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
get numberingSystem() {
|
||||||
|
callOrder.push("numberingSystem");
|
||||||
|
return {
|
||||||
|
toString() {
|
||||||
|
callOrder.push("numberingSystem toString");
|
||||||
|
return "abc";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
get numeric() {
|
get numeric() {
|
||||||
callOrder.push("numeric");
|
callOrder.push("numeric");
|
||||||
return {
|
return {
|
||||||
@ -48,6 +57,8 @@ new Intl.RelativeTimeFormat([], {
|
|||||||
assert.compareArray(callOrder, [
|
assert.compareArray(callOrder, [
|
||||||
"localeMatcher",
|
"localeMatcher",
|
||||||
"localeMatcher toString",
|
"localeMatcher toString",
|
||||||
|
"numberingSystem",
|
||||||
|
"numberingSystem toString",
|
||||||
"style",
|
"style",
|
||||||
"style toString",
|
"style toString",
|
||||||
"numeric",
|
"numeric",
|
||||||
|
@ -9,9 +9,11 @@ info: |
|
|||||||
|
|
||||||
5. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit").
|
5. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit").
|
||||||
...
|
...
|
||||||
12. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long").
|
7. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
|
||||||
...
|
...
|
||||||
14. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always").
|
16. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long").
|
||||||
|
...
|
||||||
|
18. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always").
|
||||||
|
|
||||||
GetOption ( options, property, type, values, fallback )
|
GetOption ( options, property, type, values, fallback )
|
||||||
|
|
||||||
@ -36,6 +38,9 @@ const o1 = {
|
|||||||
get localeMatcher() {
|
get localeMatcher() {
|
||||||
throw new CustomError();
|
throw new CustomError();
|
||||||
},
|
},
|
||||||
|
get numberingSystem() {
|
||||||
|
throw "should not get the numberingSystem option before localeMatcher";
|
||||||
|
},
|
||||||
get style() {
|
get style() {
|
||||||
throw "should not get the style option before localeMatcher";
|
throw "should not get the style option before localeMatcher";
|
||||||
},
|
},
|
||||||
@ -49,11 +54,14 @@ const o2 = {
|
|||||||
get localeMatcher() {
|
get localeMatcher() {
|
||||||
o2captures.push('localeMatcher');
|
o2captures.push('localeMatcher');
|
||||||
},
|
},
|
||||||
get style() {
|
get numberingSystem() {
|
||||||
throw new CustomError();
|
throw new CustomError();
|
||||||
},
|
},
|
||||||
|
get style() {
|
||||||
|
throw "should not get the style option before numberingSystem";
|
||||||
|
},
|
||||||
get numeric() {
|
get numeric() {
|
||||||
throw "should not get the numeric option before style";
|
throw "should not get the numeric option before numberingSystem";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,8 +70,27 @@ const o3 = {
|
|||||||
get localeMatcher() {
|
get localeMatcher() {
|
||||||
o3captures.push('localeMatcher');
|
o3captures.push('localeMatcher');
|
||||||
},
|
},
|
||||||
|
get numberingSystem() {
|
||||||
|
o3captures.push('numberingSystem');
|
||||||
|
},
|
||||||
get style() {
|
get style() {
|
||||||
o3captures.push('style');
|
throw new CustomError();
|
||||||
|
},
|
||||||
|
get numeric() {
|
||||||
|
throw "should not get the numeric option before style";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const o4captures = [];
|
||||||
|
const o4 = {
|
||||||
|
get localeMatcher() {
|
||||||
|
o4captures.push('localeMatcher');
|
||||||
|
},
|
||||||
|
get numberingSystem() {
|
||||||
|
o4captures.push('numberingSystem');
|
||||||
|
},
|
||||||
|
get style() {
|
||||||
|
o4captures.push('style');
|
||||||
},
|
},
|
||||||
get numeric() {
|
get numeric() {
|
||||||
throw new CustomError();
|
throw new CustomError();
|
||||||
@ -76,10 +103,15 @@ assert.throws(CustomError, () => {
|
|||||||
|
|
||||||
assert.throws(CustomError, () => {
|
assert.throws(CustomError, () => {
|
||||||
new Intl.RelativeTimeFormat("en", o2);
|
new Intl.RelativeTimeFormat("en", o2);
|
||||||
}, `Exception from style getter should be propagated`);
|
}, `Exception from numberingSystem getter should be propagated`);
|
||||||
assert.compareArray(o2captures, ['localeMatcher']);
|
assert.compareArray(o2captures, ['localeMatcher']);
|
||||||
|
|
||||||
assert.throws(CustomError, () => {
|
assert.throws(CustomError, () => {
|
||||||
new Intl.RelativeTimeFormat("en", o3);
|
new Intl.RelativeTimeFormat("en", o3);
|
||||||
|
}, `Exception from style getter should be propagated`);
|
||||||
|
assert.compareArray(o3captures, ['localeMatcher', 'numberingSystem']);
|
||||||
|
|
||||||
|
assert.throws(CustomError, () => {
|
||||||
|
new Intl.RelativeTimeFormat("en", o4);
|
||||||
}, `Exception from numeric getter should be propagated`);
|
}, `Exception from numeric getter should be propagated`);
|
||||||
assert.compareArray(o3captures, ['localeMatcher', 'style']);
|
assert.compareArray(o4captures, ['localeMatcher', 'numberingSystem', 'style']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user