Skip to content

Commit

Permalink
intl: Tests for default options tweak proposal (#1220)
Browse files Browse the repository at this point in the history
Tests for ECMA 402 PR tc39/ecma402#170
The tests on Date/DateTimeFormat are valid without the PR.
  • Loading branch information
littledan authored and leobalter committed Sep 12, 2017
1 parent d809fd0 commit 765f273
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/intl402/Collator/default-options-object-prototype.js
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
}
20 changes: 20 additions & 0 deletions test/intl402/DateTimeFormat/default-options-object-prototype.js
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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");
}
22 changes: 22 additions & 0 deletions test/intl402/NumberFormat/default-options-object-prototype.js
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 765f273

Please sign in to comment.