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