diff --git a/test/intl402/Locale/constructor-options-firstDayOfWeek-invalid.js b/test/intl402/Locale/constructor-options-firstDayOfWeek-invalid.js new file mode 100644 index 0000000000..a2a754d923 --- /dev/null +++ b/test/intl402/Locale/constructor-options-firstDayOfWeek-invalid.js @@ -0,0 +1,31 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale +description: > + Checks error cases for the options argument to the Locale constructor. +info: | + Intl.Locale( tag [, options] ) + + ... + x. Let numberingSystem be ? GetOption(options, "firstDayOfWeek", "string", < *"mon"*, *"tue"*, *"wed"*, *"thu"*, *"fri"*, *"sat"*, *"sun"*, *"0"*, *"1"*, *"2"*, *"3"*, *"4"*, *"5"*, *"6"*, *"7"*> , undefined). + ... + +features: [Intl.Locale,Intl.Locale-info] +---*/ + +const invalidFirstDayOfWeekOptions = [ + "", + "m", + "mo", + "monday", + true, + false, + null, +]; +for (const firstDayOfWeek of invalidFirstDayOfWeekOptions) { + assert.throws(RangeError, function() { + new Intl.Locale('en', {firstDayOfWeek}); + }, `new Intl.Locale("en", {firstDayOfWeek: "${firstDayOfWeek}"}) throws RangeError`); +} diff --git a/test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js b/test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js new file mode 100644 index 0000000000..d9efe8bf82 --- /dev/null +++ b/test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js @@ -0,0 +1,65 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale +description: > + Checks valid cases for the options argument to the Locale constructor. +info: | + Intl.Locale( tag [, options] ) + + ... + x. Let numberingSystem be ? GetOption(options, "firstDayOfWeek", "string", < *"mon"*, *"tue"*, *"wed"*, *"thu"*, *"fri"*, *"sat"*, *"sun"*, *"0"*, *"1"*, *"2"*, *"3"*, *"4"*, *"5"*, *"6"*, *"7"*> , undefined). + x. Let firstDay be *undefined*. + x. If fw is not *undefined*, then + x. Set firstDay to !WeekdayToString(fw). + x. Set opt.[[fw]] to firstDay. + ... + x. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys). + ... + x. Let firstDay be *undefined*. + x. If r.[[fw]] is not *undefined*, then + x. Set firstDay to ! WeekdayToNumber(r.[[fw]]). + x. Set locale.[[FirstDayOfWeek]] to firstDay. + ... + +features: [Intl.Locale,Intl.Locale-info] +---*/ + +const validFirstDayOfWeekOptions = [ + ["mon", "en-u-fw-mon"], + ["tue", "en-u-fw-tue"], + ["wed", "en-u-fw-wed"], + ["thu", "en-u-fw-thu"], + ["fri", "en-u-fw-fri"], + ["sat", "en-u-fw-sat"], + ["sun", "en-u-fw-sun"], + ["1", "en-u-fw-mon"], + ["2", "en-u-fw-tue"], + ["3", "en-u-fw-wed"], + ["4", "en-u-fw-thu"], + ["5", "en-u-fw-fri"], + ["6", "en-u-fw-sat"], + ["7", "en-u-fw-sun"], + ["0", "en-u-fw-sun"], + [1, "en-u-fw-mon"], + [2, "en-u-fw-tue"], + [3, "en-u-fw-wed"], + [4, "en-u-fw-thu"], + [5, "en-u-fw-fri"], + [6, "en-u-fw-sat"], + [7, "en-u-fw-sun"], + [0, "en-u-fw-sun"], +]; +for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) { + assert.sameValue( + new Intl.Locale('en', { firstDayOfWeek }).toString(), + expected, + `new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).toString() returns "${expected}"` + ); + assert.sameValue( + new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).toString(), + expected, + `new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).toString() returns "${expected}"` + ); +} diff --git a/test/intl402/Locale/prototype/firstDayOfWeek/branding.js b/test/intl402/Locale/prototype/firstDayOfWeek/branding.js new file mode 100644 index 0000000000..cfc161854c --- /dev/null +++ b/test/intl402/Locale/prototype/firstDayOfWeek/branding.js @@ -0,0 +1,30 @@ +// Copyright 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.firstDayOfWeek +description: > + Verifies the branding check for the "firstDayOfWeek" property of the Locale prototype object. +info: | + Intl.Locale.prototype.firstDayOfWeek + + 2. If Type(loc) is not Object or loc does not have an [[InitializedLocale]] internal slot, then + a. Throw a TypeError exception. +features: [Intl.Locale,Intl.Locale-info] +---*/ + +const propdesc = Object.getOwnPropertyDescriptor(Intl.Locale.prototype, "firstDayOfWeek"); +const invalidValues = [ + undefined, + null, + true, + "", + Symbol(), + 1, + {}, + Intl.Locale.prototype, +]; + +for (const invalidValue of invalidValues) { + assert.throws(TypeError, () => propdesc.get.call(invalidValue)); +} diff --git a/test/intl402/Locale/prototype/firstDayOfWeek/name.js b/test/intl402/Locale/prototype/firstDayOfWeek/name.js new file mode 100644 index 0000000000..1b1bb3a2e5 --- /dev/null +++ b/test/intl402/Locale/prototype/firstDayOfWeek/name.js @@ -0,0 +1,22 @@ +// Copyright 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale.prototype.firstDayOfWeek +description: > + Checks the "name" property of Intl.Locale.prototype.firstDayOfWeek. +info: | + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + Every built-in function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. Functions that are specified as get or set accessor functions of built-in properties have "get " or "set " prepended to the property name string. + Unless otherwise specified, the name property of a built-in function object, if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.Locale,Intl.Locale-info] +---*/ + +const getter = Object.getOwnPropertyDescriptor(Intl.Locale.prototype, "firstDayOfWeek").get; +verifyProperty(getter, "name", { + value: "get firstDayOfWeek", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/intl402/Locale/prototype/firstDayOfWeek/prop-desc.js b/test/intl402/Locale/prototype/firstDayOfWeek/prop-desc.js new file mode 100644 index 0000000000..3c4d81bdd5 --- /dev/null +++ b/test/intl402/Locale/prototype/firstDayOfWeek/prop-desc.js @@ -0,0 +1,25 @@ +// Copyright 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale +description: > + Checks the "firstDayOfWeek" property of the Locale prototype object. +info: | + Intl.Locale.prototype.firstDayOfWeek + + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + + Every accessor property described in clauses 18 through 26 and in Annex B.2 has the attributes { [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. If only a get accessor function is described, the set accessor function is the default value, undefined. +includes: [propertyHelper.js] +features: [Intl.Locale,Intl.Locale-info] +---*/ + +const propdesc = Object.getOwnPropertyDescriptor(Intl.Locale.prototype, "firstDayOfWeek"); +assert.sameValue(propdesc.set, undefined); +assert.sameValue(typeof propdesc.get, "function"); + +verifyProperty(Intl.Locale.prototype, "firstDayOfWeek", { + enumerable: false, + configurable: true, +}); diff --git a/test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js b/test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js new file mode 100644 index 0000000000..12acd526a9 --- /dev/null +++ b/test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js @@ -0,0 +1,30 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale +description: > + Checks valid cases for the options argument to the Locale constructor. +info: | + Intl.Locale.prototype.firstDayOfWeek + 3. Return loc.[[FirstDayOfWeek]]. + +features: [Intl.Locale,Intl.Locale-info] +---*/ + +const validIds = [ + ["en-u-fw-mon", 1], + ["en-u-fw-tue", 2], + ["en-u-fw-wed", 3], + ["en-u-fw-thu", 4], + ["en-u-fw-fri", 5], + ["en-u-fw-sat", 6], + ["en-u-fw-sun", 7], +]; +for (const [id, expected] of validIds) { + assert.sameValue( + new Intl.Locale(id).firstDayOfWeek, + expected, + `new Intl.Locale(${id}).firstDayOfWeek returns "${expected}"` + ); +} diff --git a/test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js b/test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js new file mode 100644 index 0000000000..6f1643afd2 --- /dev/null +++ b/test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js @@ -0,0 +1,51 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale +description: > + Checks valid cases for the options argument to the Locale constructor. +info: | + Intl.Locale.prototype.firstDayOfWeek + 3. Return loc.[[FirstDayOfWeek]]. + +features: [Intl.Locale,Intl.Locale-info] +---*/ + +const validFirstDayOfWeekOptions = [ + ["mon", 1], + ["tue", 2], + ["wed", 3], + ["thu", 4], + ["fri", 5], + ["sat", 6], + ["sun", 7], + ["1", 1], + ["2", 2], + ["3", 3], + ["4", 4], + ["5", 5], + ["6", 6], + ["7", 7], + ["0", 7], + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 6], + [7, 7], + [0, 7], +]; +for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) { + assert.sameValue( + new Intl.Locale('en', { firstDayOfWeek }).firstDayOfWeek, + expected, + `new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"` + ); + assert.sameValue( + new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).firstDayOfWeek, + expected, + `new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"` + ); +} diff --git a/test/intl402/Locale/prototype/getWeekInfo/firstDay-by-id.js b/test/intl402/Locale/prototype/getWeekInfo/firstDay-by-id.js new file mode 100644 index 0000000000..f5252e62ab --- /dev/null +++ b/test/intl402/Locale/prototype/getWeekInfo/firstDay-by-id.js @@ -0,0 +1,31 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale.prototype.getWeekInfo +description: > + Checks that the return value of Intl.Locale.prototype.getWeekInfo is an Object + with the correct keys and properties. +info: | + get Intl.Locale.prototype.getWeekInfo + ... + 6. Perform ! CreateDataPropertyOrThrow(info, "firstDay", wi.[[FirstDay]]). +features: [Reflect,Intl.Locale,Intl.Locale-info] +---*/ + +const validFirstDayOfWeekIds = [ + ["en-u-fw-mon", 1], + ["en-u-fw-tue", 2], + ["en-u-fw-wed", 3], + ["en-u-fw-thu", 4], + ["en-u-fw-fri", 5], + ["en-u-fw-sat", 6], + ["en-u-fw-sun", 7], +]; +for (const [id, expected] of validFirstDayOfWeekIds) { + assert.sameValue( + new Intl.Locale(id).getWeekInfo().firstDay, + expected, + `new Intl.Locale(${id}).getWeekInfo().firstDay returns "${expected}"` + ); +} diff --git a/test/intl402/Locale/prototype/getWeekInfo/firstDay-by-option.js b/test/intl402/Locale/prototype/getWeekInfo/firstDay-by-option.js new file mode 100644 index 0000000000..bdf9cc280c --- /dev/null +++ b/test/intl402/Locale/prototype/getWeekInfo/firstDay-by-option.js @@ -0,0 +1,52 @@ +// Copyright 2023 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.locale.prototype.getWeekInfo +description: > + Checks that the return value of Intl.Locale.prototype.getWeekInfo is an Object + with the correct keys and properties. +info: | + get Intl.Locale.prototype.getWeekInfo + ... + 6. Perform ! CreateDataPropertyOrThrow(info, "firstDay", wi.[[FirstDay]]). +features: [Reflect,Intl.Locale,Intl.Locale-info] +---*/ + +const validFirstDayOfWeekOptions = [ + ["mon", 1], + ["tue", 2], + ["wed", 3], + ["thu", 4], + ["fri", 5], + ["sat", 6], + ["sun", 7], + ["1", 1], + ["2", 2], + ["3", 3], + ["4", 4], + ["5", 5], + ["6", 6], + ["7", 7], + ["0", 7], + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 6], + [7, 7], + [0, 7], +]; +for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) { + assert.sameValue( + new Intl.Locale('en', { firstDayOfWeek }).getWeekInfo().firstDay, + expected, + `new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).getWeekInfo().firstDay returns "${expected}"` + ); + assert.sameValue( + new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).getWeekInfo().firstDay, + expected, + `new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"` + ); +}