mirror of https://github.com/tc39/test262.git
Use assert-lib: intl402/NumberFormat
This commit is contained in:
parent
315031c07d
commit
8bed4d442d
|
@ -19,16 +19,12 @@ testWithIntlConstructors(function (Constructor) {
|
|||
// variant 1: use constructor in a "new" expression
|
||||
obj = new Constructor();
|
||||
newObj = Intl.NumberFormat.call(obj);
|
||||
if (obj === newObj) {
|
||||
$ERROR("NumberFormat object created with \"new\" was not ignored as this-value.");
|
||||
}
|
||||
assert.notSameValue(obj, newObj, "NumberFormat object created with \"new\" was not ignored as this-value.");
|
||||
|
||||
// variant 2: use constructor as a function
|
||||
obj = Constructor();
|
||||
newObj = Intl.NumberFormat.call(obj);
|
||||
if (obj === newObj) {
|
||||
$ERROR("NumberFormat object created with constructor as function was not ignored as this-value.");
|
||||
}
|
||||
assert.notSameValue(obj, newObj, "NumberFormat object created with constructor as function was not ignored as this-value.");
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -19,63 +19,37 @@ validValues.forEach(function (value) {
|
|||
format = new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value});
|
||||
actual = format.resolvedOptions().currency;
|
||||
expected = value.toString().toUpperCase();
|
||||
if (actual !== expected) {
|
||||
$ERROR("Incorrect resolved currency with currency style - expected " +
|
||||
expected + "; got " + actual + ".");
|
||||
}
|
||||
assert.sameValue(actual, expected, "Incorrect resolved currency with currency style.");
|
||||
|
||||
// without currency style, we shouldn't get any currency back
|
||||
format = new Intl.NumberFormat([defaultLocale], {currency: value});
|
||||
actual = format.resolvedOptions().currency;
|
||||
expected = undefined;
|
||||
if (actual !== expected) {
|
||||
$ERROR("Incorrect resolved currency with non-currency style - expected " +
|
||||
expected + "; got " + actual + ".");
|
||||
}
|
||||
assert.sameValue(actual, expected, "Incorrect resolved currency with non-currency style.");
|
||||
|
||||
// currencies specified through the locale must be ignored
|
||||
format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value});
|
||||
actual = format.resolvedOptions().currency;
|
||||
expected = value.toString().toUpperCase();
|
||||
if (actual !== expected) {
|
||||
$ERROR("Incorrect resolved currency with -u-cu- and currency style - expected " +
|
||||
expected + "; got " + actual + ".");
|
||||
}
|
||||
assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and currency style.");
|
||||
|
||||
format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value});
|
||||
actual = format.resolvedOptions().currency;
|
||||
expected = undefined;
|
||||
if (actual !== expected) {
|
||||
$ERROR("Incorrect resolved currency with -u-cu- and non-currency style - expected " +
|
||||
expected + "; got " + actual + ".");
|
||||
}
|
||||
assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and non-currency style.");
|
||||
});
|
||||
|
||||
invalidValues.forEach(function (value) {
|
||||
function expectError(f) {
|
||||
var error;
|
||||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
if (error === undefined) {
|
||||
$ERROR("Invalid currency value " + value + " was not rejected.");
|
||||
} else if (error.name !== "RangeError") {
|
||||
$ERROR("Invalid currency value " + value + " was rejected with wrong error " + error.name + ".");
|
||||
}
|
||||
}
|
||||
|
||||
expectError(function () {
|
||||
assert.throws(RangeError, function () {
|
||||
return new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value});
|
||||
});
|
||||
expectError(function () {
|
||||
}, "Invalid currency value " + value + " was not rejected.");
|
||||
assert.throws(RangeError, function () {
|
||||
return new Intl.NumberFormat([defaultLocale], {currency: value});
|
||||
});
|
||||
expectError(function () {
|
||||
}, "Invalid currency value " + value + " was not rejected.");
|
||||
assert.throws(RangeError, function () {
|
||||
return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value});
|
||||
});
|
||||
expectError(function () {
|
||||
}, "Invalid currency value " + value + " was not rejected.");
|
||||
assert.throws(RangeError, function () {
|
||||
return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value});
|
||||
});
|
||||
}, "Invalid currency value " + value + " was not rejected.");
|
||||
});
|
||||
|
|
|
@ -11,23 +11,10 @@ author: Norbert Lindenberg
|
|||
|
||||
var defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
|
||||
|
||||
function expectError(f) {
|
||||
var error;
|
||||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
if (error === undefined) {
|
||||
$ERROR("Invalid currency value " + value + " was not rejected.");
|
||||
} else if (error.name !== "TypeError") {
|
||||
$ERROR("Invalid currency value " + value + " was rejected with wrong error " + error.name + ".");
|
||||
}
|
||||
}
|
||||
|
||||
expectError(function () {
|
||||
assert.throws(TypeError, function () {
|
||||
return new Intl.NumberFormat([defaultLocale], {style: "currency"});
|
||||
});
|
||||
expectError(function () {
|
||||
}, "Throws TypeError when currency code is not specified.");
|
||||
|
||||
assert.throws(TypeError, function () {
|
||||
return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency"});
|
||||
});
|
||||
}, "Throws TypeError when currency code is not specified; Currenty code from Unicode locale extension sequence is ignored.");
|
||||
|
|
|
@ -183,12 +183,6 @@ Object.getOwnPropertyNames(currencyDigits).forEach(function (currency) {
|
|||
var format = Intl.NumberFormat([], {style: "currency", currency: currency});
|
||||
var min = format.resolvedOptions().minimumFractionDigits;
|
||||
var max = format.resolvedOptions().maximumFractionDigits;
|
||||
if (min !== digits) {
|
||||
$ERROR("Didn't get correct minimumFractionDigits for currency " +
|
||||
currency + "; expected " + digits + ", got " + min + ".");
|
||||
}
|
||||
if (max !== digits) {
|
||||
$ERROR("Didn't get correct maximumFractionDigits for currency " +
|
||||
currency + "; expected " + digits + ", got " + max + ".");
|
||||
}
|
||||
assert.sameValue(min, digits, "Didn't get correct minimumFractionDigits for currency " + currency + ".");
|
||||
assert.sameValue(max, digits, "Didn't get correct maximumFractionDigits for currency " + currency + ".");
|
||||
});
|
||||
|
|
|
@ -13,6 +13,4 @@ includes: [testIntl.js]
|
|||
taintProperties(["localeMatcher"]);
|
||||
|
||||
var locale = new Intl.NumberFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
|
||||
if (!isCanonicalizedStructurallyValidLanguageTag(locale)) {
|
||||
$ERROR("NumberFormat returns invalid locale " + locale + ".");
|
||||
}
|
||||
assert(isCanonicalizedStructurallyValidLanguageTag(locale), "NumberFormat returns invalid locale " + locale + ".");
|
||||
|
|
|
@ -12,10 +12,6 @@ author: Norbert Lindenberg
|
|||
var obj = new Intl.NumberFormat();
|
||||
|
||||
var actualPrototype = Object.getPrototypeOf(obj);
|
||||
if (actualPrototype !== Intl.NumberFormat.prototype) {
|
||||
$ERROR("Prototype of object constructed by Intl.NumberFormat isn't Intl.NumberFormat.prototype; got " + actualPrototype);
|
||||
}
|
||||
assert.sameValue(actualPrototype, Intl.NumberFormat.prototype, "Prototype of object constructed by Intl.NumberFormat isn't Intl.NumberFormat.prototype.");
|
||||
|
||||
if (!Object.isExtensible(obj)) {
|
||||
$ERROR("Object constructed by Intl.NumberFormat must be extensible.");
|
||||
}
|
||||
assert(Object.isExtensible(obj), "Object constructed by Intl.NumberFormat must be extensible.");
|
||||
|
|
|
@ -29,18 +29,9 @@ locales.forEach(function (locale) {
|
|||
keyValues[key].forEach(function (value) {
|
||||
var numberFormat = new Intl.NumberFormat([locale + "-u-" + key + "-" + value]);
|
||||
var options = numberFormat.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 !== numberFormat.format(input)) {
|
||||
$ERROR("Formatted value " + numberFormat.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(numberFormat.format(input), defaultFormatted, "Formatted value " + numberFormat.format(input) + " is affected by key " + key + "; value " + value + ".");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,6 +12,4 @@ author: Norbert Lindenberg
|
|||
var obj = new Intl.NumberFormat();
|
||||
|
||||
var toStringValue = Object.prototype.toString.call(obj);
|
||||
if (toStringValue !== "[object Object]") {
|
||||
$ERROR("Intl.NumberFormat instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
|
||||
}
|
||||
assert.sameValue(toStringValue, "[object Object]", "Intl.NumberFormat instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
|
||||
|
|
|
@ -18,8 +18,5 @@ var wellFormedCurrencyCodes = [
|
|||
wellFormedCurrencyCodes.forEach(function (code) {
|
||||
// this must not throw an exception for a valid currency code
|
||||
var format = new Intl.NumberFormat(["de-de"], {style: "currency", currency: code});
|
||||
if (format.resolvedOptions().currency !== code.toUpperCase()) {
|
||||
$ERROR("Currency " + code + " was not correctly accepted; turned into " +
|
||||
format.resolvedOptions().currency + ".");
|
||||
}
|
||||
assert.sameValue(format.resolvedOptions().currency, code.toUpperCase(), "Currency " + code + " was not correctly accepted.");
|
||||
});
|
||||
|
|
|
@ -20,16 +20,8 @@ var invalidCurrencyCodes = [
|
|||
];
|
||||
|
||||
invalidCurrencyCodes.forEach(function (code) {
|
||||
var error;
|
||||
try {
|
||||
// this must throw an exception for an invalid currency code
|
||||
// this must throw an exception for an invalid currency code
|
||||
assert.throws(RangeError, function() {
|
||||
var format = new Intl.NumberFormat(["de-de"], {style: "currency", currency: code});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
if (error === undefined) {
|
||||
$ERROR("Invalid currency code '" + code + "' was not rejected.");
|
||||
} else if (error.name !== "RangeError") {
|
||||
$ERROR("Invalid currency code '" + code + "' was rejected with wrong error " + error.name + ".");
|
||||
}
|
||||
}, "Invalid currency code '" + code + "' was not rejected.");
|
||||
});
|
||||
|
|
|
@ -8,15 +8,7 @@ author: Norbert Lindenberg
|
|||
---*/
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(Intl.NumberFormat, "prototype");
|
||||
if (desc === undefined) {
|
||||
$ERROR("Intl.NumberFormat.prototype is not defined.");
|
||||
}
|
||||
if (desc.writable) {
|
||||
$ERROR("Intl.NumberFormat.prototype must not be writable.");
|
||||
}
|
||||
if (desc.enumerable) {
|
||||
$ERROR("Intl.NumberFormat.prototype must not be enumerable.");
|
||||
}
|
||||
if (desc.configurable) {
|
||||
$ERROR("Intl.NumberFormat.prototype must not be configurable.");
|
||||
}
|
||||
assert.notSameValue(desc, undefined, "Intl.NumberFormat.prototype is not defined.");
|
||||
assert.sameValue(desc.writable, false, "Intl.NumberFormat.prototype must not be writable.");
|
||||
assert.sameValue(desc.enumerable, false, "Intl.NumberFormat.prototype must not be enumerable.");
|
||||
assert.sameValue(desc.configurable, false, "Intl.NumberFormat.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.NumberFormat
|
||||
if (typeof Intl.NumberFormat.prototype.format(0) !== "string") {
|
||||
$ERROR("Intl.NumberFormat's prototype is not an object that has been " +
|
||||
"initialized as an Intl.NumberFormat");
|
||||
}
|
||||
assert.sameValue(typeof Intl.NumberFormat.prototype.format(0), "string", "Intl.NumberFormat's prototype is not an object that has been initialized as an Intl.NumberFormat");
|
||||
|
|
|
@ -19,16 +19,8 @@ var invalidTargets = [undefined, null, true, 0, "NumberFormat", [], {}];
|
|||
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.NumberFormat.prototype.constructor !== Intl.NumberFormat) {
|
||||
$ERROR("Intl.NumberFormat.prototype.constructor is not the same as " +
|
||||
"Intl.NumberFormat");
|
||||
}
|
||||
assert.sameValue(Intl.NumberFormat.prototype.constructor, Intl.NumberFormat, "Intl.NumberFormat.prototype.constructor is not the same as Intl.NumberFormat");
|
||||
|
|
|
@ -20,9 +20,5 @@ for (i in testData) {
|
|||
correctResult = formatter.format(number);
|
||||
|
||||
result = formatter.format(input);
|
||||
if (result !== correctResult) {
|
||||
$ERROR('Intl.NumberFormat does not convert other ' +
|
||||
'types to numbers. Input: "'+input+'" Output: "'+result+'" '+
|
||||
'Expected output: "'+correctResult+'"');
|
||||
}
|
||||
assert.sameValue(result, correctResult, 'Intl.NumberFormat does not convert other types to numbers. Input: "' + input + '".');
|
||||
}
|
||||
|
|
|
@ -30,11 +30,7 @@ locales.forEach(function (locales) {
|
|||
numbers.forEach(function (number) {
|
||||
var referenceFormatted = formatObj.format(number);
|
||||
var formatted = formatFunc(number);
|
||||
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) + ".");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -11,10 +11,6 @@ author: Roozbeh Pournader
|
|||
|
||||
var formatter = new Intl.NumberFormat();
|
||||
|
||||
if (formatter.format(1) === formatter.format(-1)) {
|
||||
$ERROR('Intl.NumberFormat is formatting 1 and -1 the same way.');
|
||||
}
|
||||
assert.notSameValue(formatter.format(1), formatter.format(-1), 'Intl.NumberFormat is formatting 1 and -1 the same way.');
|
||||
|
||||
if (formatter.format(-0) !== formatter.format(0)) {
|
||||
$ERROR('Intl.NumberFormat is formatting signed zeros differently.');
|
||||
}
|
||||
assert.sameValue(formatter.format(-0), formatter.format(0), 'Intl.NumberFormat is formatting signed zeros differently.');
|
||||
|
|
|
@ -30,31 +30,14 @@ var formattedNaN = formatter.format(NaN);
|
|||
var formattedInfinity = formatter.format(Infinity);
|
||||
var formattedNegativeInfinity = formatter.format(-Infinity);
|
||||
|
||||
if (formattedNaN === formattedInfinity) {
|
||||
$ERROR('Intl.NumberFormat formats NaN and Infinity the ' +
|
||||
'same way.');
|
||||
}
|
||||
assert.notSameValue(formattedNaN, formattedInfinity, 'Intl.NumberFormat formats NaN and Infinity the same way.');
|
||||
|
||||
if (formattedNaN === formattedNegativeInfinity) {
|
||||
$ERROR('Intl.NumberFormat formats NaN and negative ' +
|
||||
'Infinity the same way.');
|
||||
}
|
||||
assert.notSameValue(formattedNaN, formattedNegativeInfinity, 'Intl.NumberFormat formats NaN and negative Infinity the same way.');
|
||||
|
||||
if (formattedInfinity === formattedNegativeInfinity) {
|
||||
$ERROR('Intl.NumberFormat formats Infinity and ' +
|
||||
'negative Infinity the same way.');
|
||||
}
|
||||
assert.notSameValue(formattedInfinity, formattedNegativeInfinity, 'Intl.NumberFormat formats Infinity and negative Infinity the same way.');
|
||||
|
||||
if (hasUnicodeDigits.test(formattedNaN)) {
|
||||
$ERROR('Intl.NumberFormat formats NaN using a digit.');
|
||||
}
|
||||
assert.sameValue(hasUnicodeDigits.test(formattedNaN), false, 'Intl.NumberFormat formats NaN using a digit.');
|
||||
|
||||
if (hasUnicodeDigits.test(formattedInfinity)) {
|
||||
$ERROR('Intl.NumberFormat formats Infinity using a ' +
|
||||
'digit.');
|
||||
}
|
||||
assert.sameValue(hasUnicodeDigits.test(formattedInfinity), false, 'Intl.NumberFormat formats Infinity using a digit.');
|
||||
|
||||
if (hasUnicodeDigits.test(formattedNegativeInfinity)) {
|
||||
$ERROR('Intl.NumberFormat formats negative Infinity ' +
|
||||
'using a digit.');
|
||||
}
|
||||
assert.sameValue(hasUnicodeDigits.test(formattedNegativeInfinity), false, 'Intl.NumberFormat formats negative Infinity using a digit.');
|
||||
|
|
|
@ -17,12 +17,7 @@ var formattedTwentyPercent = percentFormatter.format(0.20);
|
|||
|
||||
// FIXME: May not work for some theoretical locales where percents and
|
||||
// normal numbers are formatted using different numbering systems.
|
||||
if (formattedTwentyPercent.indexOf(formattedTwenty) === -1) {
|
||||
$ERROR("Intl.NumberFormat's formatting of 20% does not include a " +
|
||||
"formatting of 20 as a substring.");
|
||||
}
|
||||
assert.notSameValue(formattedTwentyPercent.indexOf(formattedTwenty), -1, "Intl.NumberFormat's formatting of 20% does not include a formatting of 20 as a substring.");
|
||||
|
||||
// FIXME: Move this to somewhere appropriate
|
||||
if (percentFormatter.format(0.011) === percentFormatter.format(0.02)) {
|
||||
$ERROR('Intl.NumberFormat is formatting 1.1% and 2% the same way.');
|
||||
}
|
||||
assert.notSameValue(percentFormatter.format(0.011), percentFormatter.format(0.02), 'Intl.NumberFormat is formatting 1.1% and 2% the same way.');
|
||||
|
|
|
@ -14,9 +14,7 @@ includes: [testIntl.js]
|
|||
var actual = new Intl.NumberFormat().resolvedOptions();
|
||||
|
||||
var actual2 = new Intl.NumberFormat().resolvedOptions();
|
||||
if (actual2 === actual) {
|
||||
$ERROR("resolvedOptions returned the same object twice.");
|
||||
}
|
||||
assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice.");
|
||||
|
||||
// this assumes the default values where the specification provides them
|
||||
mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);
|
||||
|
|
|
@ -15,15 +15,9 @@ var requestedLocales = [defaultLocale, notSupported];
|
|||
|
||||
var supportedLocales;
|
||||
|
||||
if (!Intl.NumberFormat.hasOwnProperty('supportedLocalesOf')) {
|
||||
$ERROR("Intl.NumberFormat doesn't have a supportedLocalesOf property.");
|
||||
}
|
||||
assert(Intl.NumberFormat.hasOwnProperty('supportedLocalesOf'), "Intl.NumberFormat doesn't have a supportedLocalesOf property.");
|
||||
|
||||
supportedLocales = Intl.NumberFormat.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