Merge pull request #1024 from anba/assert-lib-intl402-rebase

Switch to assert-lib in intl402
This commit is contained in:
Leo Balter 2017-05-05 12:19:48 -04:00 committed by GitHub
commit fbf992bd3f
94 changed files with 227 additions and 786 deletions

View File

@ -25,18 +25,10 @@ var invalidLanguageTags = [
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
invalidLanguageTags.forEach(function (tag) { invalidLanguageTags.forEach(function (tag) {
var error;
try {
// this must throw an exception for an invalid language tag // this must throw an exception for an invalid language tag
assert.throws(RangeError, function() {
var obj = new Constructor([tag]); var obj = new Constructor([tag]);
} catch (e) { }, "Invalid language tag " + tag + " was not rejected.");
error = e;
}
if (error === undefined) {
$ERROR("Invalid language tag " + tag + " was not rejected.");
} else if (error.name !== "RangeError") {
$ERROR("Invalid language tag " + tag + " was rejected with wrong error " + error.name + ".");
}
}); });
return true; return true;
}); });

View File

@ -31,18 +31,10 @@ var invalidLanguageTags = [
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
invalidLanguageTags.forEach(function (tag) { invalidLanguageTags.forEach(function (tag) {
var error;
try {
// this must throw an exception for an invalid language tag // this must throw an exception for an invalid language tag
assert.throws(RangeError, function() {
var obj = new Constructor([tag]); var obj = new Constructor([tag]);
} catch (e) { }, "Invalid language tag " + tag + " was not rejected.");
error = e;
}
if (error === undefined) {
$ERROR("Invalid language tag " + tag + " was not rejected.");
} else if (error.name !== "RangeError") {
$ERROR("Invalid language tag " + tag + " was rejected with wrong error " + error.name + ".");
}
}); });
return true; return true;
}); });

View File

@ -35,9 +35,7 @@ var canonicalizedTags = {
// make sure the data above is correct // make sure the data above is correct
Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) { Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
canonicalizedTags[tag].forEach(function (canonicalTag) { canonicalizedTags[tag].forEach(function (canonicalTag) {
if (!isCanonicalizedStructurallyValidLanguageTag(canonicalTag)) { assert(isCanonicalizedStructurallyValidLanguageTag(canonicalTag), "Test data \"" + canonicalTag + "\" is not canonicalized and structurally valid language tag.");
$ERROR("Test data \"" + canonicalTag + "\" is not canonicalized and structurally valid language tag.");
}
}); });
}); });
@ -51,17 +49,11 @@ testWithIntlConstructors(function (Constructor) {
// In this variant, shortened forms or the default locale may be returned // In this variant, shortened forms or the default locale may be returned
var object = new Constructor([tag], {localeMatcher: "lookup"}); var object = new Constructor([tag], {localeMatcher: "lookup"});
var locale = object.resolvedOptions().locale; var locale = object.resolvedOptions().locale;
if (canonicalizedTags[tag].indexOf(locale) === -1 && locale !== defaultLocale) { assert(canonicalizedTags[tag].indexOf(locale) !== -1 || locale === defaultLocale, "For " + tag + " got " + locale + "; expected one of " + canonicalizedTags[tag].join(", ") + ".");
$ERROR("For " + tag + " got " + locale + "; expected one of " +
canonicalizedTags[tag].join(", ") + ".");
}
// Variant 2: get the supported locales. If the tag is supported, it should be returned canonicalized but unshortened // Variant 2: get the supported locales. If the tag is supported, it should be returned canonicalized but unshortened
var supported = Constructor.supportedLocalesOf([tag]); var supported = Constructor.supportedLocalesOf([tag]);
if (supported.length > 0 && supported[0] !== canonicalizedTags[tag][0]) { assert(supported.length === 0 || supported[0] === canonicalizedTags[tag][0], "For " + tag + " got " + supported[0] + "; expected " + canonicalizedTags[tag][0] + ".");
$ERROR("For " + tag + " got " + supported[0] + "; expected " +
canonicalizedTags[tag][0] + ".");
}
}); });
return true; return true;
}); });

View File

@ -12,8 +12,6 @@ includes: [testIntl.js]
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var defaultLocale = new Constructor().resolvedOptions().locale; var defaultLocale = new Constructor().resolvedOptions().locale;
if (!isCanonicalizedStructurallyValidLanguageTag(defaultLocale)) { assert(isCanonicalizedStructurallyValidLanguageTag(defaultLocale), "Default locale \"" + defaultLocale + "\" is not canonicalized and structurally valid language tag.");
$ERROR("Default locale \"" + defaultLocale + "\" is not canonicalized and structurally valid language tag.");
}
return true; return true;
}); });

View File

@ -11,7 +11,5 @@ includes: [testIntl.js]
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var defaultLocale = new Constructor().resolvedOptions().locale; var defaultLocale = new Constructor().resolvedOptions().locale;
var supportedLocales = Constructor.supportedLocalesOf([defaultLocale]); var supportedLocales = Constructor.supportedLocalesOf([defaultLocale]);
if (supportedLocales.indexOf(defaultLocale) === -1) { assert.notSameValue(supportedLocales.indexOf(defaultLocale), -1, "Default locale is not reported as available.");
$ERROR("Default locale is not reported as available.");
}
}); });

View File

@ -17,16 +17,12 @@ testWithIntlConstructors(function (Constructor) {
var pos = locale.lastIndexOf("-"); var pos = locale.lastIndexOf("-");
if (pos !== -1) { if (pos !== -1) {
fallback = locale.substring(0, pos); fallback = locale.substring(0, pos);
if (info.supported.indexOf(fallback) === -1) { assert.notSameValue(info.supported.indexOf(fallback), -1, "Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
$ERROR("Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
}
} }
var match = /([a-z]{2,3})(-[A-Z][a-z]{3})(-[A-Z]{2})/.exec(locale); var match = /([a-z]{2,3})(-[A-Z][a-z]{3})(-[A-Z]{2})/.exec(locale);
if (match !== null) { if (match !== null) {
fallback = match[1] + match[3]; fallback = match[1] + match[3];
if (info.supported.indexOf(fallback) === -1) { assert.notSameValue(info.supported.indexOf(fallback), -1, "Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
$ERROR("Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
}
} }
}); });
}); });

View File

@ -13,12 +13,8 @@ includes: [testIntl.js]
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var supportedForUndefined = Constructor.supportedLocalesOf(undefined); var supportedForUndefined = Constructor.supportedLocalesOf(undefined);
var supportedForEmptyList = Constructor.supportedLocalesOf([]); var supportedForEmptyList = Constructor.supportedLocalesOf([]);
if (supportedForUndefined.length !== supportedForEmptyList.length) { assert.sameValue(supportedForUndefined.length, supportedForEmptyList.length, "Supported locales differ between undefined and empty list input.");
$ERROR("Supported locales differ between undefined and empty list input.");
}
// we don't compare the elements because length should be 0 - let's just verify that // we don't compare the elements because length should be 0 - let's just verify that
if (supportedForUndefined.length !== 0) { assert.sameValue(supportedForUndefined.length, 0, "Internal test error: Assumption about length being 0 is invalid.");
$ERROR("Internal test error: Assumption about length being 0 is invalid.");
}
return true; return true;
}); });

View File

@ -15,7 +15,5 @@ taintArray();
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var defaultLocale = new Constructor().resolvedOptions().locale; var defaultLocale = new Constructor().resolvedOptions().locale;
var canonicalized = Constructor.supportedLocalesOf([defaultLocale, defaultLocale]); var canonicalized = Constructor.supportedLocalesOf([defaultLocale, defaultLocale]);
if (canonicalized.length > 1) { assert.sameValue(canonicalized.length > 1, false, "Canonicalization didn't remove duplicate language tags from locale list.");
$ERROR("Canonicalization didn't remove duplicate language tags from locale list.");
}
}); });

View File

@ -61,24 +61,11 @@ testWithIntlConstructors(function (Constructor) {
error2 = e; error2 = e;
} }
if ((error1 === undefined) !== (error2 === undefined)) { assert.sameValue((error1 === undefined), (error2 === undefined), "Single locale string " + locale + " was " + (error1 === undefined ? "accepted" : "rejected") + ", but locale list containing that string wasn't.");
if (error1 === undefined) { if (error1 === undefined) {
$ERROR("Single locale string " + locale + assert.sameValue(locale1, locale2, "Single locale string " + locale + " results in " + locale1 + ", but locale list [" + locale + "] results in " + locale2 + ".");
" was accepted, but locale list containing that string wasn't.");
} else { } else {
$ERROR("Single locale string " + locale + assert.sameValue(error1.name, error2.name, "Single locale string " + locale + " results in error " + error1.name + ", but locale list [" + locale + "] results in error " + error2.name + ".");
" was rejected, but locale list containing that string wasn't.");
}
} else if (error1 === undefined) {
if (locale1 !== locale2) {
$ERROR("Single locale string " + locale + " results in " + locale1 +
", but locale list [" + locale + "] results in " + locale2 + ".");
}
} else {
if (error1.name !== error2.name) {
$ERROR("Single locale string " + locale + " results in error " + error1.name +
", but locale list [" + locale + "] results in error " + error2.name + ".");
}
} }
}); });

View File

@ -14,34 +14,20 @@ testWithIntlConstructors(function (Constructor) {
// undefined is handled separately // undefined is handled separately
// null should result in a TypeError // null should result in a TypeError
var error; assert.throws(TypeError, function() {
try {
var supportedForNull = Constructor.supportedLocalesOf(null); var supportedForNull = Constructor.supportedLocalesOf(null);
} catch (e) { }, "Null as locale list was not rejected.");
error = e;
}
if (error === undefined) {
$ERROR("Null as locale list was not rejected.");
} else if (error.name !== "TypeError") {
$ERROR("Null as locale list was rejected with wrong error " + error.name + ".");
}
// let's use an empty list for comparison // let's use an empty list for comparison
var supportedForEmptyList = Constructor.supportedLocalesOf([]); var supportedForEmptyList = Constructor.supportedLocalesOf([]);
// we don't compare the elements because length should be 0 - let's just verify that // we don't compare the elements because length should be 0 - let's just verify that
if (supportedForEmptyList.length !== 0) { assert.sameValue(supportedForEmptyList.length, 0, "Internal test error: Assumption about length being 0 is invalid.");
$ERROR("Internal test error: Assumption about length being 0 is invalid.");
}
// most non-objects will be interpreted as empty lists because a missing length property is interpreted as 0 // most non-objects will be interpreted as empty lists because a missing length property is interpreted as 0
var supportedForNumber = Constructor.supportedLocalesOf(5); var supportedForNumber = Constructor.supportedLocalesOf(5);
if (supportedForNumber.length !== supportedForEmptyList.length) { assert.sameValue(supportedForNumber.length, supportedForEmptyList.length, "Supported locales differ between numeric and empty list input.");
$ERROR("Supported locales differ between numeric and empty list input.");
}
var supportedForBoolean = Constructor.supportedLocalesOf(true); var supportedForBoolean = Constructor.supportedLocalesOf(true);
if (supportedForBoolean.length !== supportedForEmptyList.length) { assert.sameValue(supportedForBoolean.length, supportedForEmptyList.length, "Supported locales differ between boolean and empty list input.");
$ERROR("Supported locales differ between boolean and empty list input.");
}
return true; return true;
}); });

View File

@ -12,17 +12,9 @@ var notStringOrObject = [undefined, null, true, false, 0, 5, -5, NaN];
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
notStringOrObject.forEach(function (value) { notStringOrObject.forEach(function (value) {
var error; assert.throws(TypeError, function() {
try {
var supported = Constructor.supportedLocalesOf([value]); var supported = Constructor.supportedLocalesOf([value]);
} catch (e) { }, "" + value + " as locale was not rejected.");
error = e;
}
if (error === undefined) {
$ERROR("" + value + " as locale was not rejected.");
} else if (error.name !== "TypeError") {
$ERROR("" + value + " as locale was rejected with wrong error " + error.name + ".");
}
}); });
return true; return true;

View File

@ -13,7 +13,5 @@ includes: [testIntl.js]
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var defaultLocale = new Constructor().resolvedOptions().locale; var defaultLocale = new Constructor().resolvedOptions().locale;
var canonicalized = Constructor.supportedLocalesOf([defaultLocale, defaultLocale]); var canonicalized = Constructor.supportedLocalesOf([defaultLocale, defaultLocale]);
if (canonicalized.length > 1) { assert.sameValue(canonicalized.length > 1, false, "Canonicalization didn't remove duplicate language tags from locale list.");
$ERROR("Canonicalization didn't remove duplicate language tags from locale list.");
}
}); });

View File

@ -23,23 +23,15 @@ testWithIntlConstructors(function (Constructor) {
while (i < limit && supportedByConstructor[i] === supported[i]) { while (i < limit && supportedByConstructor[i] === supported[i]) {
i++; i++;
} }
if (i < supportedByConstructor.length) { assert.sameValue(i < supportedByConstructor.length, false, "Locale " + supportedByConstructor[i] + " is returned by resolvedOptions but not by supportedLocalesOf.");
$ERROR("Locale " + supportedByConstructor[i] + assert.sameValue(i < supported.length, false, "Locale " + supported[i] + " is returned by supportedLocalesOf but not by resolvedOptions.");
" is returned by resolvedOptions but not by supportedLocalesOf.");
} else if (i < supported.length) {
$ERROR("Locale " + supported[i] +
" is returned by supportedLocalesOf but not by resolvedOptions.");
}
}); });
// this test is only valid for lookup - best fit may find additional locales supported // this test is only valid for lookup - best fit may find additional locales supported
var unsupportedByConstructor = info.unsupported; var unsupportedByConstructor = info.unsupported;
var supported = Constructor.supportedLocalesOf(unsupportedByConstructor, var supported = Constructor.supportedLocalesOf(unsupportedByConstructor,
{localeMatcher: "lookup"}); {localeMatcher: "lookup"});
if (supported.length > 0) { assert.sameValue(supported.length > 0, false, "Locale " + supported[0] + " is returned by supportedLocalesOf but not by resolvedOptions.");
$ERROR("Locale " + supported[0] +
" is returned by supportedLocalesOf but not by resolvedOptions.");
}
return true; return true;
}); });

View File

@ -14,9 +14,7 @@ taintProperties(["locale", "extension", "extensionIndex"]);
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var locale = new Constructor(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; var locale = new Constructor(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { assert(isCanonicalizedStructurallyValidLanguageTag(locale), "Constructor returns invalid locale " + locale + ".");
$ERROR("Constructor returns invalid locale " + locale + ".");
}
return true; return true;
}); });

View File

@ -14,9 +14,7 @@ taintProperties(["dataLocale", "nu", "ca", "co", "locale"]);
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var locale = new Constructor(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; var locale = new Constructor(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { assert(isCanonicalizedStructurallyValidLanguageTag(locale), "Constructor returns invalid locale " + locale + ".");
$ERROR("Constructor returns invalid locale " + locale + ".");
}
return true; return true;
}); });

View File

@ -18,9 +18,7 @@ testWithIntlConstructors(function (Constructor) {
var defaultLocale = new Constructor().resolvedOptions().locale; var defaultLocale = new Constructor().resolvedOptions().locale;
var canonicalized = Constructor.supportedLocalesOf([defaultLocale, defaultLocale], var canonicalized = Constructor.supportedLocalesOf([defaultLocale, defaultLocale],
{localeMatcher: matcher}); {localeMatcher: matcher});
if (canonicalized.length > 1) { assert.sameValue(canonicalized.length > 1, false, "Canonicalization with matcher " + matcher + " didn't remove duplicate language tags from locale list.");
$ERROR("Canonicalization with matcher " + matcher + " didn't remove duplicate language tags from locale list.");
}
}); });
return true; return true;

View File

@ -14,9 +14,7 @@ testWithIntlConstructors(function (Constructor) {
// this test should work equally for both matching algorithms // this test should work equally for both matching algorithms
["lookup", "best fit"].forEach(function (matcher) { ["lookup", "best fit"].forEach(function (matcher) {
var supported = Constructor.supportedLocalesOf([], {localeMatcher: matcher}); var supported = Constructor.supportedLocalesOf([], {localeMatcher: matcher});
if (supported.length !== 0) { assert.sameValue(supported.length, 0, "SupportedLocales with matcher " + matcher + " returned a non-empty list for an empty list.");
$ERROR("SupportedLocales with matcher " + matcher + " returned a non-empty list for an empty list.");
}
}); });
return true; return true;

View File

@ -25,19 +25,13 @@ testWithIntlConstructors(function (Constructor) {
var supported3 = Constructor.supportedLocalesOf([locale + invalidExtension], var supported3 = Constructor.supportedLocalesOf([locale + invalidExtension],
{localeMatcher: matcher}); {localeMatcher: matcher});
if (supported1.length === 1) { if (supported1.length === 1) {
if (supported2.length !== 1 || supported3.length !== 1) { assert.sameValue(supported2.length, 1, "#1.1: Presence of Unicode locale extension sequence affects whether locale " + locale + " is considered supported with matcher " + matcher + ".");
$ERROR("Presence of Unicode locale extension sequence affects whether locale " + assert.sameValue(supported3.length, 1, "#1.2: Presence of Unicode locale extension sequence affects whether locale " + locale + " is considered supported with matcher " + matcher + ".");
locale + " is considered supported with matcher " + matcher + "."); assert.sameValue(supported2[0], locale + validExtension, "#2.1: Unicode locale extension sequence is not correctly returned for locale " + locale + " with matcher " + matcher + ".");
} assert.sameValue(supported3[0], locale + invalidExtension, "#2.2: Unicode locale extension sequence is not correctly returned for locale " + locale + " with matcher " + matcher + ".");
if (supported2[0] !== locale + validExtension || supported3[0] !== locale + invalidExtension) {
$ERROR("Unicode locale extension sequence is not correctly returned for locale " +
locale + " with matcher " + matcher + ".");
}
} else { } else {
if (supported2.length !== 0 || supported3.length !== 0) { assert.sameValue(supported2.length, 0, "#3.1: Presence of Unicode locale extension sequence affects whether locale " + locale + " is considered supported with matcher " + matcher + ".");
$ERROR("Presence of Unicode locale extension sequence affects whether locale " + assert.sameValue(supported3.length, 0, "#3.2: Presence of Unicode locale extension sequence affects whether locale " + locale + " is considered supported with matcher " + matcher + ".");
locale + " is considered supported with matcher " + matcher + ".");
}
} }
}); });
}); });

View File

@ -17,15 +17,9 @@ testWithIntlConstructors(function (Constructor) {
var noLinguisticContent = "zxx"; var noLinguisticContent = "zxx";
var supported = Constructor.supportedLocalesOf([defaultLocale, noLinguisticContent], var supported = Constructor.supportedLocalesOf([defaultLocale, noLinguisticContent],
{localeMatcher: matcher}); {localeMatcher: matcher});
if (supported.indexOf(defaultLocale) === -1) { assert.notSameValue(supported.indexOf(defaultLocale), -1, "SupportedLocales didn't return default locale with matcher " + matcher + ".");
$ERROR("SupportedLocales didn't return default locale with matcher " + matcher + "."); assert.sameValue(supported.indexOf(noLinguisticContent), -1, "SupportedLocales returned the \"no linguistic content\" locale with matcher " + matcher + ".");
} assert.sameValue(supported.length > 1, false, "SupportedLocales returned stray locales: " + supported.join(", ") + " with matcher " + matcher + ".");
if (supported.indexOf(noLinguisticContent) !== -1) {
$ERROR("SupportedLocales returned the \"no linguistic content\" locale with matcher " + matcher + ".");
}
if (supported.length > 1) {
$ERROR("SupportedLocales returned stray locales: " + supported.join(", ") + " with matcher " + matcher + ".");
}
}); });
return true; return true;

View File

@ -18,17 +18,9 @@ testWithIntlConstructors(function (Constructor) {
var invalidValues = [null, 0, 5, NaN, true, false, "invalid"]; var invalidValues = [null, 0, 5, NaN, true, false, "invalid"];
invalidValues.forEach(function (value) { invalidValues.forEach(function (value) {
var error; assert.throws(RangeError, function() {
try {
var supported = Constructor.supportedLocalesOf([defaultLocale], {localeMatcher: value}); var supported = Constructor.supportedLocalesOf([defaultLocale], {localeMatcher: value});
} catch (e) { }, "Invalid localeMatcher value " + value + " was not rejected.");
error = e;
}
if (error === undefined) {
$ERROR("Invalid localeMatcher value " + value + " was not rejected.");
} else if (error.name !== "RangeError") {
$ERROR("Invalid localeMatcher value " + value + " was rejected with wrong error " + error.name + ".");
}
}); });
return true; return true;

View File

@ -12,20 +12,14 @@ includes: [testIntl.js]
function testFrozenProperty(obj, property) { function testFrozenProperty(obj, property) {
var desc = Object.getOwnPropertyDescriptor(obj, property); var desc = Object.getOwnPropertyDescriptor(obj, property);
if (desc.writable) { assert.sameValue(desc.writable, false, "Property " + property + " of object returned by SupportedLocales is writable.");
$ERROR("Property " + property + " of object returned by SupportedLocales is writable."); assert.sameValue(desc.configurable, false, "Property " + property + " of object returned by SupportedLocales is configurable.");
}
if (desc.configurable) {
$ERROR("Property " + property + " of object returned by SupportedLocales is configurable.");
}
} }
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
var defaultLocale = new Constructor().resolvedOptions().locale; var defaultLocale = new Constructor().resolvedOptions().locale;
var supported = Constructor.supportedLocalesOf([defaultLocale]); var supported = Constructor.supportedLocalesOf([defaultLocale]);
if (!Object.isExtensible(supported)) { assert(Object.isExtensible(supported), "Object returned by SupportedLocales is not extensible.");
$ERROR("Object returned by SupportedLocales is not extensible.");
}
for (var i = 0; i < supported.length; i++) { for (var i = 0; i < supported.length; i++) {
testFrozenProperty(supported, i); testFrozenProperty(supported, i);
} }

View File

@ -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;
}); });

View File

@ -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 + ".");
}

View File

@ -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");

View File

@ -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 + ".");
}
} }
}); });
}); });

View File

@ -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.");
}

View File

@ -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));
}); });
}); });

View File

@ -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 + ".");
}

View File

@ -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.");
}
} }
}); });

View File

@ -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.");
}

View File

@ -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.");
}

View File

@ -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 + ".");
}
}); });
}); });

View File

@ -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) {

View File

@ -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");
}

View File

@ -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 = [

View File

@ -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.');
}

View File

@ -19,16 +19,8 @@ var invalidValues = [undefined, null, 5, "5", false, {valueOf: function () { ret
Object.getOwnPropertyNames(functions).forEach(function (p) { Object.getOwnPropertyNames(functions).forEach(function (p) {
var f = functions[p]; var f = functions[p];
invalidValues.forEach(function (value) { invalidValues.forEach(function (value) {
var error; assert.throws(TypeError, function() {
try {
var result = f.call(value); var result = f.call(value);
} catch (e) { }, "Date.prototype." + p + " did not reject this = " + value + ".");
error = e;
}
if (error === undefined) {
$ERROR("Date.prototype." + p + " did not reject this = " + value + ".");
} else if (error.name !== "TypeError") {
$ERROR("Date.prototype." + p + " rejected this = " + value + " with wrong error " + error.name + ".");
}
}); });
}); });

View File

@ -20,9 +20,6 @@ Object.getOwnPropertyNames(functions).forEach(function (p) {
var f = functions[p]; var f = functions[p];
invalidValues.forEach(function (value) { invalidValues.forEach(function (value) {
var result = f.call(new Date(value)); var result = f.call(new Date(value));
if (result !== "Invalid Date") { assert.sameValue(result, "Invalid Date", "Date.prototype." + p + " did not return \"Invalid Date\" for " + value);
$ERROR("Date.prototype." + p + " did not return \"Invalid Date\" for " +
value + " got " + result + " instead.");
}
}); });
}); });

View File

@ -31,21 +31,11 @@ Object.getOwnPropertyNames(functions).forEach(function (p) {
} catch (e) { } catch (e) {
referenceError = e; referenceError = e;
} }
if (referenceError === undefined) { assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.DateTimeFormat for locales " + locales + ".");
$ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for locales " + locales + ".");
}
try { assert.throws(referenceError.constructor, function() {
var result = f.call(new Date(), locales); var result = f.call(new Date(), locales);
} catch (e) { }, "Date.prototype." + p + " didn't throw exception for locales " + locales + ".");
error = e;
}
if (error === undefined) {
$ERROR("Date.prototype." + p + " didn't throw exception for locales " + locales + ".");
} else if (error.name !== referenceError.name) {
$ERROR("Date.prototype." + p + " threw exception " + error.name +
" for locales " + locales + "; expected " + referenceError.name + ".");
}
}); });
options.forEach(function (options) { options.forEach(function (options) {
@ -55,22 +45,10 @@ Object.getOwnPropertyNames(functions).forEach(function (p) {
} catch (e) { } catch (e) {
referenceError = e; referenceError = e;
} }
if (referenceError === undefined) { assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.DateTimeFormat for options " + JSON.stringify(options) + ".");
$ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for options " +
JSON.stringify(options) + ".");
}
try { assert.throws(referenceError.constructor, function() {
var result = f.call(new Date(), [], options); var result = f.call(new Date(), [], options);
} catch (e) { }, "Date.prototype." + p + " didn't throw exception for options " + JSON.stringify(options) + ".");
error = e;
}
if (error === undefined) {
$ERROR("Date.prototype." + p + " didn't throw exception for options " +
JSON.stringify(options) + ".");
} else if (error.name !== referenceError.name) {
$ERROR("Date.prototype." + p + " threw exception " + error.name +
" for options " + JSON.stringify(options) + "; expected " + referenceError.name + ".");
}
}); });
}); });

View File

@ -19,16 +19,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.DateTimeFormat.call(obj); newObj = Intl.DateTimeFormat.call(obj);
if (obj === newObj) { assert.notSameValue(obj, newObj, "DateTimeFormat object created with \"new\" was not ignored as this-value.");
$ERROR("DateTimeFormat 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.DateTimeFormat.call(obj); newObj = Intl.DateTimeFormat.call(obj);
if (obj === newObj) { assert.notSameValue(obj, newObj, "DateTimeFormat object created with constructor as function was not ignored as this-value.");
$ERROR("DateTimeFormat object created with constructor as function was not ignored as this-value.");
}
return true; return true;
}); });

View File

@ -13,6 +13,4 @@ includes: [testIntl.js]
taintProperties(["weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZone"]); taintProperties(["weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZone"]);
var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { assert(isCanonicalizedStructurallyValidLanguageTag(locale), "DateTimeFormat returns invalid locale " + locale + ".");
$ERROR("DateTimeFormat returns invalid locale " + locale + ".");
}

View File

@ -13,6 +13,4 @@ includes: [testIntl.js]
taintProperties(["localeMatcher"]); taintProperties(["localeMatcher"]);
var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { assert(isCanonicalizedStructurallyValidLanguageTag(locale), "DateTimeFormat returns invalid locale " + locale + ".");
$ERROR("DateTimeFormat returns invalid locale " + locale + ".");
}

View File

@ -19,20 +19,18 @@ function testWithDateTimeFormat(options, expected) {
var resolvedOptions = format.resolvedOptions(); var resolvedOptions = format.resolvedOptions();
getDateTimeComponents().forEach(function (component) { getDateTimeComponents().forEach(function (component) {
if (resolvedOptions.hasOwnProperty(component)) { if (resolvedOptions.hasOwnProperty(component)) {
if (!expected.hasOwnProperty(component)) { assert(expected.hasOwnProperty(component),
$ERROR("Unrequested component " + component + "Unrequested component " + component +
" added to expected subset " + JSON.stringify(expected) + " added to expected subset " + JSON.stringify(expected) +
"; locales " + locales + ", options " + "; locales " + locales + ", options " +
(options ? JSON.stringify(options) : options) + "."); (options ? JSON.stringify(options) : options) + ".");
}
} else { } else {
if (expected.hasOwnProperty(component)) { assert.sameValue(expected.hasOwnProperty(component), false,
$ERROR("Missing component " + component + "Missing component " + component +
" from expected subset " + JSON.stringify(expected) + " from expected subset " + JSON.stringify(expected) +
"; locales " + locales + ", options " + "; locales " + locales + ", options " +
(options ? JSON.stringify(options) : options) + "."); (options ? JSON.stringify(options) : options) + ".");
} }
}
}); });
}); });
} }
@ -50,13 +48,12 @@ function testWithToLocale(f, options, expected) {
var referenceFormat = new Intl.DateTimeFormat(locales, expected); var referenceFormat = new Intl.DateTimeFormat(locales, expected);
expectedStrings.push(referenceFormat.format(date)); expectedStrings.push(referenceFormat.format(date));
}); });
if (expectedStrings.indexOf(formatted) === -1) { assert.notSameValue(expectedStrings.indexOf(formatted), -1,
$ERROR("Function " + f + " did not return expected string for locales " + "Function " + f + " did not return expected string for locales " +
locales + ", options " + (options? JSON.stringify(options) : options) + locales + ", options " + (options? JSON.stringify(options) : options) +
"; expected " + "; expected " +
(expectedStrings.length === 1 ? expectedStrings[0] : "one of " + expectedStrings) + (expectedStrings.length === 1 ? expectedStrings[0] : "one of " + expectedStrings) +
", got " + formatted + "."); ", got " + formatted + ".");
}
}); });
}); });
} }

View File

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

View File

@ -30,18 +30,9 @@ locales.forEach(function (locale) {
keyValues[key].forEach(function (value) { keyValues[key].forEach(function (value) {
var dateTimeFormat = new Intl.DateTimeFormat([locale + "-u-" + key + "-" + value]); var dateTimeFormat = new Intl.DateTimeFormat([locale + "-u-" + key + "-" + value]);
var options = dateTimeFormat.resolvedOptions(); var options = dateTimeFormat.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 + "."); assert.sameValue(dateTimeFormat.format(input), defaultFormatted, "Formatted value " + dateTimeFormat.format(input) + " 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 !== dateTimeFormat.format(input)) {
$ERROR("Formatted value " + dateTimeFormat.format(input) + " is affected by key " +
key + "; value " + value + ".");
}
}); });
}); });
}); });

View File

@ -28,11 +28,10 @@ locales.forEach(function (locale) {
var actual = format.resolvedOptions(); var actual = format.resolvedOptions();
getDateTimeComponents().forEach(function (component) { getDateTimeComponents().forEach(function (component) {
if (actual.hasOwnProperty(component)) { if (actual.hasOwnProperty(component)) {
if (!subset.hasOwnProperty(component)) { assert(subset.hasOwnProperty(component),
$ERROR("Unrequested component " + component + "Unrequested component " + component +
" added to requested subset " + JSON.stringify(subset) + " added to requested subset " + JSON.stringify(subset) +
"; locale " + locale + "."); "; locale " + locale + ".");
}
try { try {
testValidDateTimeComponentValue(component, actual[component]); testValidDateTimeComponentValue(component, actual[component]);
} catch (e) { } catch (e) {
@ -41,12 +40,11 @@ locales.forEach(function (locale) {
throw e; throw e;
} }
} else { } else {
if (subset.hasOwnProperty(component)) { assert.sameValue(subset.hasOwnProperty(component), false,
$ERROR("Missing component " + component + "Missing component " + component +
" from requested subset " + JSON.stringify(subset) + " from requested subset " + JSON.stringify(subset) +
"; locale " + locale + "."); "; locale " + locale + ".");
} }
}
}); });
}); });
}); });

View File

@ -12,6 +12,4 @@ author: Norbert Lindenberg
var obj = new Intl.DateTimeFormat(); var obj = new Intl.DateTimeFormat();
var toStringValue = Object.prototype.toString.call(obj); var toStringValue = Object.prototype.toString.call(obj);
if (toStringValue !== "[object Object]") { assert.sameValue(toStringValue, "[object Object]", "Intl.DateTimeFormat instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
$ERROR("Intl.DateTimeFormat instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
}

View File

@ -15,8 +15,5 @@ var validTimeZoneNames = [
validTimeZoneNames.forEach(function (name) { validTimeZoneNames.forEach(function (name) {
// this must not throw an exception for a valid time zone name // this must not throw an exception for a valid time zone name
var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name}); var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name});
if (format.resolvedOptions().timeZone !== name.toUpperCase()) { assert.sameValue(format.resolvedOptions().timeZone, name.toUpperCase(), "Time zone name " + name + " was not correctly accepted.");
$ERROR("Time zone name " + name + " was not correctly accepted; turned into " +
format.resolvedOptions().timeZone + ".");
}
}); });

View File

@ -19,16 +19,8 @@ var invalidTimeZoneNames = [
]; ];
invalidTimeZoneNames.forEach(function (name) { invalidTimeZoneNames.forEach(function (name) {
var error;
try {
// this must throw an exception for an invalid time zone name // this must throw an exception for an invalid time zone name
assert.throws(RangeError, function() {
var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name}); var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name});
} catch (e) { }, "Invalid time zone name " + name + " was not rejected.");
error = e;
}
if (error === undefined) {
$ERROR("Invalid time zone name " + name + " was not rejected.");
} else if (error.name !== "RangeError") {
$ERROR("Invalid time zone name " + name + " was rejected with wrong error " + error.name + ".");
}
}); });

View File

@ -28,11 +28,8 @@ Object.getOwnPropertyNames(additionalTimeZoneNames).forEach(function (name) {
if (error === undefined) { if (error === undefined) {
var actual = format.resolvedOptions().timeZone; var actual = format.resolvedOptions().timeZone;
var expected = additionalTimeZoneNames[name]; var expected = additionalTimeZoneNames[name];
if (actual !== expected) { assert.sameValue(actual, expected, "Time zone name " + name + " was accepted, but incorrectly canonicalized.");
$ERROR("Time zone name " + name + " was accepted, but incorrectly canonicalized to " + } else {
actual + "; expected " + expected + "."); assert(error instanceof RangeError, "Time zone name " + name + " was rejected with wrong error " + error.name + ".");
}
} else if (error.name !== "RangeError") {
$ERROR("Time zone name " + name + " was rejected with wrong error " + error.name + ".");
} }
}); });

View File

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

View File

@ -11,7 +11,4 @@ author: Roozbeh Pournader
// 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.DateTimeFormat // initialized as an Intl.DateTimeFormat
if (typeof Intl.DateTimeFormat.prototype.format(0) !== "string") { assert.sameValue(typeof Intl.DateTimeFormat.prototype.format(0), "string", "Intl.DateTimeFormat's prototype is not an object that has been initialized as an Intl.DateTimeFormat");
$ERROR("Intl.DateTimeFormat's prototype is not an object that has been " +
"initialized as an Intl.DateTimeFormat");
}

View File

@ -19,16 +19,8 @@ var invalidTargets = [undefined, null, true, 0, "DateTimeFormat", [], {}];
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: Roozbeh Pournader author: Roozbeh Pournader
---*/ ---*/
if (Intl.DateTimeFormat.prototype.constructor !== Intl.DateTimeFormat) { assert.sameValue(Intl.DateTimeFormat.prototype.constructor, Intl.DateTimeFormat, "Intl.DateTimeFormat.prototype.constructor is not the same as Intl.DateTimeFormat");
$ERROR("Intl.DateTimeFormat.prototype.constructor is not the same as " +
"Intl.DateTimeFormat");
}

View File

@ -23,11 +23,7 @@ locales.forEach(function (locales) {
dates.forEach(function (date) { dates.forEach(function (date) {
var referenceFormatted = formatObj.format(date); var referenceFormatted = formatObj.format(date);
var formatted = formatFunc(date); var formatted = formatFunc(date);
if (referenceFormatted !== formatted) { assert.sameValue(referenceFormatted, formatted, "format function produces different result than format method for locales " + locales + "; options: " + (options ? JSON.stringify(options) : options) + ".");
$ERROR("format function produces different result than format method for locales " +
locales + "; options: " + (options ? JSON.stringify(options) : options) +
" : " + formatted + " vs. " + referenceFormatted + ".");
}
}); });
}); });
}); });

View File

@ -12,15 +12,7 @@ var invalidValues = [NaN, Infinity, -Infinity];
var format = new Intl.DateTimeFormat(); var format = new Intl.DateTimeFormat();
invalidValues.forEach(function (value) { invalidValues.forEach(function (value) {
var error; assert.throws(RangeError, function() {
try {
var result = format.format(value); var result = format.format(value);
} catch (e) { }, "Invalid value " + value + " was not rejected.");
error = e;
}
if (error === undefined) {
$ERROR("Invalid value " + value + " was not rejected.");
} else if (error.name !== "RangeError") {
$ERROR("Invalid value " + value + " was rejected with wrong error " + error.name + ".");
}
}); });

View File

@ -18,17 +18,12 @@ var dates = [
var format = new Intl.DateTimeFormat(["en-US"], {year: "numeric", month: "long", timeZone: "UTC"}); var format = new Intl.DateTimeFormat(["en-US"], {year: "numeric", month: "long", timeZone: "UTC"});
// this test requires a Gregorian calendar, which we usually find in the US // this test requires a Gregorian calendar, which we usually find in the US
if (format.resolvedOptions().calendar !== "gregory") { assert.sameValue(format.resolvedOptions().calendar, "gregory", "Internal error: Didn't find Gregorian calendar");
$ERROR("Internal error: Didn't find Gregorian calendar");
}
dates.forEach(function (date) { dates.forEach(function (date) {
var year = new Date(date).getUTCFullYear(); var year = new Date(date).getUTCFullYear();
var expectedYear = year <= 0 ? 1 - year : year; var expectedYear = year <= 0 ? 1 - year : year;
var expectedYearString = expectedYear.toLocaleString(["en-US"], {useGrouping: false}); var expectedYearString = expectedYear.toLocaleString(["en-US"], {useGrouping: false});
var dateString = format.format(date); var dateString = format.format(date);
if (dateString.indexOf(expectedYearString) === -1) { assert.notSameValue(dateString.indexOf(expectedYearString), -1, "Formatted year doesn't contain expected year expected " + expectedYearString + ", got " + dateString + ".");
$ERROR("Formatted year doesn't contain expected year expected " +
expectedYearString + ", got " + dateString + ".");
}
}); });

View File

@ -14,9 +14,7 @@ includes: [testIntl.js]
var actual = new Intl.DateTimeFormat().resolvedOptions(); var actual = new Intl.DateTimeFormat().resolvedOptions();
var actual2 = new Intl.DateTimeFormat().resolvedOptions(); var actual2 = new Intl.DateTimeFormat().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/calendar.xml; version CLDR 21. // source: CLDR file common/bcp47/calendar.xml; version CLDR 21.
var calendars = [ var calendars = [

View File

@ -15,15 +15,9 @@ var requestedLocales = [defaultLocale, notSupported];
var supportedLocales; var supportedLocales;
if (!Intl.DateTimeFormat.hasOwnProperty('supportedLocalesOf')) { assert(Intl.DateTimeFormat.hasOwnProperty('supportedLocalesOf'), "Intl.DateTimeFormat doesn't have a supportedLocalesOf property.");
$ERROR("Intl.DateTimeFormat doesn't have a supportedLocalesOf property.");
}
supportedLocales = Intl.DateTimeFormat.supportedLocalesOf(requestedLocales); supportedLocales = Intl.DateTimeFormat.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.');
}

View File

@ -7,6 +7,4 @@ description: Tests that Intl has Object.prototype as its prototype.
author: Norbert Lindenberg author: Norbert Lindenberg
---*/ ---*/
if (Object.getPrototypeOf(Intl) !== Object.prototype) { assert.sameValue(Object.getPrototypeOf(Intl), Object.prototype, "Intl doesn't have Object.prototype as its prototype.");
$ERROR("Intl doesn't have Object.prototype as its prototype.");
}

View File

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

View File

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

View File

@ -19,16 +19,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.NumberFormat.call(obj); newObj = Intl.NumberFormat.call(obj);
if (obj === newObj) { assert.notSameValue(obj, newObj, "NumberFormat object created with \"new\" was not ignored as this-value.");
$ERROR("NumberFormat 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.NumberFormat.call(obj); newObj = Intl.NumberFormat.call(obj);
if (obj === newObj) { assert.notSameValue(obj, newObj, "NumberFormat object created with constructor as function was not ignored as this-value.");
$ERROR("NumberFormat object created with constructor as function was not ignored as this-value.");
}
return true; return true;
}); });

View File

@ -19,63 +19,37 @@ validValues.forEach(function (value) {
format = new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value}); format = new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value});
actual = format.resolvedOptions().currency; actual = format.resolvedOptions().currency;
expected = value.toString().toUpperCase(); expected = value.toString().toUpperCase();
if (actual !== expected) { assert.sameValue(actual, expected, "Incorrect resolved currency with currency style.");
$ERROR("Incorrect resolved currency with currency style - expected " +
expected + "; got " + actual + ".");
}
// without currency style, we shouldn't get any currency back // without currency style, we shouldn't get any currency back
format = new Intl.NumberFormat([defaultLocale], {currency: value}); format = new Intl.NumberFormat([defaultLocale], {currency: value});
actual = format.resolvedOptions().currency; actual = format.resolvedOptions().currency;
expected = undefined; expected = undefined;
if (actual !== expected) { assert.sameValue(actual, expected, "Incorrect resolved currency with non-currency style.");
$ERROR("Incorrect resolved currency with non-currency style - expected " +
expected + "; got " + actual + ".");
}
// currencies specified through the locale must be ignored // currencies specified through the locale must be ignored
format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value}); format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value});
actual = format.resolvedOptions().currency; actual = format.resolvedOptions().currency;
expected = value.toString().toUpperCase(); expected = value.toString().toUpperCase();
if (actual !== expected) { assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and currency style.");
$ERROR("Incorrect resolved currency with -u-cu- and currency style - expected " +
expected + "; got " + actual + ".");
}
format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value}); format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value});
actual = format.resolvedOptions().currency; actual = format.resolvedOptions().currency;
expected = undefined; expected = undefined;
if (actual !== expected) { assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and non-currency style.");
$ERROR("Incorrect resolved currency with -u-cu- and non-currency style - expected " +
expected + "; got " + actual + ".");
}
}); });
invalidValues.forEach(function (value) { invalidValues.forEach(function (value) {
function expectError(f) { assert.throws(RangeError, function () {
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 () {
return new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value}); return new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value});
}); }, "Invalid currency value " + value + " was not rejected.");
expectError(function () { assert.throws(RangeError, function () {
return new Intl.NumberFormat([defaultLocale], {currency: value}); return new Intl.NumberFormat([defaultLocale], {currency: value});
}); }, "Invalid currency value " + value + " was not rejected.");
expectError(function () { assert.throws(RangeError, function () {
return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value}); return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value});
}); }, "Invalid currency value " + value + " was not rejected.");
expectError(function () { assert.throws(RangeError, function () {
return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value}); return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value});
}); }, "Invalid currency value " + value + " was not rejected.");
}); });

View File

@ -11,23 +11,10 @@ author: Norbert Lindenberg
var defaultLocale = new Intl.NumberFormat().resolvedOptions().locale; var defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
function expectError(f) { assert.throws(TypeError, function () {
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 () {
return new Intl.NumberFormat([defaultLocale], {style: "currency"}); return new Intl.NumberFormat([defaultLocale], {style: "currency"});
}); }, "Throws TypeError when currency code is not specified.");
expectError(function () {
assert.throws(TypeError, function () {
return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency"}); 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.");

View File

@ -183,12 +183,6 @@ Object.getOwnPropertyNames(currencyDigits).forEach(function (currency) {
var format = Intl.NumberFormat([], {style: "currency", currency: currency}); var format = Intl.NumberFormat([], {style: "currency", currency: currency});
var min = format.resolvedOptions().minimumFractionDigits; var min = format.resolvedOptions().minimumFractionDigits;
var max = format.resolvedOptions().maximumFractionDigits; var max = format.resolvedOptions().maximumFractionDigits;
if (min !== digits) { assert.sameValue(min, digits, "Didn't get correct minimumFractionDigits for currency " + currency + ".");
$ERROR("Didn't get correct minimumFractionDigits for currency " + assert.sameValue(max, digits, "Didn't get correct maximumFractionDigits for currency " + currency + ".");
currency + "; expected " + digits + ", got " + min + ".");
}
if (max !== digits) {
$ERROR("Didn't get correct maximumFractionDigits for currency " +
currency + "; expected " + digits + ", got " + max + ".");
}
}); });

View File

@ -13,6 +13,4 @@ includes: [testIntl.js]
taintProperties(["localeMatcher"]); taintProperties(["localeMatcher"]);
var locale = new Intl.NumberFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; var locale = new Intl.NumberFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { assert(isCanonicalizedStructurallyValidLanguageTag(locale), "NumberFormat returns invalid locale " + locale + ".");
$ERROR("NumberFormat returns invalid locale " + locale + ".");
}

View File

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

View File

@ -29,18 +29,9 @@ locales.forEach(function (locale) {
keyValues[key].forEach(function (value) { keyValues[key].forEach(function (value) {
var numberFormat = new Intl.NumberFormat([locale + "-u-" + key + "-" + value]); var numberFormat = new Intl.NumberFormat([locale + "-u-" + key + "-" + value]);
var options = numberFormat.resolvedOptions(); var options = numberFormat.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 + "."); assert.sameValue(numberFormat.format(input), defaultFormatted, "Formatted value " + numberFormat.format(input) + " 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 + ".");
}
}); });
}); });
}); });

View File

@ -12,6 +12,4 @@ author: Norbert Lindenberg
var obj = new Intl.NumberFormat(); var obj = new Intl.NumberFormat();
var toStringValue = Object.prototype.toString.call(obj); var toStringValue = Object.prototype.toString.call(obj);
if (toStringValue !== "[object Object]") { assert.sameValue(toStringValue, "[object Object]", "Intl.NumberFormat instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
$ERROR("Intl.NumberFormat instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
}

View File

@ -18,8 +18,5 @@ var wellFormedCurrencyCodes = [
wellFormedCurrencyCodes.forEach(function (code) { wellFormedCurrencyCodes.forEach(function (code) {
// this must not throw an exception for a valid currency code // this must not throw an exception for a valid currency code
var format = new Intl.NumberFormat(["de-de"], {style: "currency", currency: code}); var format = new Intl.NumberFormat(["de-de"], {style: "currency", currency: code});
if (format.resolvedOptions().currency !== code.toUpperCase()) { assert.sameValue(format.resolvedOptions().currency, code.toUpperCase(), "Currency " + code + " was not correctly accepted.");
$ERROR("Currency " + code + " was not correctly accepted; turned into " +
format.resolvedOptions().currency + ".");
}
}); });

View File

@ -20,16 +20,8 @@ var invalidCurrencyCodes = [
]; ];
invalidCurrencyCodes.forEach(function (code) { 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}); var format = new Intl.NumberFormat(["de-de"], {style: "currency", currency: code});
} catch (e) { }, "Invalid currency code '" + code + "' was not rejected.");
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 + ".");
}
}); });

View File

@ -8,15 +8,7 @@ author: Norbert Lindenberg
---*/ ---*/
var desc = Object.getOwnPropertyDescriptor(Intl.NumberFormat, "prototype"); var desc = Object.getOwnPropertyDescriptor(Intl.NumberFormat, "prototype");
if (desc === undefined) { assert.notSameValue(desc, undefined, "Intl.NumberFormat.prototype is not defined.");
$ERROR("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.");
if (desc.writable) { assert.sameValue(desc.configurable, false, "Intl.NumberFormat.prototype must not be configurable.");
$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.");
}

View File

@ -11,7 +11,4 @@ author: Roozbeh Pournader
// 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.NumberFormat // initialized as an Intl.NumberFormat
if (typeof Intl.NumberFormat.prototype.format(0) !== "string") { 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");
$ERROR("Intl.NumberFormat's prototype is not an object that has been " +
"initialized as an Intl.NumberFormat");
}

View File

@ -19,16 +19,8 @@ var invalidTargets = [undefined, null, true, 0, "NumberFormat", [], {}];
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: Roozbeh Pournader author: Roozbeh Pournader
---*/ ---*/
if (Intl.NumberFormat.prototype.constructor !== Intl.NumberFormat) { assert.sameValue(Intl.NumberFormat.prototype.constructor, Intl.NumberFormat, "Intl.NumberFormat.prototype.constructor is not the same as Intl.NumberFormat");
$ERROR("Intl.NumberFormat.prototype.constructor is not the same as " +
"Intl.NumberFormat");
}

View File

@ -20,9 +20,5 @@ for (i in testData) {
correctResult = formatter.format(number); correctResult = formatter.format(number);
result = formatter.format(input); result = formatter.format(input);
if (result !== correctResult) { assert.sameValue(result, correctResult, 'Intl.NumberFormat does not convert other types to numbers. Input: "' + input + '".');
$ERROR('Intl.NumberFormat does not convert other ' +
'types to numbers. Input: "'+input+'" Output: "'+result+'" '+
'Expected output: "'+correctResult+'"');
}
} }

View File

@ -30,11 +30,7 @@ locales.forEach(function (locales) {
numbers.forEach(function (number) { numbers.forEach(function (number) {
var referenceFormatted = formatObj.format(number); var referenceFormatted = formatObj.format(number);
var formatted = formatFunc(number); var formatted = formatFunc(number);
if (referenceFormatted !== formatted) { assert.sameValue(referenceFormatted, formatted, "format function produces different result than format method for locales " + locales + "; options: " + (options ? JSON.stringify(options) : options) + ".");
$ERROR("format function produces different result than format method for locales " +
locales + "; options: " + (options ? JSON.stringify(options) : options) +
" : " + formatted + " vs. " + referenceFormatted + ".");
}
}); });
}); });
}); });

View File

@ -11,10 +11,6 @@ author: Roozbeh Pournader
var formatter = new Intl.NumberFormat(); var formatter = new Intl.NumberFormat();
if (formatter.format(1) === formatter.format(-1)) { assert.notSameValue(formatter.format(1), formatter.format(-1), 'Intl.NumberFormat is formatting 1 and -1 the same way.');
$ERROR('Intl.NumberFormat is formatting 1 and -1 the same way.');
}
if (formatter.format(-0) !== formatter.format(0)) { assert.sameValue(formatter.format(-0), formatter.format(0), 'Intl.NumberFormat is formatting signed zeros differently.');
$ERROR('Intl.NumberFormat is formatting signed zeros differently.');
}

View File

@ -30,31 +30,14 @@ var formattedNaN = formatter.format(NaN);
var formattedInfinity = formatter.format(Infinity); var formattedInfinity = formatter.format(Infinity);
var formattedNegativeInfinity = formatter.format(-Infinity); var formattedNegativeInfinity = formatter.format(-Infinity);
if (formattedNaN === formattedInfinity) { assert.notSameValue(formattedNaN, formattedInfinity, 'Intl.NumberFormat formats NaN and Infinity the same way.');
$ERROR('Intl.NumberFormat formats NaN and Infinity the ' +
'same way.');
}
if (formattedNaN === formattedNegativeInfinity) { assert.notSameValue(formattedNaN, formattedNegativeInfinity, 'Intl.NumberFormat formats NaN and negative Infinity the same way.');
$ERROR('Intl.NumberFormat formats NaN and negative ' +
'Infinity the same way.');
}
if (formattedInfinity === formattedNegativeInfinity) { assert.notSameValue(formattedInfinity, formattedNegativeInfinity, 'Intl.NumberFormat formats Infinity and negative Infinity the same way.');
$ERROR('Intl.NumberFormat formats Infinity and ' +
'negative Infinity the same way.');
}
if (hasUnicodeDigits.test(formattedNaN)) { assert.sameValue(hasUnicodeDigits.test(formattedNaN), false, 'Intl.NumberFormat formats NaN using a digit.');
$ERROR('Intl.NumberFormat formats NaN using a digit.');
}
if (hasUnicodeDigits.test(formattedInfinity)) { assert.sameValue(hasUnicodeDigits.test(formattedInfinity), false, 'Intl.NumberFormat formats Infinity using a digit.');
$ERROR('Intl.NumberFormat formats Infinity using a ' +
'digit.');
}
if (hasUnicodeDigits.test(formattedNegativeInfinity)) { assert.sameValue(hasUnicodeDigits.test(formattedNegativeInfinity), false, 'Intl.NumberFormat formats negative Infinity using a digit.');
$ERROR('Intl.NumberFormat formats negative Infinity ' +
'using a digit.');
}

View File

@ -17,12 +17,7 @@ var formattedTwentyPercent = percentFormatter.format(0.20);
// FIXME: May not work for some theoretical locales where percents and // FIXME: May not work for some theoretical locales where percents and
// normal numbers are formatted using different numbering systems. // normal numbers are formatted using different numbering systems.
if (formattedTwentyPercent.indexOf(formattedTwenty) === -1) { assert.notSameValue(formattedTwentyPercent.indexOf(formattedTwenty), -1, "Intl.NumberFormat's formatting of 20% does not include a formatting of 20 as a substring.");
$ERROR("Intl.NumberFormat's formatting of 20% does not include a " +
"formatting of 20 as a substring.");
}
// FIXME: Move this to somewhere appropriate // FIXME: Move this to somewhere appropriate
if (percentFormatter.format(0.011) === percentFormatter.format(0.02)) { assert.notSameValue(percentFormatter.format(0.011), percentFormatter.format(0.02), 'Intl.NumberFormat is formatting 1.1% and 2% the same way.');
$ERROR('Intl.NumberFormat is formatting 1.1% and 2% the same way.');
}

View File

@ -14,9 +14,7 @@ includes: [testIntl.js]
var actual = new Intl.NumberFormat().resolvedOptions(); var actual = new Intl.NumberFormat().resolvedOptions();
var actual2 = new Intl.NumberFormat().resolvedOptions(); var actual2 = new Intl.NumberFormat().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.NumberFormat.hasOwnProperty('supportedLocalesOf')) { assert(Intl.NumberFormat.hasOwnProperty('supportedLocalesOf'), "Intl.NumberFormat doesn't have a supportedLocalesOf property.");
$ERROR("Intl.NumberFormat doesn't have a supportedLocalesOf property.");
}
supportedLocales = Intl.NumberFormat.supportedLocalesOf(requestedLocales); supportedLocales = Intl.NumberFormat.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.');
}

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.');
}
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.');
}

View File

@ -12,15 +12,7 @@ author: Norbert Lindenberg
var invalidValues = [undefined, null]; var invalidValues = [undefined, null];
invalidValues.forEach(function (value) { invalidValues.forEach(function (value) {
var error; assert.throws(TypeError, function() {
try {
var result = String.prototype.localeCompare.call(value, ""); var result = String.prototype.localeCompare.call(value, "");
} catch (e) { }, "String.prototype.localeCompare did not reject this = " + value + ".");
error = e;
}
if (error === undefined) {
$ERROR("String.prototype.localeCompare did not reject this = " + value + ".");
} else if (error.name !== "TypeError") {
$ERROR("String.prototype.localeCompare rejected this = " + value + " with wrong error " + error.name + ".");
}
}); });

View File

@ -15,12 +15,6 @@ for (i = 0; i < thisValues.length; i++) {
var j; var j;
for (j = 0; j < thatValues.length; j++) { for (j = 0; j < thatValues.length; j++) {
var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]); var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]);
if ((result === 0) !== (i === j)) { assert.sameValue((result === 0), (i === j), "localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as " + (result === 0 ? "equal" : "different") + ".");
if (result === 0) {
$ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as equal.");
} else {
$ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as different.");
}
}
} }
} }

View File

@ -15,12 +15,6 @@ for (i = 0; i < thisValues.length; i++) {
var j; var j;
for (j = 0; j < thatValues.length; j++) { for (j = 0; j < thatValues.length; j++) {
var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]); var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]);
if ((result === 0) !== (i === j)) { assert.sameValue((result === 0), (i === j), "localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as " + (result === 0 ? "equal" : "different") + ".");
if (result === 0) {
$ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as equal.");
} else {
$ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as different.");
}
}
} }
} }

View File

@ -14,10 +14,6 @@ var thisValues = ["a", "t", "u", "undefined", "UNDEFINED", "nicht definiert", "x
var i; var i;
for (i = 0; i < thisValues.length; i++) { for (i = 0; i < thisValues.length; i++) {
var thisValue = thisValues[i]; var thisValue = thisValues[i];
if (thisValue.localeCompare() !== thisValue.localeCompare(undefined)) { assert.sameValue(thisValue.localeCompare(), thisValue.localeCompare(undefined), "String.prototype.localeCompare does not treat missing 'that' argument as undefined.");
$ERROR("String.prototype.localeCompare does not treat missing 'that' argument as undefined."); assert.sameValue(thisValue.localeCompare(undefined), thisValue.localeCompare("undefined"), "String.prototype.localeCompare does not treat undefined 'that' argument as \"undefined\".");
}
if (thisValue.localeCompare(undefined) !== thisValue.localeCompare("undefined")) {
$ERROR("String.prototype.localeCompare does not treat undefined 'that' argument as \"undefined\".");
}
} }

View File

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