mirror of https://github.com/tc39/test262.git
Use assert-lib: intl402/Collator
This commit is contained in:
parent
19eb1d2e02
commit
3aa427257b
|
@ -14,16 +14,12 @@ testWithIntlConstructors(function (Constructor) {
|
|||
// variant 1: use constructor in a "new" expression
|
||||
obj = new Constructor();
|
||||
newObj = Intl.Collator.call(obj);
|
||||
if (obj === newObj) {
|
||||
$ERROR("Collator object created with \"new\" was not ignored as this-value.");
|
||||
}
|
||||
assert.notSameValue(obj, newObj, "Collator object created with \"new\" was not ignored as this-value.");
|
||||
|
||||
// variant 2: use constructor as a function
|
||||
obj = Constructor();
|
||||
newObj = Intl.Collator.call(obj);
|
||||
if (obj === newObj) {
|
||||
$ERROR("Collator object created with constructor as function was not ignored as this-value.");
|
||||
}
|
||||
assert.notSameValue(obj, newObj, "Collator object created with constructor as function was not ignored as this-value.");
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -13,6 +13,4 @@ includes: [testIntl.js]
|
|||
taintProperties(["localeMatcher", "kn", "kf"]);
|
||||
|
||||
var locale = new Intl.Collator(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
|
||||
if (!isCanonicalizedStructurallyValidLanguageTag(locale)) {
|
||||
$ERROR("Collator returns invalid locale " + locale + ".");
|
||||
}
|
||||
assert(isCanonicalizedStructurallyValidLanguageTag(locale), "Collator returns invalid locale " + locale + ".");
|
||||
|
|
|
@ -13,16 +13,10 @@ function checkCollation(extensionCoValue, usageValue, expectedCollations, expect
|
|||
var collator = new Intl.Collator([requestLocale], options);
|
||||
|
||||
var collation = collator.resolvedOptions().collation;
|
||||
if (expectedCollations.indexOf(collation) === -1) {
|
||||
$ERROR((extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) +
|
||||
"\" should be " + expectedCollations.join(" or ") + ", but is " + collation + ".");
|
||||
}
|
||||
assert.notSameValue(expectedCollations.indexOf(collation), -1, (extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) + "\" should be " + expectedCollations.join(" or ") + ", but is " + collation + ".");
|
||||
|
||||
var usage = collator.resolvedOptions().usage;
|
||||
if (expectedUsage !== usage) {
|
||||
$ERROR((usageValue === undefined ? "Default usage" : "Usage") +
|
||||
" should be " + expectedUsage + ", but is " + usage + ".");
|
||||
}
|
||||
assert.sameValue(usage, expectedUsage, (usageValue === undefined ? "Default usage" : "Usage") + " mismatch.");
|
||||
}
|
||||
|
||||
checkCollation(undefined, undefined, ["default"], "sort");
|
||||
|
|
|
@ -35,10 +35,7 @@ options.forEach(function (option) {
|
|||
supportedValues.forEach(function (value) {
|
||||
collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]);
|
||||
result = collator.resolvedOptions()[option.property];
|
||||
if (result !== value) {
|
||||
$ERROR("Property " + option.property + " couldn't be set through locale extension key " +
|
||||
option.key + "; requested value: " + value + "; actual value: " + result + ".");
|
||||
}
|
||||
assert.sameValue(result, value, "Property " + option.property + " couldn't be set through locale extension key " + option.key + ".");
|
||||
});
|
||||
|
||||
// verify that the options setting overrides the locale setting
|
||||
|
@ -54,10 +51,7 @@ options.forEach(function (option) {
|
|||
opt[option.property] = value;
|
||||
collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt);
|
||||
result = collator.resolvedOptions()[option.property];
|
||||
if (result !== value) {
|
||||
$ERROR("Options value for property " + option.property + " doesn't override locale extension key " +
|
||||
option.key + "; requested value: " + value + "; actual value: " + result + ".");
|
||||
}
|
||||
assert.sameValue(result, value, "Options value for property " + option.property + " doesn't override locale extension key " + option.key + ".");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,10 +12,6 @@ author: Norbert Lindenberg
|
|||
var obj = new Intl.Collator();
|
||||
|
||||
var actualPrototype = Object.getPrototypeOf(obj);
|
||||
if (actualPrototype !== Intl.Collator.prototype) {
|
||||
$ERROR("Prototype of object constructed by Intl.Collator isn't Intl.Collator.prototype; got " + actualPrototype);
|
||||
}
|
||||
assert.sameValue(actualPrototype, Intl.Collator.prototype, "Prototype of object constructed by Intl.Collator isn't Intl.Collator.prototype.");
|
||||
|
||||
if (!Object.isExtensible(obj)) {
|
||||
$ERROR("Object constructed by Intl.Collator must be extensible.");
|
||||
}
|
||||
assert(Object.isExtensible(obj), "Object constructed by Intl.Collator must be extensible.");
|
||||
|
|
|
@ -39,14 +39,8 @@ Object.getOwnPropertyNames(keyValues).forEach(function (key) {
|
|||
keyValues[key].forEach(function (value) {
|
||||
var collator = new Intl.Collator([defaultLocale + "-u-" + key + "-" + value]);
|
||||
var options = collator.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 + ".");
|
||||
}
|
||||
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 + ".");
|
||||
testArraysAreSame(defaultSortedArray, testArray.sort(collator.compare));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,6 +10,4 @@ author: Norbert Lindenberg
|
|||
var obj = new Intl.Collator();
|
||||
|
||||
var toStringValue = Object.prototype.toString.call(obj);
|
||||
if (toStringValue !== "[object Object]") {
|
||||
$ERROR("Intl.Collator instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
|
||||
}
|
||||
assert.sameValue(toStringValue, "[object Object]", "Intl.Collator instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
|
||||
|
|
|
@ -17,11 +17,7 @@ extensions.forEach(function (extension) {
|
|||
var locale = collator.resolvedOptions().locale;
|
||||
var numeric = collator.resolvedOptions().numeric;
|
||||
if (numeric !== undefined) {
|
||||
if (numeric !== true) {
|
||||
$ERROR("Default value for \"kn\" should be true, but is " + numeric + ".");
|
||||
}
|
||||
if (locale.indexOf("-kn") !== -1) {
|
||||
$ERROR("\"kn\" is returned in locale, but shouldn't be.");
|
||||
}
|
||||
assert.sameValue(numeric, true, "Default value for \"kn\" should be true, but is " + numeric + ".");
|
||||
assert.sameValue(locale.indexOf("-kn"), -1, "\"kn\" is returned in locale, but shouldn't be.");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,15 +8,7 @@ author: Norbert Lindenberg
|
|||
---*/
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(Intl.Collator, "prototype");
|
||||
if (desc === undefined) {
|
||||
$ERROR("Intl.Collator.prototype is not defined.");
|
||||
}
|
||||
if (desc.writable) {
|
||||
$ERROR("Intl.Collator.prototype must not be writable.");
|
||||
}
|
||||
if (desc.enumerable) {
|
||||
$ERROR("Intl.Collator.prototype must not be enumerable.");
|
||||
}
|
||||
if (desc.configurable) {
|
||||
$ERROR("Intl.Collator.prototype must not be configurable.");
|
||||
}
|
||||
assert.notSameValue(desc, undefined, "Intl.Collator.prototype is not defined.");
|
||||
assert.sameValue(desc.writable, false, "Intl.Collator.prototype must not be writable.");
|
||||
assert.sameValue(desc.enumerable, false, "Intl.Collator.prototype must not be enumerable.");
|
||||
assert.sameValue(desc.configurable, false, "Intl.Collator.prototype must not be configurable.");
|
||||
|
|
|
@ -10,7 +10,4 @@ description: >
|
|||
|
||||
// test by calling a function that would fail if "this" were not an object
|
||||
// initialized as an Intl.Collator
|
||||
if (Intl.Collator.prototype.compare("aаあ아", "aаあ아") !== 0) {
|
||||
$ERROR("Intl.Collator.prototype is not an object that has been " +
|
||||
"initialized as an Intl.Collator.");
|
||||
}
|
||||
assert.sameValue(Intl.Collator.prototype.compare("aаあ아", "aаあ아"), 0, "Intl.Collator.prototype is not an object that has been initialized as an Intl.Collator.");
|
||||
|
|
|
@ -19,16 +19,8 @@ var invalidTargets = [undefined, null, true, 0, "Collator", [], {}];
|
|||
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.");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -52,10 +52,7 @@ var pairs = [
|
|||
var i;
|
||||
for (i = 0; i < pairs.length; i++) {
|
||||
var pair = pairs[i];
|
||||
if (collator.compare(pair[0], pair[1]) !== 0) {
|
||||
$ERROR("Collator.compare considers " + pair[0] + " (" + toU(pair[0]) +
|
||||
") ≠ " + pair[1] + " (" + toU(pair[1]) + ").");
|
||||
}
|
||||
assert.sameValue(collator.compare(pair[0], pair[1]), 0, "Collator.compare considers " + pair[0] + " (" + toU(pair[0]) + ") ≠ " + pair[1] + " (" + toU(pair[1]) + ").");
|
||||
}
|
||||
|
||||
function toU(s) {
|
||||
|
|
|
@ -8,7 +8,4 @@ description: >
|
|||
Intl.Collator.
|
||||
---*/
|
||||
|
||||
if (Intl.Collator.prototype.constructor !== Intl.Collator) {
|
||||
$ERROR("Intl.Collator.prototype.constructor is not the same as " +
|
||||
"Intl.Collator");
|
||||
}
|
||||
assert.sameValue(Intl.Collator.prototype.constructor, Intl.Collator, "Intl.Collator.prototype.constructor is not the same as Intl.Collator");
|
||||
|
|
|
@ -13,9 +13,7 @@ includes: [testIntl.js]
|
|||
var actual = new Intl.Collator().resolvedOptions();
|
||||
|
||||
var actual2 = new Intl.Collator().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/collation.xml; version CLDR 21.
|
||||
var collations = [
|
||||
|
|
|
@ -14,15 +14,9 @@ var requestedLocales = [defaultLocale, notSupported];
|
|||
|
||||
var supportedLocales;
|
||||
|
||||
if (!Intl.Collator.hasOwnProperty('supportedLocalesOf')) {
|
||||
$ERROR("Intl.Collator doesn't have a supportedLocalesOf property.");
|
||||
}
|
||||
assert(Intl.Collator.hasOwnProperty('supportedLocalesOf'), "Intl.Collator doesn't have a supportedLocalesOf property.");
|
||||
|
||||
supportedLocales = Intl.Collator.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