-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intl: Tests for default options tweak proposal (#1220)
Tests for ECMA 402 PR tc39/ecma402#170 The tests on Date/DateTimeFormat are valid without the PR.
- Loading branch information
Showing
6 changed files
with
119 additions
and
0 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
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); |
19 changes: 19 additions & 0 deletions
19
test/intl402/Date/prototype/toLocaleString/default-options-object-prototype.js
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,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
20
test/intl402/DateTimeFormat/default-options-object-prototype.js
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,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); |
19 changes: 19 additions & 0 deletions
19
test/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js
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,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
22
test/intl402/NumberFormat/default-options-object-prototype.js
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,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); |
19 changes: 19 additions & 0 deletions
19
test/intl402/String/prototype/localeCompare/default-options-object-prototype.js
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,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); | ||
} |