Add Collator test for ignorePunctuation (#3913)

Test the explicit setting of ignorePunctuation in the option bag
reflect to the value in resolvedOptions() under Thai and
other locales. (Thai is a special case)

Test the behavior of the compare sync with the value of
resolvedOptions().ignorePunctuation
This commit is contained in:
Frank Yung-Fong Tang 2023-09-13 08:48:22 -07:00 committed by GitHub
parent 1bd99bf069
commit 3c9b3913b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-collator-comparestrings
description: test CompareStrings sync with resolvedOptions().ignorePunctuation.
locale: [en, th, ja]
---*/
// test on three locales, 'th' has different default.
['en', 'th', 'ja'].forEach((locale) => {
[undefined, true, false].forEach((ignorePunctuation) => {
let col = new Intl.Collator(locale, {ignorePunctuation});
// if ignorePunctuation is true, the comparison will be 0
let expected = col.resolvedOptions().ignorePunctuation ? 0 : -1;
assert.sameValue(col.compare("", " "), expected, "Compare to space");
assert.sameValue(col.compare("", "*"), expected, "Compare to star");
});
});

View File

@ -0,0 +1,15 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializecollator
description: resolved ignorePunctuation is the same as the one specified in option bag.
locale: [en, th, ja]
---*/
['en', 'th', 'ja'].forEach((locale) => {
[true, false].forEach((ignorePunctuation) => {
assert.sameValue(
(new Intl.Collator(locale, {ignorePunctuation}))
.resolvedOptions().ignorePunctuation,
ignorePunctuation);
});
});