intl: Tests for default options tweak proposal (#1220)

Tests for ECMA 402 PR https://github.com/tc39/ecma402/pull/170
The tests on Date/DateTimeFormat are valid without the PR.
This commit is contained in:
Daniel Ehrenberg 2017-09-12 18:12:55 +02:00 committed by Leo Balter
parent d809fd0a4f
commit 765f273ac4
6 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,20 @@
// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializecollator
description: >
Monkey-patching Object.prototype does not change the default
options for Collator as a null prototype is used.
info: >
InitializeCollator ( collator, locales, options )
1. If _options_ is *undefined*, then
1. Let _options_ be ObjectCreate(*null*).
---*/
let defaultSensitivity = new Intl.Collator("en").resolvedOptions().sensitivity;
Object.prototype.sensitivity = "base";
let collator = new Intl.Collator("en");
assert.sameValue(collator.resolvedOptions().sensitivity, defaultSensitivity);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-todatetimeoptions
description: >
Monkey-patching Object.prototype does not change the default
options for DateTimeFormat as a null prototype is used.
info: >
ToDateTimeOptions ( options, required, defaults )
1. If options is undefined, let options be null; otherwise let options be ? ToObject(options).
1. Let options be ObjectCreate(options).
---*/
if (new Intl.DateTimeFormat("en").resolvedOptions().locale === "en") {
Object.prototype.year = "2-digit";
assert.notSameValue(new Date().toLocaleString("en").length, 2);
}

View File

@ -0,0 +1,20 @@
// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-todatetimeoptions
description: >
Monkey-patching Object.prototype does not change the default
options for DateTimeFormat as a null prototype is used.
info: >
ToDateTimeOptions ( options, required, defaults )
1. If options is undefined, let options be null; otherwise let options be ? ToObject(options).
1. Let options be ObjectCreate(options).
---*/
let defaultYear = new Intl.DateTimeFormat("en").resolvedOptions().year;
Object.prototype.year = "2-digit";
let formatter = new Intl.DateTimeFormat("en");
assert.sameValue(formatter.resolvedOptions().year, defaultYear);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: >
Monkey-patching Object.prototype does not change the default
options for NumberFormat as a null prototype is used.
info: >
InitializeNumberFormat ( numberFormat, locales, options )
1. If _options_ is *undefined*, then
1. Let _options_ be ObjectCreate(*null*).
---*/
if (new Intl.NumberFormat("en").resolvedOptions().locale === "en") {
Object.prototype.maximumFractionDigits = 1;
assert.sameValue(1.23.toLocaleString("en"), "1.23");
}

View File

@ -0,0 +1,22 @@
// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: >
Monkey-patching Object.prototype does not change the default
options for NumberFormat as a null prototype is used.
info: >
InitializeNumberFormat ( numberFormat, locales, options )
1. If _options_ is *undefined*, then
1. Let _options_ be ObjectCreate(*null*).
---*/
let defaultMaximumFractionDigits =
new Intl.NumberFormat("en").resolvedOptions().maximumFractionDigits;
Object.prototype.maximumFractionDigits = 1;
let formatter = new Intl.NumberFormat("en");
assert.sameValue(formatter.resolvedOptions().maximumFractionDigits,
defaultMaximumFractionDigits);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializecollator
description: >
Monkey-patching Object.prototype does not change the default
options for Collator as a null prototype is used.
info: >
InitializeCollator ( collator, locales, options )
1. If _options_ is *undefined*, then
1. Let _options_ be ObjectCreate(*null*).
---*/
if (new Intl.Collator("en").resolvedOptions().locale === "en") {
Object.prototype.sensitivity = "base";
assert.sameValue("a".localeCompare("A"), -1);
}