Skip to content
Snippets Groups Projects
Commit 765f273a authored by Daniel Ehrenberg's avatar Daniel Ehrenberg Committed by Leo Balter
Browse files

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.
parent d809fd0a
No related branches found
No related tags found
No related merge requests found
// 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);
// 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);
}
// 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);
// 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");
}
// 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);
// 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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment