diff options
author | Daniel Ehrenberg <littledan@chromium.org> | 2017-09-12 18:12:55 +0200 |
---|---|---|
committer | Leo Balter <leonardo.balter@gmail.com> | 2017-09-12 12:12:55 -0400 |
commit | 765f273ac41ea2927cf00ae1812795683015117a (patch) | |
tree | 856fa4fa9182b4055b73f6304b726720a076d6fd /test/intl402 | |
parent | d809fd0a4f327a6ec3486bfc3b90e2cea4937985 (diff) | |
download | qtdeclarative-testsuites-765f273ac41ea2927cf00ae1812795683015117a.tar.gz |
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.
Diffstat (limited to 'test/intl402')
6 files changed, 119 insertions, 0 deletions
diff --git a/test/intl402/Collator/default-options-object-prototype.js b/test/intl402/Collator/default-options-object-prototype.js new file mode 100644 index 000000000..4f51ef930 --- /dev/null +++ b/test/intl402/Collator/default-options-object-prototype.js @@ -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); diff --git a/test/intl402/Date/prototype/toLocaleString/default-options-object-prototype.js b/test/intl402/Date/prototype/toLocaleString/default-options-object-prototype.js new file mode 100644 index 000000000..04d4fdaee --- /dev/null +++ b/test/intl402/Date/prototype/toLocaleString/default-options-object-prototype.js @@ -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); +} diff --git a/test/intl402/DateTimeFormat/default-options-object-prototype.js b/test/intl402/DateTimeFormat/default-options-object-prototype.js new file mode 100644 index 000000000..33ff81263 --- /dev/null +++ b/test/intl402/DateTimeFormat/default-options-object-prototype.js @@ -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); diff --git a/test/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js b/test/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js new file mode 100644 index 000000000..1ef822d02 --- /dev/null +++ b/test/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js @@ -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"); +} diff --git a/test/intl402/NumberFormat/default-options-object-prototype.js b/test/intl402/NumberFormat/default-options-object-prototype.js new file mode 100644 index 000000000..bf62923f3 --- /dev/null +++ b/test/intl402/NumberFormat/default-options-object-prototype.js @@ -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); diff --git a/test/intl402/String/prototype/localeCompare/default-options-object-prototype.js b/test/intl402/String/prototype/localeCompare/default-options-object-prototype.js new file mode 100644 index 000000000..54449691a --- /dev/null +++ b/test/intl402/String/prototype/localeCompare/default-options-object-prototype.js @@ -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); +} |