From 72db5f1ec1288ac9f73212a46914be9acc652058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 21 Dec 2017 12:08:21 -0800 Subject: [PATCH] Replace mustHaveProperty with verifyProperty --- harness/testIntl.js | 45 ------------------- .../prototype/resolvedOptions/10.3.3.js | 23 +++++++--- .../prototype/resolvedOptions/12.3.3.js | 30 ++++++++++--- .../prototype/resolvedOptions/hourCycle.js | 39 +++++++++++----- .../prototype/resolvedOptions/11.3.3.js | 25 ++++++++--- .../prototype/resolvedOptions/properties.js | 18 +++++--- 6 files changed, 98 insertions(+), 82 deletions(-) diff --git a/harness/testIntl.js b/harness/testIntl.js index 5646e9c2e7..690791d7d0 100644 --- a/harness/testIntl.js +++ b/harness/testIntl.js @@ -828,51 +828,6 @@ function testOption(Constructor, property, type, values, fallback, testOptions) } -/** - * Tests whether the named property of the given object has a valid value - * and the default attributes of the properties of an object literal. - * @param {Object} obj the object to be tested. - * @param {string} property the name of the property - * @param {Function|Array} valid either a function that tests value for validity and returns a boolean, - * an array of valid values. - * @exception if the property has an invalid value. - */ -function testProperty(obj, property, valid) { - var desc = Object.getOwnPropertyDescriptor(obj, property); - if (!desc.writable) { - $ERROR("Property " + property + " must be writable."); - } - if (!desc.enumerable) { - $ERROR("Property " + property + " must be enumerable."); - } - if (!desc.configurable) { - $ERROR("Property " + property + " must be configurable."); - } - var value = desc.value; - var isValid = (typeof valid === "function") ? valid(value) : (valid.indexOf(value) !== -1); - if (!isValid) { - $ERROR("Property value " + value + " is not allowed for property " + property + "."); - } -} - - -/** - * Tests whether the given object has the named property with a valid value - * and the default attributes of the properties of an object literal. - * @param {Object} obj the object to be tested. - * @param {string} property the name of the property - * @param {Function|Array} valid either a function that tests value for validity and returns a boolean, - * an array of valid values. - * @exception if the property is missing or has an invalid value. - */ -function mustHaveProperty(obj, property, valid) { - if (!obj.hasOwnProperty(property)) { - $ERROR("Object is missing property " + property + "."); - } - testProperty(obj, property, valid); -} - - /** * Properties of the RegExp constructor that may be affected by use of regular * expressions, and the default values of these properties. Properties are from diff --git a/test/intl402/Collator/prototype/resolvedOptions/10.3.3.js b/test/intl402/Collator/prototype/resolvedOptions/10.3.3.js index aeb9ea5f0d..75b7fb51fe 100644 --- a/test/intl402/Collator/prototype/resolvedOptions/10.3.3.js +++ b/test/intl402/Collator/prototype/resolvedOptions/10.3.3.js @@ -36,20 +36,29 @@ var collations = [ ]; // this assumes the default values where the specification provides them -mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); -mustHaveProperty(actual, "usage", ["sort"]); -mustHaveProperty(actual, "sensitivity", ["variant"]); -mustHaveProperty(actual, "ignorePunctuation", [false]); -mustHaveProperty(actual, "collation", collations); +assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale), + "Invalid locale: " + actual.locale); +assert.sameValue(actual.usage, "sort"); +assert.sameValue(actual.sensitivity, "variant"); +assert.sameValue(actual.ignorePunctuation, false); +assert.notSameValue(collations.indexOf(actual.collation), -1, + "Invalid collation: " + actual.collation); + +var dataPropertyDesc = { writable: true, enumerable: true, configurable: true }; +verifyProperty(actual, "locale", dataPropertyDesc); +verifyProperty(actual, "usage", dataPropertyDesc); +verifyProperty(actual, "sensitivity", dataPropertyDesc); +verifyProperty(actual, "ignorePunctuation", dataPropertyDesc); +verifyProperty(actual, "collation", dataPropertyDesc); // "numeric" is an optional property. if (actual.hasOwnProperty("numeric")) { assert.notSameValue([true, false].indexOf(actual.numeric), -1); - verifyProperty(actual, "numeric", {writable: true, enumerable: true, configurable: true}); + verifyProperty(actual, "numeric", dataPropertyDesc); } // "caseFirst" is an optional property. if (actual.hasOwnProperty("caseFirst")) { assert.notSameValue(["upper", "lower", "false"].indexOf(actual.caseFirst), -1); - verifyProperty(actual, "caseFirst", {writable: true, enumerable: true, configurable: true}); + verifyProperty(actual, "caseFirst", dataPropertyDesc); } diff --git a/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js b/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js index 9f574ae44a..6e5e481c3d 100644 --- a/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js +++ b/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js @@ -35,15 +35,31 @@ var calendars = [ ]; // this assumes the default values where the specification provides them -mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); -mustHaveProperty(actual, "calendar", calendars); -mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem); -mustHaveProperty(actual, "timeZone", isCanonicalizedStructurallyValidTimeZoneName); +assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale), + "Invalid locale: " + actual.locale); +assert.notSameValue(calendars.indexOf(actual.calendar), -1, + "Invalid calendar: " + actual.calendar); +assert(isValidNumberingSystem(actual.numberingSystem), + "Invalid numbering system: " + actual.numberingSystem); +assert(isCanonicalizedStructurallyValidTimeZoneName(actual.timeZone), + "Invalid time zone: " + actual.timeZone); +assert.notSameValue(["2-digit", "numeric"].indexOf(actual.year), -1, + "Invalid year: " + actual.year); +assert.notSameValue(["2-digit", "numeric", "narrow", "short", "long"].indexOf(actual.month), -1, + "Invalid month: " + actual.month); +assert.notSameValue(["2-digit", "numeric"].indexOf(actual.day), -1, + "Invalid day: " + actual.day); + +var dataPropertyDesc = { writable: true, enumerable: true, configurable: true }; +verifyProperty(actual, "locale", dataPropertyDesc); +verifyProperty(actual, "calendar", dataPropertyDesc); +verifyProperty(actual, "numberingSystem", dataPropertyDesc); +verifyProperty(actual, "timeZone", dataPropertyDesc); verifyProperty(actual, "weekday", undefined); verifyProperty(actual, "era", undefined); -mustHaveProperty(actual, "year", ["2-digit", "numeric"]); -mustHaveProperty(actual, "month", ["2-digit", "numeric", "narrow", "short", "long"]); -mustHaveProperty(actual, "day", ["2-digit", "numeric"]); +verifyProperty(actual, "year", dataPropertyDesc); +verifyProperty(actual, "month", dataPropertyDesc); +verifyProperty(actual, "day", dataPropertyDesc); verifyProperty(actual, "hour", undefined); verifyProperty(actual, "minute", undefined); verifyProperty(actual, "second", undefined); diff --git a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle.js b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle.js index c09337766c..1bd3cc9687 100644 --- a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle.js +++ b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle.js @@ -9,7 +9,7 @@ description: > info: > 12.4.5 Intl.DateTimeFormat.prototype.resolvedOptions() -includes: [testIntl.js] +includes: [testIntl.js, propertyHelper.js] ---*/ /* Values passed via unicode extension key work */ @@ -27,14 +27,19 @@ const hcValuePairs = [ const hour12Values = ['h11', 'h12']; const hour24Values = ['h23', 'h24']; +const dataPropertyDesc = { writable: true, enumerable: true, configurable: true }; + for (const hcValuePair of hcValuePairs) { for (const hcValue of hcValuePair) { const resolvedOptions = new Intl.DateTimeFormat(`de-u-hc-${hcValue}`, { hour: 'numeric' }).resolvedOptions(); - mustHaveProperty(resolvedOptions, 'hourCycle', hcValuePair); - mustHaveProperty(resolvedOptions, 'hour12', [hour12Values.includes(hcValue)]); + assert(hcValuePair.includes(resolvedOptions.hourCycle)); + assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue)); + + verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc); + verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc); } } @@ -47,8 +52,11 @@ for (const hcValuePair of hcValuePairs) { hourCycle: hcValue }).resolvedOptions(); - mustHaveProperty(resolvedOptions, 'hourCycle', hcValuePair); - mustHaveProperty(resolvedOptions, 'hour12', [hour12Values.includes(hcValue)]); + assert(hcValuePair.includes(resolvedOptions.hourCycle)); + assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue)); + + verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc); + verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc); } } @@ -59,8 +67,11 @@ let resolvedOptions = new Intl.DateTimeFormat(`en-US-u-hc-h12`, { hourCycle: 'h23' }).resolvedOptions(); -mustHaveProperty(resolvedOptions, 'hourCycle', ['h23', 'h24']); -mustHaveProperty(resolvedOptions, 'hour12', [false]); +assert(['h23', 'h24'].includes(resolvedOptions.hourCycle)); +assert.sameValue(resolvedOptions.hour12, false); + +verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc); +verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc); /* When hour12 and hourCycle are set, hour12 takes precedence */ @@ -70,8 +81,11 @@ resolvedOptions = new Intl.DateTimeFormat(`fr`, { hourCycle: 'h23' }).resolvedOptions(); -mustHaveProperty(resolvedOptions, 'hourCycle', ['h11', 'h12']); -mustHaveProperty(resolvedOptions, 'hour12', [true]); +assert(['h11', 'h12'].includes(resolvedOptions.hourCycle)); +assert.sameValue(resolvedOptions.hour12, true); + +verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc); +verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc); /* When hour12 and extension key are set, hour12 takes precedence */ @@ -80,5 +94,8 @@ resolvedOptions = new Intl.DateTimeFormat(`fr-u-hc-h24`, { hour12: true, }).resolvedOptions(); -mustHaveProperty(resolvedOptions, 'hourCycle', ['h11', 'h12']); -mustHaveProperty(resolvedOptions, 'hour12', [true]); +assert(['h11', 'h12'].includes(resolvedOptions.hourCycle)); +assert.sameValue(resolvedOptions.hour12, true); + +verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc); +verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc); diff --git a/test/intl402/NumberFormat/prototype/resolvedOptions/11.3.3.js b/test/intl402/NumberFormat/prototype/resolvedOptions/11.3.3.js index d9842584bb..c27a768839 100644 --- a/test/intl402/NumberFormat/prototype/resolvedOptions/11.3.3.js +++ b/test/intl402/NumberFormat/prototype/resolvedOptions/11.3.3.js @@ -17,14 +17,25 @@ var actual2 = new Intl.NumberFormat().resolvedOptions(); assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice."); // this assumes the default values where the specification provides them -mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); -mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem); -mustHaveProperty(actual, "style", ["decimal"]); +assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale), + "Invalid locale: " + actual.locale); +assert(isValidNumberingSystem(actual.numberingSystem), + "Invalid numbering system: " + actual.numberingSystem); +assert.sameValue(actual.style, "decimal"); +assert.sameValue(actual.minimumIntegerDigits, 1); +assert.sameValue(actual.minimumFractionDigits, 0); +assert.sameValue(actual.maximumFractionDigits, 3); +assert.sameValue(actual.useGrouping, true); + +var dataPropertyDesc = { writable: true, enumerable: true, configurable: true }; +verifyProperty(actual, "locale", dataPropertyDesc); +verifyProperty(actual, "numberingSystem", dataPropertyDesc); +verifyProperty(actual, "style", dataPropertyDesc); verifyProperty(actual, "currency", undefined); verifyProperty(actual, "currencyDisplay", undefined); -mustHaveProperty(actual, "minimumIntegerDigits", [1]); -mustHaveProperty(actual, "minimumFractionDigits", [0]); -mustHaveProperty(actual, "maximumFractionDigits", [3]); +verifyProperty(actual, "minimumIntegerDigits", dataPropertyDesc); +verifyProperty(actual, "minimumFractionDigits", dataPropertyDesc); +verifyProperty(actual, "maximumFractionDigits", dataPropertyDesc); verifyProperty(actual, "minimumSignificantDigits", undefined); verifyProperty(actual, "maximumSignificantDigits", undefined); -mustHaveProperty(actual, "useGrouping", [true]); +verifyProperty(actual, "useGrouping", dataPropertyDesc); diff --git a/test/intl402/PluralRules/prototype/resolvedOptions/properties.js b/test/intl402/PluralRules/prototype/resolvedOptions/properties.js index 52acc8a95b..9839805260 100644 --- a/test/intl402/PluralRules/prototype/resolvedOptions/properties.js +++ b/test/intl402/PluralRules/prototype/resolvedOptions/properties.js @@ -17,12 +17,20 @@ var actual2 = new Intl.PluralRules().resolvedOptions(); assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice."); // this assumes the default values where the specification provides them -mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); -mustHaveProperty(actual, "type", ["cardinal"]); +assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale), + "Invalid locale: " + actual.locale); +assert.sameValue(actual.type, "cardinal"); +assert.sameValue(actual.minimumIntegerDigits, 1); +assert.sameValue(actual.minimumFractionDigits, 0); +assert.sameValue(actual.maximumFractionDigits, 3); + +var dataPropertyDesc = { writable: true, enumerable: true, configurable: true }; +verifyProperty(actual, "locale", dataPropertyDesc); +verifyProperty(actual, "type", dataPropertyDesc); verifyProperty(actual, "currency", undefined); verifyProperty(actual, "currencyDisplay", undefined); -mustHaveProperty(actual, "minimumIntegerDigits", [1]); -mustHaveProperty(actual, "minimumFractionDigits", [0]); -mustHaveProperty(actual, "maximumFractionDigits", [3]); +verifyProperty(actual, "minimumIntegerDigits", dataPropertyDesc); +verifyProperty(actual, "minimumFractionDigits", dataPropertyDesc); +verifyProperty(actual, "maximumFractionDigits", dataPropertyDesc); verifyProperty(actual, "minimumSignificantDigits", undefined); verifyProperty(actual, "maximumSignificantDigits", undefined);