forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Implement Intl.Collator on top of NSLocale. There isn't a perfect 1:1 mapping of Collator's options and NSLocale, so this uses a few workarounds: 1. ignorePunctuation is implemented by stripping punctuation from the string before doing the comparison, since there's no way to directly ignore punctuation. 2. Sensitivity is implemented by setting specific flags on the comparison to simulate the desired effect. 3. There is no way to directly specify "usage", so we instead supply "search" as a collation in the event that no other collation is specified. It also does not check the validity of flags passed in, since we don't have direct access to the underlying LocaleData. This is something we can implement later, by enumerating the allowed flag values in this file and checking against them. Reviewed By: dmitryrykun Differential Revision: D34675880 fbshipit-source-id: 19a8807e89116bd0b8a40a9f9ead3e61492b5448
- Loading branch information
1 parent
f4a9677
commit e533a51
Showing
6 changed files
with
254 additions
and
9 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
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,42 @@ | ||
/** | ||
* 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 | %FileCheck --match-full-lines %s | ||
// REQUIRES: intl | ||
|
||
print("Intl.Collator Test") | ||
// CHECK-LABEL: Intl.Collator Test | ||
|
||
print(['Z', 'a', 'z', 'ä'].sort(new Intl.Collator('de').compare)); | ||
// CHECK-NEXT: a,ä,z,Z | ||
print(['Z', 'a', 'z', 'ä'].sort(new Intl.Collator('sv').compare)); | ||
// CHECK-NEXT: a,z,Z,ä | ||
print(['Z', 'a', 'z', 'ä'].sort(new Intl.Collator('sv', {caseFirst: 'upper'}).compare)); | ||
// CHECK-NEXT: a,Z,z,ä | ||
print(['Z', 'a', 'z', 'ä'].sort(new Intl.Collator('de', { caseFirst: 'upper' } ).compare)); | ||
// CHECK-NEXT: a,ä,Z,z | ||
|
||
print(["of", "öf"].sort(new Intl.Collator('de-DE', { } ).compare)); | ||
// CHECK-NEXT: of,öf | ||
print(["of", "öf"].sort(new Intl.Collator('de-DE-u-co-phonebk', { } ).compare)); | ||
// CHECK-NEXT: öf,of | ||
print(["of", "öf"].sort(new Intl.Collator('de-DE', { collation: "phonebk" } ).compare)); | ||
// CHECK-NEXT: öf,of | ||
|
||
print(['test1', 'test2', 'test10'].sort(new Intl.Collator('en', { } ).compare)); | ||
// CHECK-NEXT: test1,test10,test2 | ||
print(['test1', 'test2', 'test10'].sort(new Intl.Collator('en', { numeric: true } ).compare)); | ||
// CHECK-NEXT: test1,test2,test10 | ||
|
||
try{ new Intl.Collator('en', { collation: "banananana" } ) } catch (e) { print(e) } | ||
// CHECK-NEXT: RangeError: Invalid collation: banananana | ||
|
||
var puncList = ["aa", "ab", "a,b", "a\nb", "a\na", "a a", "a b", "...", "", ".a.a"]; | ||
print(JSON.stringify([...puncList].sort(new Intl.Collator("en", ).compare))); | ||
// CHECK-NEXT: ["","...",".a.a","a\na","a\nb","a a","a b","a,b","aa","ab"] | ||
print(JSON.stringify([...puncList].sort(new Intl.Collator("en", { ignorePunctuation: true }).compare))); | ||
// CHECK-NEXT: ["...","","aa","a\na","a a",".a.a","ab","a,b","a\nb","a b"] |
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