Use assert-lib: intl402/Number

This commit is contained in:
André Bargull 2017-05-04 21:14:05 +02:00
parent c63cb39cbb
commit 315031c07d
2 changed files with 11 additions and 44 deletions

View File

@ -11,17 +11,9 @@ var invalidValues = [undefined, null, "5", false, {valueOf: function () { return
var validValues = [5, NaN, -1234567.89, -Infinity];
invalidValues.forEach(function (value) {
var error;
try {
assert.throws(TypeError, function() {
var result = Number.prototype.toLocaleString.call(value);
} catch (e) {
error = e;
}
if (error === undefined) {
$ERROR("Number.prototype.toLocaleString did not reject this = " + value + ".");
} else if (error.name !== "TypeError") {
$ERROR("Number.prototype.toLocaleString rejected this = " + value + " with wrong error " + error.name + ".");
}
}, "Number.prototype.toLocaleString did not reject this = " + value + ".");
});
// for valid values, just check that a Number value and the corresponding
@ -30,8 +22,5 @@ validValues.forEach(function (value) {
var Constructor = Number; // to keep jshint happy
var valueResult = Number.prototype.toLocaleString.call(value);
var objectResult = Number.prototype.toLocaleString.call(new Constructor(value));
if (valueResult !== objectResult) {
$ERROR("Number.prototype.toLocaleString produces different results for Number value " +
value + " and corresponding Number object: " + valueResult + " vs. " + objectResult + ".");
}
assert.sameValue(valueResult, objectResult, "Number.prototype.toLocaleString produces different results for Number value " + value + " and corresponding Number object.");
});

View File

@ -25,21 +25,11 @@ locales.forEach(function (locales) {
} catch (e) {
referenceError = e;
}
if (referenceError === undefined) {
$ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + ".");
}
try {
assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + ".");
assert.throws(referenceError.constructor, function() {
var result = (0).toLocaleString(locales);
} catch (e) {
error = e;
}
if (error === undefined) {
$ERROR("Number.prototype.toLocaleString didn't throw exception for locales " + locales + ".");
} else if (error.name !== referenceError.name) {
$ERROR("Number.prototype.toLocaleString threw exception " + error.name +
" for locales " + locales + "; expected " + referenceError.name + ".");
}
}, "Number.prototype.toLocaleString didn't throw exception for locales " + locales + ".");
});
options.forEach(function (options) {
@ -49,21 +39,9 @@ options.forEach(function (options) {
} catch (e) {
referenceError = e;
}
if (referenceError === undefined) {
$ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for options " +
JSON.stringify(options) + ".");
}
try {
assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.NumberFormat for options " + JSON.stringify(options) + ".");
assert.throws(referenceError.constructor, function() {
var result = (0).toLocaleString([], options);
} catch (e) {
error = e;
}
if (error === undefined) {
$ERROR("Number.prototype.toLocaleString didn't throw exception for options " +
JSON.stringify(options) + ".");
} else if (error.name !== referenceError.name) {
$ERROR("Number.prototype.toLocaleString threw exception " + error.name +
" for options " + JSON.stringify(options) + "; expected " + referenceError.name + ".");
}
}, "Number.prototype.toLocaleString didn't throw exception for options " + JSON.stringify(options) + ".");
});