From 1579764e3773c76b976bba1548739bef68d1e6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 4 May 2017 21:12:42 +0200 Subject: [PATCH] Use assert-lib: intl402/DateTimeFormat --- test/intl402/DateTimeFormat/12.1.1_1.js | 8 ++------ test/intl402/DateTimeFormat/12.1.1_22.js | 4 +--- test/intl402/DateTimeFormat/12.1.1_5.js | 4 +--- test/intl402/DateTimeFormat/12.1.1_TDTO.js | 15 ++++++--------- test/intl402/DateTimeFormat/12.1.3.js | 8 ++------ test/intl402/DateTimeFormat/12.2.3_b.js | 15 +++------------ test/intl402/DateTimeFormat/12.2.3_c.js | 10 ++++------ test/intl402/DateTimeFormat/12.4_a.js | 4 +--- test/intl402/DateTimeFormat/6.4_a.js | 5 +---- test/intl402/DateTimeFormat/6.4_b.js | 14 +++----------- test/intl402/DateTimeFormat/6.4_c.js | 9 +++------ test/intl402/DateTimeFormat/prototype/12.2.1.js | 16 ++++------------ test/intl402/DateTimeFormat/prototype/12.3_a.js | 5 +---- test/intl402/DateTimeFormat/prototype/12.3_b.js | 12 ++---------- .../prototype/constructor/12.3.1.js | 5 +---- .../prototype/format/12.3.2_1_c.js | 6 +----- .../prototype/format/12.3.2_FDT_1.js | 12 ++---------- .../prototype/format/12.3.2_FDT_7_a_iv.js | 9 ++------- .../prototype/resolvedOptions/12.3.3.js | 4 +--- .../supportedLocalesOf/12.2.2_a.js | 12 +++--------- 20 files changed, 44 insertions(+), 133 deletions(-) diff --git a/test/intl402/DateTimeFormat/12.1.1_1.js b/test/intl402/DateTimeFormat/12.1.1_1.js index 7d1d00413d..88bae8a805 100644 --- a/test/intl402/DateTimeFormat/12.1.1_1.js +++ b/test/intl402/DateTimeFormat/12.1.1_1.js @@ -19,16 +19,12 @@ testWithIntlConstructors(function (Constructor) { // variant 1: use constructor in a "new" expression obj = new Constructor(); newObj = Intl.DateTimeFormat.call(obj); - if (obj === newObj) { - $ERROR("DateTimeFormat object created with \"new\" was not ignored as this-value."); - } + assert.notSameValue(obj, newObj, "DateTimeFormat object created with \"new\" was not ignored as this-value."); // variant 2: use constructor as a function obj = Constructor(); newObj = Intl.DateTimeFormat.call(obj); - if (obj === newObj) { - $ERROR("DateTimeFormat object created with constructor as function was not ignored as this-value."); - } + assert.notSameValue(obj, newObj, "DateTimeFormat object created with constructor as function was not ignored as this-value."); return true; }); diff --git a/test/intl402/DateTimeFormat/12.1.1_22.js b/test/intl402/DateTimeFormat/12.1.1_22.js index b25417f642..00fdd88f46 100644 --- a/test/intl402/DateTimeFormat/12.1.1_22.js +++ b/test/intl402/DateTimeFormat/12.1.1_22.js @@ -13,6 +13,4 @@ includes: [testIntl.js] taintProperties(["weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZone"]); var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; -if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { - $ERROR("DateTimeFormat returns invalid locale " + locale + "."); -} +assert(isCanonicalizedStructurallyValidLanguageTag(locale), "DateTimeFormat returns invalid locale " + locale + "."); diff --git a/test/intl402/DateTimeFormat/12.1.1_5.js b/test/intl402/DateTimeFormat/12.1.1_5.js index 47f381c07f..53fdb6807c 100644 --- a/test/intl402/DateTimeFormat/12.1.1_5.js +++ b/test/intl402/DateTimeFormat/12.1.1_5.js @@ -13,6 +13,4 @@ includes: [testIntl.js] taintProperties(["localeMatcher"]); var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; -if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { - $ERROR("DateTimeFormat returns invalid locale " + locale + "."); -} +assert(isCanonicalizedStructurallyValidLanguageTag(locale), "DateTimeFormat returns invalid locale " + locale + "."); diff --git a/test/intl402/DateTimeFormat/12.1.1_TDTO.js b/test/intl402/DateTimeFormat/12.1.1_TDTO.js index b8e2443111..7d9ef93d20 100644 --- a/test/intl402/DateTimeFormat/12.1.1_TDTO.js +++ b/test/intl402/DateTimeFormat/12.1.1_TDTO.js @@ -19,19 +19,17 @@ function testWithDateTimeFormat(options, expected) { var resolvedOptions = format.resolvedOptions(); getDateTimeComponents().forEach(function (component) { if (resolvedOptions.hasOwnProperty(component)) { - if (!expected.hasOwnProperty(component)) { - $ERROR("Unrequested component " + component + + assert(expected.hasOwnProperty(component), + "Unrequested component " + component + " added to expected subset " + JSON.stringify(expected) + "; locales " + locales + ", options " + (options ? JSON.stringify(options) : options) + "."); - } } else { - if (expected.hasOwnProperty(component)) { - $ERROR("Missing component " + component + + assert.sameValue(expected.hasOwnProperty(component), false, + "Missing component " + component + " from expected subset " + JSON.stringify(expected) + "; locales " + locales + ", options " + (options ? JSON.stringify(options) : options) + "."); - } } }); }); @@ -50,13 +48,12 @@ function testWithToLocale(f, options, expected) { var referenceFormat = new Intl.DateTimeFormat(locales, expected); expectedStrings.push(referenceFormat.format(date)); }); - if (expectedStrings.indexOf(formatted) === -1) { - $ERROR("Function " + f + " did not return expected string for locales " + + assert.notSameValue(expectedStrings.indexOf(formatted), -1, + "Function " + f + " did not return expected string for locales " + locales + ", options " + (options? JSON.stringify(options) : options) + "; expected " + (expectedStrings.length === 1 ? expectedStrings[0] : "one of " + expectedStrings) + ", got " + formatted + "."); - } }); }); } diff --git a/test/intl402/DateTimeFormat/12.1.3.js b/test/intl402/DateTimeFormat/12.1.3.js index 34e24f297e..bc0da7c82e 100644 --- a/test/intl402/DateTimeFormat/12.1.3.js +++ b/test/intl402/DateTimeFormat/12.1.3.js @@ -12,10 +12,6 @@ author: Norbert Lindenberg var obj = new Intl.DateTimeFormat(); var actualPrototype = Object.getPrototypeOf(obj); -if (actualPrototype !== Intl.DateTimeFormat.prototype) { - $ERROR("Prototype of object constructed by Intl.DateTimeFormat isn't Intl.DateTimeFormat.prototype; got " + actualPrototype); -} +assert.sameValue(actualPrototype, Intl.DateTimeFormat.prototype, "Prototype of object constructed by Intl.DateTimeFormat isn't Intl.DateTimeFormat.prototype."); -if (!Object.isExtensible(obj)) { - $ERROR("Object constructed by Intl.DateTimeFormat must be extensible."); -} +assert(Object.isExtensible(obj), "Object constructed by Intl.DateTimeFormat must be extensible."); diff --git a/test/intl402/DateTimeFormat/12.2.3_b.js b/test/intl402/DateTimeFormat/12.2.3_b.js index d50fca56ce..19c6261cde 100644 --- a/test/intl402/DateTimeFormat/12.2.3_b.js +++ b/test/intl402/DateTimeFormat/12.2.3_b.js @@ -30,18 +30,9 @@ locales.forEach(function (locale) { keyValues[key].forEach(function (value) { var dateTimeFormat = new Intl.DateTimeFormat([locale + "-u-" + key + "-" + value]); var options = dateTimeFormat.resolvedOptions(); - if (options.locale !== defaultLocale) { - $ERROR("Locale " + options.locale + " is affected by key " + - key + "; value " + value + "."); - } - if (JSON.stringify(options) !== defaultOptionsJSON) { - $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " + - key + "; value " + value + "."); - } - if (defaultFormatted !== dateTimeFormat.format(input)) { - $ERROR("Formatted value " + dateTimeFormat.format(input) + " is affected by key " + - key + "; value " + value + "."); - } + assert.sameValue(options.locale, defaultLocale, "Locale " + options.locale + " is affected by key " + key + "; value " + value + "."); + assert.sameValue(JSON.stringify(options), defaultOptionsJSON, "Resolved options " + JSON.stringify(options) + " are affected by key " + key + "; value " + value + "."); + assert.sameValue(dateTimeFormat.format(input), defaultFormatted, "Formatted value " + dateTimeFormat.format(input) + " is affected by key " + key + "; value " + value + "."); }); }); }); diff --git a/test/intl402/DateTimeFormat/12.2.3_c.js b/test/intl402/DateTimeFormat/12.2.3_c.js index ba7ea2f547..340b8767ce 100644 --- a/test/intl402/DateTimeFormat/12.2.3_c.js +++ b/test/intl402/DateTimeFormat/12.2.3_c.js @@ -28,11 +28,10 @@ locales.forEach(function (locale) { var actual = format.resolvedOptions(); getDateTimeComponents().forEach(function (component) { if (actual.hasOwnProperty(component)) { - if (!subset.hasOwnProperty(component)) { - $ERROR("Unrequested component " + component + + assert(subset.hasOwnProperty(component), + "Unrequested component " + component + " added to requested subset " + JSON.stringify(subset) + "; locale " + locale + "."); - } try { testValidDateTimeComponentValue(component, actual[component]); } catch (e) { @@ -41,11 +40,10 @@ locales.forEach(function (locale) { throw e; } } else { - if (subset.hasOwnProperty(component)) { - $ERROR("Missing component " + component + + assert.sameValue(subset.hasOwnProperty(component), false, + "Missing component " + component + " from requested subset " + JSON.stringify(subset) + "; locale " + locale + "."); - } } }); }); diff --git a/test/intl402/DateTimeFormat/12.4_a.js b/test/intl402/DateTimeFormat/12.4_a.js index 8dd859471a..4b2088b514 100644 --- a/test/intl402/DateTimeFormat/12.4_a.js +++ b/test/intl402/DateTimeFormat/12.4_a.js @@ -12,6 +12,4 @@ author: Norbert Lindenberg var obj = new Intl.DateTimeFormat(); var toStringValue = Object.prototype.toString.call(obj); -if (toStringValue !== "[object Object]") { - $ERROR("Intl.DateTimeFormat instance produces wrong [[Class]] - toString returns " + toStringValue + "."); -} +assert.sameValue(toStringValue, "[object Object]", "Intl.DateTimeFormat instance produces wrong [[Class]] - toString returns " + toStringValue + "."); diff --git a/test/intl402/DateTimeFormat/6.4_a.js b/test/intl402/DateTimeFormat/6.4_a.js index e85ff366a6..a10785a99c 100644 --- a/test/intl402/DateTimeFormat/6.4_a.js +++ b/test/intl402/DateTimeFormat/6.4_a.js @@ -15,8 +15,5 @@ var validTimeZoneNames = [ validTimeZoneNames.forEach(function (name) { // this must not throw an exception for a valid time zone name var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name}); - if (format.resolvedOptions().timeZone !== name.toUpperCase()) { - $ERROR("Time zone name " + name + " was not correctly accepted; turned into " + - format.resolvedOptions().timeZone + "."); - } + assert.sameValue(format.resolvedOptions().timeZone, name.toUpperCase(), "Time zone name " + name + " was not correctly accepted."); }); diff --git a/test/intl402/DateTimeFormat/6.4_b.js b/test/intl402/DateTimeFormat/6.4_b.js index 92be9acd06..cf8472437b 100644 --- a/test/intl402/DateTimeFormat/6.4_b.js +++ b/test/intl402/DateTimeFormat/6.4_b.js @@ -19,16 +19,8 @@ var invalidTimeZoneNames = [ ]; invalidTimeZoneNames.forEach(function (name) { - var error; - try { - // this must throw an exception for an invalid time zone name + // this must throw an exception for an invalid time zone name + assert.throws(RangeError, function() { var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name}); - } catch (e) { - error = e; - } - if (error === undefined) { - $ERROR("Invalid time zone name " + name + " was not rejected."); - } else if (error.name !== "RangeError") { - $ERROR("Invalid time zone name " + name + " was rejected with wrong error " + error.name + "."); - } + }, "Invalid time zone name " + name + " was not rejected."); }); diff --git a/test/intl402/DateTimeFormat/6.4_c.js b/test/intl402/DateTimeFormat/6.4_c.js index e572e5141a..2573b81a6d 100644 --- a/test/intl402/DateTimeFormat/6.4_c.js +++ b/test/intl402/DateTimeFormat/6.4_c.js @@ -28,11 +28,8 @@ Object.getOwnPropertyNames(additionalTimeZoneNames).forEach(function (name) { if (error === undefined) { var actual = format.resolvedOptions().timeZone; var expected = additionalTimeZoneNames[name]; - if (actual !== expected) { - $ERROR("Time zone name " + name + " was accepted, but incorrectly canonicalized to " + - actual + "; expected " + expected + "."); - } - } else if (error.name !== "RangeError") { - $ERROR("Time zone name " + name + " was rejected with wrong error " + error.name + "."); + assert.sameValue(actual, expected, "Time zone name " + name + " was accepted, but incorrectly canonicalized."); + } else { + assert(error instanceof RangeError, "Time zone name " + name + " was rejected with wrong error " + error.name + "."); } }); diff --git a/test/intl402/DateTimeFormat/prototype/12.2.1.js b/test/intl402/DateTimeFormat/prototype/12.2.1.js index 288e6fd5e1..192b58d21f 100644 --- a/test/intl402/DateTimeFormat/prototype/12.2.1.js +++ b/test/intl402/DateTimeFormat/prototype/12.2.1.js @@ -10,15 +10,7 @@ author: Norbert Lindenberg ---*/ var desc = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat, "prototype"); -if (desc === undefined) { - $ERROR("Intl.DateTimeFormat.prototype is not defined."); -} -if (desc.writable) { - $ERROR("Intl.DateTimeFormat.prototype must not be writable."); -} -if (desc.enumerable) { - $ERROR("Intl.DateTimeFormat.prototype must not be enumerable."); -} -if (desc.configurable) { - $ERROR("Intl.DateTimeFormat.prototype must not be configurable."); -} +assert.notSameValue(desc, undefined, "Intl.DateTimeFormat.prototype is not defined."); +assert.sameValue(desc.writable, false, "Intl.DateTimeFormat.prototype must not be writable."); +assert.sameValue(desc.enumerable, false, "Intl.DateTimeFormat.prototype must not be enumerable."); +assert.sameValue(desc.configurable, false, "Intl.DateTimeFormat.prototype must not be configurable."); diff --git a/test/intl402/DateTimeFormat/prototype/12.3_a.js b/test/intl402/DateTimeFormat/prototype/12.3_a.js index 8cc79e4030..3704829c89 100644 --- a/test/intl402/DateTimeFormat/prototype/12.3_a.js +++ b/test/intl402/DateTimeFormat/prototype/12.3_a.js @@ -11,7 +11,4 @@ author: Roozbeh Pournader // test by calling a function that would fail if "this" were not an object // initialized as an Intl.DateTimeFormat -if (typeof Intl.DateTimeFormat.prototype.format(0) !== "string") { - $ERROR("Intl.DateTimeFormat's prototype is not an object that has been " + - "initialized as an Intl.DateTimeFormat"); -} +assert.sameValue(typeof Intl.DateTimeFormat.prototype.format(0), "string", "Intl.DateTimeFormat's prototype is not an object that has been initialized as an Intl.DateTimeFormat"); diff --git a/test/intl402/DateTimeFormat/prototype/12.3_b.js b/test/intl402/DateTimeFormat/prototype/12.3_b.js index 9cb3aed6ed..beb5928274 100644 --- a/test/intl402/DateTimeFormat/prototype/12.3_b.js +++ b/test/intl402/DateTimeFormat/prototype/12.3_b.js @@ -19,16 +19,8 @@ var invalidTargets = [undefined, null, true, 0, "DateTimeFormat", [], {}]; Object.getOwnPropertyNames(functions).forEach(function (functionName) { var f = functions[functionName]; invalidTargets.forEach(function (target) { - var error; - try { + assert.throws(TypeError, function() { f.call(target); - } catch (e) { - error = e; - } - if (error === undefined) { - $ERROR("Calling " + functionName + " on " + target + " was not rejected."); - } else if (error.name !== "TypeError") { - $ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + "."); - } + }, "Calling " + functionName + " on " + target + " was not rejected."); }); }); diff --git a/test/intl402/DateTimeFormat/prototype/constructor/12.3.1.js b/test/intl402/DateTimeFormat/prototype/constructor/12.3.1.js index bc92aa2c18..4a4502389b 100644 --- a/test/intl402/DateTimeFormat/prototype/constructor/12.3.1.js +++ b/test/intl402/DateTimeFormat/prototype/constructor/12.3.1.js @@ -9,7 +9,4 @@ description: > author: Roozbeh Pournader ---*/ -if (Intl.DateTimeFormat.prototype.constructor !== Intl.DateTimeFormat) { - $ERROR("Intl.DateTimeFormat.prototype.constructor is not the same as " + - "Intl.DateTimeFormat"); -} +assert.sameValue(Intl.DateTimeFormat.prototype.constructor, Intl.DateTimeFormat, "Intl.DateTimeFormat.prototype.constructor is not the same as Intl.DateTimeFormat"); diff --git a/test/intl402/DateTimeFormat/prototype/format/12.3.2_1_c.js b/test/intl402/DateTimeFormat/prototype/format/12.3.2_1_c.js index 407a37a9dc..67938c8ded 100644 --- a/test/intl402/DateTimeFormat/prototype/format/12.3.2_1_c.js +++ b/test/intl402/DateTimeFormat/prototype/format/12.3.2_1_c.js @@ -23,11 +23,7 @@ locales.forEach(function (locales) { dates.forEach(function (date) { var referenceFormatted = formatObj.format(date); var formatted = formatFunc(date); - if (referenceFormatted !== formatted) { - $ERROR("format function produces different result than format method for locales " + - locales + "; options: " + (options ? JSON.stringify(options) : options) + - " : " + formatted + " vs. " + referenceFormatted + "."); - } + assert.sameValue(referenceFormatted, formatted, "format function produces different result than format method for locales " + locales + "; options: " + (options ? JSON.stringify(options) : options) + "."); }); }); }); diff --git a/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_1.js b/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_1.js index f395a23fcf..9a7922ff6d 100644 --- a/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_1.js +++ b/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_1.js @@ -12,15 +12,7 @@ var invalidValues = [NaN, Infinity, -Infinity]; var format = new Intl.DateTimeFormat(); invalidValues.forEach(function (value) { - var error; - try { + assert.throws(RangeError, function() { var result = format.format(value); - } catch (e) { - error = e; - } - if (error === undefined) { - $ERROR("Invalid value " + value + " was not rejected."); - } else if (error.name !== "RangeError") { - $ERROR("Invalid value " + value + " was rejected with wrong error " + error.name + "."); - } + }, "Invalid value " + value + " was not rejected."); }); diff --git a/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_7_a_iv.js b/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_7_a_iv.js index 1e731fa738..749fc55ee2 100644 --- a/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_7_a_iv.js +++ b/test/intl402/DateTimeFormat/prototype/format/12.3.2_FDT_7_a_iv.js @@ -18,17 +18,12 @@ var dates = [ var format = new Intl.DateTimeFormat(["en-US"], {year: "numeric", month: "long", timeZone: "UTC"}); // this test requires a Gregorian calendar, which we usually find in the US -if (format.resolvedOptions().calendar !== "gregory") { - $ERROR("Internal error: Didn't find Gregorian calendar"); -} +assert.sameValue(format.resolvedOptions().calendar, "gregory", "Internal error: Didn't find Gregorian calendar"); dates.forEach(function (date) { var year = new Date(date).getUTCFullYear(); var expectedYear = year <= 0 ? 1 - year : year; var expectedYearString = expectedYear.toLocaleString(["en-US"], {useGrouping: false}); var dateString = format.format(date); - if (dateString.indexOf(expectedYearString) === -1) { - $ERROR("Formatted year doesn't contain expected year – expected " + - expectedYearString + ", got " + dateString + "."); - } + assert.notSameValue(dateString.indexOf(expectedYearString), -1, "Formatted year doesn't contain expected year – expected " + expectedYearString + ", got " + dateString + "."); }); diff --git a/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js b/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js index 46a6b38c0e..caebc99049 100644 --- a/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js +++ b/test/intl402/DateTimeFormat/prototype/resolvedOptions/12.3.3.js @@ -14,9 +14,7 @@ includes: [testIntl.js] var actual = new Intl.DateTimeFormat().resolvedOptions(); var actual2 = new Intl.DateTimeFormat().resolvedOptions(); -if (actual2 === actual) { - $ERROR("resolvedOptions returned the same object twice."); -} +assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice."); // source: CLDR file common/bcp47/calendar.xml; version CLDR 21. var calendars = [ diff --git a/test/intl402/DateTimeFormat/supportedLocalesOf/12.2.2_a.js b/test/intl402/DateTimeFormat/supportedLocalesOf/12.2.2_a.js index 725709e028..d033017e3c 100644 --- a/test/intl402/DateTimeFormat/supportedLocalesOf/12.2.2_a.js +++ b/test/intl402/DateTimeFormat/supportedLocalesOf/12.2.2_a.js @@ -15,15 +15,9 @@ var requestedLocales = [defaultLocale, notSupported]; var supportedLocales; -if (!Intl.DateTimeFormat.hasOwnProperty('supportedLocalesOf')) { - $ERROR("Intl.DateTimeFormat doesn't have a supportedLocalesOf property."); -} +assert(Intl.DateTimeFormat.hasOwnProperty('supportedLocalesOf'), "Intl.DateTimeFormat doesn't have a supportedLocalesOf property."); supportedLocales = Intl.DateTimeFormat.supportedLocalesOf(requestedLocales); -if (supportedLocales.length !== 1) { - $ERROR('The length of supported locales list is not 1.'); -} +assert.sameValue(supportedLocales.length, 1, 'The length of supported locales list is not 1.'); -if (supportedLocales[0] !== defaultLocale) { - $ERROR('The default locale is not returned in the supported list.'); -} +assert.sameValue(supportedLocales[0], defaultLocale, 'The default locale is not returned in the supported list.');