| 1 |
// |reftest| skip-if(!this.hasOwnProperty("Intl")) |
| 2 |
|
| 3 |
// Test number-format options are accepted by Intl.PluralRules. |
| 4 |
|
| 5 |
for (let minimumIntegerDigits of [undefined, 1, 21]) { |
| 6 |
for (let minimumFractionDigits of [undefined, 0, 20]) { |
| 7 |
for (let maximumFractionDigits of [undefined, 0, 20]) { |
| 8 |
for (let minimumSignificantDigits of [undefined, 0, 21]) { |
| 9 |
for (let maximumSignificantDigits of [undefined, 0, 21]) { |
| 10 |
for (let roundingPriority of [undefined, "morePrecision"]) { |
| 11 |
for (let roundingIncrement of [undefined, 5000]) { |
| 12 |
for (let roundingMode of [undefined, "trunc"]) { |
| 13 |
for (let trailingZeroDisplay of [undefined, "stripIfInteger"]) { |
| 14 |
let options = { |
| 15 |
minimumIntegerDigits, |
| 16 |
minimumFractionDigits, |
| 17 |
maximumFractionDigits, |
| 18 |
minimumSignificantDigits, |
| 19 |
maximumSignificantDigits, |
| 20 |
roundingPriority, |
| 21 |
roundingIncrement, |
| 22 |
roundingMode, |
| 23 |
trailingZeroDisplay, |
| 24 |
}; |
| 25 |
|
| 26 |
let pl; |
| 27 |
try { |
| 28 |
pl = new Intl.PluralRules("en", options); |
| 29 |
} catch (e) { |
| 30 |
// Ignore exception from conflicting options. |
| 31 |
continue; |
| 32 |
} |
| 33 |
|
| 34 |
// InitializePluralRules: |
| 35 |
// 8. Perform ? SetNumberFormatDigitOptions(pluralRules, options, +0𝔽, 3𝔽, "standard"). |
| 36 |
let mnfdDefault = 0; |
| 37 |
let mxfdDefault = 3; |
| 38 |
|
| 39 |
// SetNumberFormatDigitOptions: |
| 40 |
// 13. If roundingIncrement is not 1, set mxfdDefault to mnfdDefault. |
| 41 |
if (roundingIncrement > 1) { |
| 42 |
mxfdDefault = mnfdDefault; |
| 43 |
} |
| 44 |
|
| 45 |
// 17. If mnsd is not undefined or mxsd is not undefined, then |
| 46 |
// a. Let hasSd be true. |
| 47 |
// 18. Else, |
| 48 |
// a. Let hasSd be false. |
| 49 |
let hasSd = minimumSignificantDigits !== undefined || maximumSignificantDigits !== undefined; |
| 50 |
|
| 51 |
// 21. Let needSd be true. |
| 52 |
// 22. Let needFd be true. |
| 53 |
let needSd = true; |
| 54 |
let needFd = true; |
| 55 |
|
| 56 |
// 23. If roundingPriority is "auto", then |
| 57 |
// a. Set needSd to hasSd. |
| 58 |
// b. If needSd is true, or hasFd is false and notation is "compact", then |
| 59 |
// i. Set needFd to false. |
| 60 |
if ((roundingPriority ?? "auto") === "auto") { |
| 61 |
needSd = hasSd; |
| 62 |
if (needSd) { |
| 63 |
needFd = false; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
// 24. If needSd is true, then |
| 68 |
// a. If hasSd is true, then |
| 69 |
// i. Set intlObj.[[MinimumSignificantDigits]] to ? DefaultNumberOption(mnsd, 1, 21, 1). |
| 70 |
// ii. Set intlObj.[[MaximumSignificantDigits]] to ? DefaultNumberOption(mxsd, intlObj.[[MinimumSignificantDigits]], 21, 21). |
| 71 |
// b. Else, |
| 72 |
// i. Set intlObj.[[MinimumSignificantDigits]] to 1. |
| 73 |
// ii. Set intlObj.[[MaximumSignificantDigits]] to 21. |
| 74 |
let mnsd = undefined; |
| 75 |
let mxsd = undefined; |
| 76 |
if (needSd) { |
| 77 |
mnsd = minimumSignificantDigits ?? 1; |
| 78 |
mxsd = maximumSignificantDigits ?? 21; |
| 79 |
} |
| 80 |
|
| 81 |
// 25. If needFd is true, then |
| 82 |
// a. If hasFd is true, then |
| 83 |
// i. Set mnfd to ? DefaultNumberOption(mnfd, 0, 20, undefined). |
| 84 |
// ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 20, undefined). |
| 85 |
// iii. If mnfd is undefined, set mnfd to min(mnfdDefault, mxfd). |
| 86 |
// iv. Else if mxfd is undefined, set mxfd to max(mxfdDefault, mnfd). |
| 87 |
// v. Else if mnfd is greater than mxfd, throw a RangeError exception. |
| 88 |
// vi. Set intlObj.[[MinimumFractionDigits]] to mnfd. |
| 89 |
// vii. Set intlObj.[[MaximumFractionDigits]] to mxfd. |
| 90 |
// b. Else, |
| 91 |
// i. Set intlObj.[[MinimumFractionDigits]] to mnfdDefault. |
| 92 |
// ii. Set intlObj.[[MaximumFractionDigits]] to mxfdDefault. |
| 93 |
let mnfd = undefined; |
| 94 |
let mxfd = undefined; |
| 95 |
if (needFd) { |
| 96 |
mnfd = minimumFractionDigits ?? mnfdDefault; |
| 97 |
mxfd = maximumFractionDigits ?? Math.max(mxfdDefault, mnfd); |
| 98 |
} |
| 99 |
|
| 100 |
// 26. If needSd is false and needFd is false, then |
| 101 |
// a. Set intlObj.[[MinimumFractionDigits]] to 0. |
| 102 |
// b. Set intlObj.[[MaximumFractionDigits]] to 0. |
| 103 |
// c. Set intlObj.[[MinimumSignificantDigits]] to 1. |
| 104 |
// d. Set intlObj.[[MaximumSignificantDigits]] to 2. |
| 105 |
// e. Set intlObj.[[RoundingType]] to morePrecision. |
| 106 |
if (!needSd && !needFd) { |
| 107 |
mnfd = 0; |
| 108 |
mxfd = 0; |
| 109 |
mnsd = 1; |
| 110 |
mxsd = 2; |
| 111 |
} |
| 112 |
|
| 113 |
let resolved = pl.resolvedOptions(); |
| 114 |
assertEq(resolved.minimumIntegerDigits, minimumIntegerDigits ?? 1); |
| 115 |
assertEq(resolved.minimumFractionDigits, mnfd); |
| 116 |
assertEq(resolved.maximumFractionDigits, mxfd); |
| 117 |
assertEq(resolved.minimumSignificantDigits, mnsd); |
| 118 |
assertEq(resolved.maximumSignificantDigits, mxsd); |
| 119 |
assertEq(resolved.roundingPriority, roundingPriority ?? "auto"); |
| 120 |
assertEq(resolved.roundingIncrement, roundingIncrement ?? 1); |
| 121 |
assertEq(resolved.roundingMode, roundingMode ?? "halfExpand"); |
| 122 |
assertEq(resolved.trailingZeroDisplay, trailingZeroDisplay ?? "auto"); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if (typeof reportCompare === "function") |
| 134 |
reportCompare(0, 0, 'ok'); |