-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix NumberFormat.resolvedOptions on Android (#1565)
Summary: A typo currently leads to wrong results for `NumberFormat.resolvedOptions()`: `minimumSignificantDigits` and `maximumSignificantDigits` are interchanged. This PR fixes that and adds tests. Pull Request resolved: #1565 Test Plan: Added unit tests. Reviewed By: dannysu Differential Revision: D65822468 Pulled By: neildhar fbshipit-source-id: bb5ba5d6257b9c6d7257fb9494b988b175855d77
- Loading branch information
1 parent
f3271d6
commit 662354b
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %hermes %s | ||
// REQUIRES: intl | ||
|
||
function assert(pred, str) { | ||
if (!pred) { | ||
throw new Error('assertion failed' + (str === undefined ? '' : (': ' + str))); | ||
} | ||
} | ||
|
||
let resolvedOptions; | ||
|
||
resolvedOptions = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD' }).resolvedOptions(); | ||
assert(resolvedOptions.minimumSignificantDigits === undefined); | ||
assert(resolvedOptions.maximumSignificantDigits === undefined); | ||
|
||
// | ||
// Validate minimumSignificantDigits logic | ||
// | ||
try { new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', minimumSignificantDigits: -1 }) } | ||
catch (e) { assert(e.message.includes('minimumSignificantDigits value is invalid.')) } | ||
|
||
try { new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', minimumSignificantDigits: 22 }) } | ||
catch (e) { assert(e.message.includes('minimumSignificantDigits value is invalid.')) } | ||
|
||
resolvedOptions = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', minimumSignificantDigits: 1 }).resolvedOptions(); | ||
assert(resolvedOptions.minimumSignificantDigits === 1); | ||
assert(resolvedOptions.maximumSignificantDigits === 21); | ||
|
||
resolvedOptions = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', minimumSignificantDigits: 21 }).resolvedOptions(); | ||
assert(resolvedOptions.minimumSignificantDigits === 21); | ||
assert(resolvedOptions.maximumSignificantDigits === 21); | ||
|
||
// | ||
// Validate maximumSignificantDigits logic | ||
// | ||
try { new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', maximumSignificantDigits: -1 }) } | ||
catch (e) { assert(e.message.includes('maximumSignificantDigits value is invalid.')) } | ||
|
||
try { new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', maximumSignificantDigits: 22 }) } | ||
catch (e) { assert(e.message.includes('maximumSignificantDigits value is invalid.')) } | ||
|
||
resolvedOptions = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', maximumSignificantDigits: 1 }).resolvedOptions(); | ||
assert(resolvedOptions.minimumSignificantDigits === 1); | ||
assert(resolvedOptions.maximumSignificantDigits === 1); | ||
|
||
resolvedOptions = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', maximumSignificantDigits: 21 }).resolvedOptions(); | ||
assert(resolvedOptions.minimumSignificantDigits === 1); | ||
assert(resolvedOptions.maximumSignificantDigits === 21); | ||
|
||
// | ||
// Validate when both are set | ||
// | ||
try { new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', minimumSignificantDigits: 5, maximumSignificantDigits: 2 }) } | ||
catch (e) { assert(e.message.includes('maximumSignificantDigits value is invalid.')) } | ||
|
||
resolvedOptions = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', minimumSignificantDigits: 3, maximumSignificantDigits: 5 }).resolvedOptions(); | ||
assert(resolvedOptions.minimumSignificantDigits === 3); | ||
assert(resolvedOptions.maximumSignificantDigits === 5); |