mirror of https://github.com/tc39/test262.git
Use assert-lib: intl402/DateTimeFormat
This commit is contained in:
parent
94e9ad831e
commit
1579764e37
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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 + ".");
|
||||
|
|
|
@ -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 + ".");
|
||||
|
|
|
@ -19,20 +19,18 @@ 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 + ".");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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 + ".");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,12 +40,11 @@ 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 + ".");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 + ".");
|
||||
|
|
|
@ -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.");
|
||||
});
|
||||
|
|
|
@ -19,16 +19,8 @@ var invalidTimeZoneNames = [
|
|||
];
|
||||
|
||||
invalidTimeZoneNames.forEach(function (name) {
|
||||
var error;
|
||||
try {
|
||||
// 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.");
|
||||
});
|
||||
|
|
|
@ -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 + ".");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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.");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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) + ".");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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.");
|
||||
});
|
||||
|
|
|
@ -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 + ".");
|
||||
});
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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.');
|
||||
|
|
Loading…
Reference in New Issue