Use assert-lib: intl402/PluralRules

This commit is contained in:
André Bargull 2017-05-04 21:25:02 +02:00
parent bfac377fca
commit 0271179c4a
6 changed files with 14 additions and 45 deletions

View File

@ -12,10 +12,6 @@ author: Zibi Braniecki
var obj = new Intl.PluralRules(); var obj = new Intl.PluralRules();
var actualPrototype = Object.getPrototypeOf(obj); var actualPrototype = Object.getPrototypeOf(obj);
if (actualPrototype !== Intl.PluralRules.prototype) { assert.sameValue(actualPrototype, Intl.PluralRules.prototype, "Prototype of object constructed by Intl.PluralRules isn't Intl.PluralRules.prototype; got " + actualPrototype);
$ERROR("Prototype of object constructed by Intl.PluralRules isn't Intl.PluralRules.prototype; got " + actualPrototype);
}
if (!Object.isExtensible(obj)) { assert(Object.isExtensible(obj), "Object constructed by Intl.PluralRules must be extensible.");
$ERROR("Object constructed by Intl.PluralRules must be extensible.");
}

View File

@ -19,16 +19,8 @@ var invalidTargets = [undefined, null, true, 0, "PluralRules", [], {}];
Object.getOwnPropertyNames(functions).forEach(function (functionName) { Object.getOwnPropertyNames(functions).forEach(function (functionName) {
var f = functions[functionName]; var f = functions[functionName];
invalidTargets.forEach(function (target) { invalidTargets.forEach(function (target) {
var error; assert.throws(TypeError, function () {
try {
f.call(target); f.call(target);
} catch (e) { }, "Calling " + functionName + " on " + target + " was not rejected.");
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 + ".");
}
}); });
}); });

View File

@ -9,7 +9,4 @@ description: >
author: Zibi Braniecki author: Zibi Braniecki
---*/ ---*/
if (Intl.PluralRules.prototype.constructor !== Intl.PluralRules) { assert.sameValue(Intl.PluralRules.prototype.constructor, Intl.PluralRules, "Intl.PluralRules.prototype.constructor is not the same as Intl.PluralRules");
$ERROR("Intl.PluralRules.prototype.constructor is not the same as " +
"Intl.PluralRules");
}

View File

@ -8,15 +8,7 @@ author: Zibi Braniecki
---*/ ---*/
var desc = Object.getOwnPropertyDescriptor(Intl.PluralRules, "prototype"); var desc = Object.getOwnPropertyDescriptor(Intl.PluralRules, "prototype");
if (desc === undefined) { assert.notSameValue(desc, undefined, "Intl.PluralRules.prototype is not defined.");
$ERROR("Intl.PluralRules.prototype is not defined."); assert.sameValue(desc.writable, false, "Intl.PluralRules.prototype must not be writable.");
} assert.sameValue(desc.enumerable, false, "Intl.PluralRules.prototype must not be enumerable.");
if (desc.writable) { assert.sameValue(desc.configurable, false, "Intl.PluralRules.prototype must not be configurable.");
$ERROR("Intl.PluralRules.prototype must not be writable.");
}
if (desc.enumerable) {
$ERROR("Intl.PluralRules.prototype must not be enumerable.");
}
if (desc.configurable) {
$ERROR("Intl.PluralRules.prototype must not be configurable.");
}

View File

@ -14,9 +14,7 @@ includes: [testIntl.js]
var actual = new Intl.PluralRules().resolvedOptions(); var actual = new Intl.PluralRules().resolvedOptions();
var actual2 = new Intl.PluralRules().resolvedOptions(); var actual2 = new Intl.PluralRules().resolvedOptions();
if (actual2 === actual) { assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice.");
$ERROR("resolvedOptions returned the same object twice.");
}
// this assumes the default values where the specification provides them // this assumes the default values where the specification provides them
mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);

View File

@ -15,15 +15,9 @@ var requestedLocales = [defaultLocale, notSupported];
var supportedLocales; var supportedLocales;
if (!Intl.PluralRules.hasOwnProperty('supportedLocalesOf')) { assert(Intl.PluralRules.hasOwnProperty('supportedLocalesOf'), "Intl.PluralRules doesn't have a supportedLocalesOf property.");
$ERROR("Intl.PluralRules doesn't have a supportedLocalesOf property.");
}
supportedLocales = Intl.PluralRules.supportedLocalesOf(requestedLocales); supportedLocales = Intl.PluralRules.supportedLocalesOf(requestedLocales);
if (supportedLocales.length !== 1) { assert.sameValue(supportedLocales.length, 1, 'The length of supported locales list is not 1.');
$ERROR('The length of supported locales list is not 1.');
} assert.sameValue(supportedLocales[0], defaultLocale, 'The default locale is not returned in the supported list.');
if (supportedLocales[0] !== defaultLocale) {
$ERROR('The default locale is not returned in the supported list.');
}