| 1 |
// Copyright 2018 Igalia, S.L. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-intl.locale |
| 6 |
description: > |
| 7 |
Checks valid cases for the options argument to the Locale constructor. |
| 8 |
info: | |
| 9 |
Intl.Locale( tag [, options] ) |
| 10 |
|
| 11 |
... |
| 12 |
22. Let kf be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined). |
| 13 |
23. Set opt.[[kf]] to kf. |
| 14 |
... |
| 15 |
30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys). |
| 16 |
... |
| 17 |
|
| 18 |
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys ) |
| 19 |
|
| 20 |
... |
| 21 |
8. Let locale be the String value that is tag with all Unicode locale extension sequences removed. |
| 22 |
9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords). |
| 23 |
10. If newExtension is not the empty String, then |
| 24 |
a. Let locale be ! InsertUnicodeExtension(locale, newExtension). |
| 25 |
... |
| 26 |
|
| 27 |
CanonicalizeUnicodeExtension( attributes, keywords ) |
| 28 |
... |
| 29 |
4. Repeat for each element entry of keywords in List order, |
| 30 |
a. Let keyword be entry.[[Key]]. |
| 31 |
b. If entry.[[Value]] is not the empty String, then |
| 32 |
i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]]. |
| 33 |
c. Append keyword to fullKeywords. |
| 34 |
... |
| 35 |
features: [Intl.Locale] |
| 36 |
---*/ |
| 37 |
|
| 38 |
const validCaseFirstOptions = [ |
| 39 |
"upper", |
| 40 |
"lower", |
| 41 |
"false", |
| 42 |
false, |
| 43 |
{ toString() { return false; } }, |
| 44 |
]; |
| 45 |
for (const caseFirst of validCaseFirstOptions) { |
| 46 |
const expected = String(caseFirst); |
| 47 |
let expect = "en-u-kf-" + expected; |
| 48 |
assert.sameValue( |
| 49 |
new Intl.Locale('en', { caseFirst }).toString(), |
| 50 |
expect, |
| 51 |
`new Intl.Locale("en", { caseFirst: "${caseFirst}" }).toString() returns "${expect}"` |
| 52 |
); |
| 53 |
|
| 54 |
expect = "en-u-kf-" + expected; |
| 55 |
assert.sameValue( |
| 56 |
new Intl.Locale('en-u-kf-lower', { caseFirst }).toString(), |
| 57 |
expect, |
| 58 |
`new Intl.Locale("en-u-kf-lower", { caseFirst: "${caseFirst}" }).toString() returns "${expect}"` |
| 59 |
); |
| 60 |
|
| 61 |
assert.sameValue( |
| 62 |
new Intl.Locale('en-u-kf-lower', { caseFirst }).caseFirst, |
| 63 |
expected, |
| 64 |
`new Intl.Locale("en-u-kf-lower", { caseFirst }).caseFirst equals "${expected}"` |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
reportCompare(0, 0); |