mirror of https://github.com/tc39/test262.git
Add Intl.PluralRules tests (#782)
* Add Intl.PluralRules tests * document the tests
This commit is contained in:
parent
c2eacd956e
commit
82c2ca0709
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules meets the requirements for
|
||||||
|
built-in objects defined by the introduction of chapter 17 of the
|
||||||
|
ECMAScript Language Specification.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testBuiltInObject.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.PluralRules, true, true, ["supportedLocalesOf"], 0);
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-intl-pluralrules-constructor
|
||||||
|
description: Tests that Intl.PluralRules can be subclassed.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testIntl.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// get a plural-rules and have it format an array of dates for comparison with the subclass
|
||||||
|
var locales = ["tlh", "id", "en"];
|
||||||
|
var a = [1, 5, 12];
|
||||||
|
|
||||||
|
var referencePluralRules = new Intl.PluralRules(locales);
|
||||||
|
var referenceSelected = a.map(referencePluralRules.select.bind(referencePluralRules));
|
||||||
|
|
||||||
|
class MyPluralRules extends Intl.PluralRules {
|
||||||
|
constructor(locales, options) {
|
||||||
|
super(locales, options);
|
||||||
|
// could initialize MyPluralRules properties
|
||||||
|
}
|
||||||
|
// could add methods to MyPluralRules.prototype
|
||||||
|
}
|
||||||
|
|
||||||
|
var pr = new MyPluralRules(locales);
|
||||||
|
var actual = a.map(pr.select.bind(pr));
|
||||||
|
testArraysAreSame(referenceSelected, actual);
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-intl-pluralrules-constructor
|
||||||
|
description: >
|
||||||
|
Tests that objects constructed by Intl.PluralRules have the specified
|
||||||
|
internal properties.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = new Intl.PluralRules();
|
||||||
|
|
||||||
|
var actualPrototype = Object.getPrototypeOf(obj);
|
||||||
|
if (actualPrototype !== Intl.PluralRules.prototype) {
|
||||||
|
$ERROR("Prototype of object constructed by Intl.PluralRules isn't Intl.PluralRules.prototype; got " + actualPrototype);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Object.isExtensible(obj)) {
|
||||||
|
$ERROR("Object constructed by Intl.PluralRules must be extensible.");
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules
|
||||||
|
description: Intl.PluralRules.length.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Intl.PluralRules.length, 0);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Intl.PluralRules, "length");
|
||||||
|
verifyNotWritable(Intl.PluralRules, "length");
|
||||||
|
verifyConfigurable(Intl.PluralRules, "length");
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules
|
||||||
|
description: Intl.PluralRules.name is "PluralRules"
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Intl.PluralRules.name, "PluralRules");
|
||||||
|
|
||||||
|
verifyNotEnumerable(Intl.PluralRules, "name");
|
||||||
|
verifyNotWritable(Intl.PluralRules, "name");
|
||||||
|
verifyConfigurable(Intl.PluralRules, "name");
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-properties-of-intl-pluralrules-prototype-object
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules.prototype functions throw a TypeError if
|
||||||
|
called on a non-object value or an object that hasn't been
|
||||||
|
initialized as a PluralRules.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var functions = {
|
||||||
|
select: Intl.PluralRules.prototype.select,
|
||||||
|
resolvedOptions: Intl.PluralRules.prototype.resolvedOptions
|
||||||
|
};
|
||||||
|
var invalidTargets = [undefined, null, true, 0, "PluralRules", [], {}];
|
||||||
|
|
||||||
|
Object.getOwnPropertyNames(functions).forEach(function (functionName) {
|
||||||
|
var f = functions[functionName];
|
||||||
|
invalidTargets.forEach(function (target) {
|
||||||
|
var error;
|
||||||
|
try {
|
||||||
|
f.call(target);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
if (error === undefined) {
|
||||||
|
$ERROR("Calling " + functionName + " on " + target + " was not rejected.");
|
||||||
|
} else if (error.name !== "TypeError") {
|
||||||
|
$ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + ".");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-properties-of-intl-pluralrules-prototype-object
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules.prototype meets the requirements for
|
||||||
|
built-in objects defined by the introduction of chapter 17 of the
|
||||||
|
ECMAScript Language Specification.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testBuiltInObject.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.PluralRules.prototype, false, false, ["constructor", "select", "resolvedOptions"]);
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.prototype.constructor
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules.prototype is an object that has been
|
||||||
|
initialized as an Intl.PluralRules.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
---*/
|
||||||
|
|
||||||
|
if (Intl.PluralRules.prototype.constructor !== Intl.PluralRules) {
|
||||||
|
$ERROR("Intl.PluralRules.prototype.constructor is not the same as " +
|
||||||
|
"Intl.PluralRules");
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-properties-of-intl-pluralrules-prototype-object
|
||||||
|
description: Tests that Intl.PluralRules.prototype has the required attributes.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(Intl.PluralRules, "prototype");
|
||||||
|
if (desc === undefined) {
|
||||||
|
$ERROR("Intl.PluralRules.prototype is not defined.");
|
||||||
|
}
|
||||||
|
if (desc.writable) {
|
||||||
|
$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.");
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-properties-of-intl-pluralrules-prototype-object
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules.prototype is an object that has been
|
||||||
|
initialized as an Intl.PluralRules.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// test by calling a function that would fail if "this" were not an object
|
||||||
|
// initialized as an Intl.PluralRules
|
||||||
|
if (typeof Intl.PluralRules.prototype.select(0) !== "string") {
|
||||||
|
$ERROR("Intl.PluralRules's prototype is not an object that has been " +
|
||||||
|
"initialized as an Intl.PluralRules");
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.prototype.resolvedOptions
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules.prototype.resolvedOptions meets the requirements for
|
||||||
|
built-in objects defined by the introduction of chapter 17 of the
|
||||||
|
ECMAScript Language Specification.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testBuiltInObject.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.PluralRules.prototype.resolvedOptions, true, false, [], 0);
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.resolvedOptions.name
|
||||||
|
description: Intl.PluralRules.resolvedOptions.name is "resolvedOptions"
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Intl.PluralRules.prototype.resolvedOptions.name, "resolvedOptions");
|
||||||
|
|
||||||
|
verifyNotEnumerable(Intl.PluralRules.prototype.resolvedOptions, "name");
|
||||||
|
verifyNotWritable(Intl.PluralRules.prototype.resolvedOptions, "name");
|
||||||
|
verifyConfigurable(Intl.PluralRules.prototype.resolvedOptions, "name");
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.prototype.resolvedOptions
|
||||||
|
description: >
|
||||||
|
Tests that the object returned by
|
||||||
|
Intl.PluralRules.prototype.resolvedOptions has the right
|
||||||
|
properties.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testIntl.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var actual = new Intl.PluralRules().resolvedOptions();
|
||||||
|
|
||||||
|
var actual2 = new Intl.PluralRules().resolvedOptions();
|
||||||
|
if (actual2 === actual) {
|
||||||
|
$ERROR("resolvedOptions returned the same object twice.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// this assumes the default values where the specification provides them
|
||||||
|
mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);
|
||||||
|
mustHaveProperty(actual, "type", ["cardinal"]);
|
||||||
|
mustNotHaveProperty(actual, "currency");
|
||||||
|
mustNotHaveProperty(actual, "currencyDisplay");
|
||||||
|
mustHaveProperty(actual, "minimumIntegerDigits", [1]);
|
||||||
|
mustHaveProperty(actual, "minimumFractionDigits", [0]);
|
||||||
|
mustHaveProperty(actual, "maximumFractionDigits", [3]);
|
||||||
|
mustNotHaveProperty(actual, "minimumSignificantDigits");
|
||||||
|
mustNotHaveProperty(actual, "maximumSignificantDigits");
|
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.prototype.select
|
||||||
|
description: Intl.PluralRules.prototype.select.name is "select"
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Intl.PluralRules.prototype.select.name, 'select',
|
||||||
|
'The value of `Intl.PluralRules.prototype.select.name` is `"select"`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Intl.PluralRules.prototype.select, 'name');
|
||||||
|
verifyNotWritable(Intl.PluralRules.prototype.select, 'name');
|
||||||
|
verifyConfigurable(Intl.PluralRules.prototype.select, 'name');
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.prototype.select
|
||||||
|
description: Tests that select function returns "other" for non finite values.
|
||||||
|
info:
|
||||||
|
1.1.4. ResolvePlural (pluralRules, n)
|
||||||
|
(...)
|
||||||
|
1.1.4_3. If isFinite(n) is false, then
|
||||||
|
1.1.4_3.a. Return "other".
|
||||||
|
author: Zibi Braniecki
|
||||||
|
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var invalidValues = [NaN, Infinity, -Infinity];
|
||||||
|
|
||||||
|
var pr = new Intl.PluralRules();
|
||||||
|
|
||||||
|
invalidValues.forEach(function (value) {
|
||||||
|
assert.sameValue(pr.select(value), "other");
|
||||||
|
});
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-intl-pluralrules-abstracts
|
||||||
|
description: >
|
||||||
|
Tests that the behavior of a Record is not affected by
|
||||||
|
adversarial changes to Object.prototype.
|
||||||
|
info:
|
||||||
|
1.1.1. InitializePluralRules (pluralRules, locales, options)
|
||||||
|
(...)
|
||||||
|
1.1.1_6. Let t be ? GetOption(options, "type", "string", « "cardinal", "ordinal" », "cardinal").
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testIntl.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
taintProperties(["type"]);
|
||||||
|
|
||||||
|
var pr = new Intl.PluralRules();
|
||||||
|
var time = pr.select(9);
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.supportedLocalesOf
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules.supportedLocalesOf doesn't access
|
||||||
|
arguments that it's not given.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testIntl.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
taintDataProperty(Object.prototype, "1");
|
||||||
|
new Intl.PluralRules("und");
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.supportedLocalesOf
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules has a supportedLocalesOf property, and
|
||||||
|
it works as planned.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var defaultLocale = new Intl.PluralRules().resolvedOptions().locale;
|
||||||
|
var notSupported = 'zxx'; // "no linguistic content"
|
||||||
|
var requestedLocales = [defaultLocale, notSupported];
|
||||||
|
|
||||||
|
var supportedLocales;
|
||||||
|
|
||||||
|
if (!Intl.PluralRules.hasOwnProperty('supportedLocalesOf')) {
|
||||||
|
$ERROR("Intl.PluralRules doesn't have a supportedLocalesOf property.");
|
||||||
|
}
|
||||||
|
|
||||||
|
supportedLocales = Intl.PluralRules.supportedLocalesOf(requestedLocales);
|
||||||
|
if (supportedLocales.length !== 1) {
|
||||||
|
$ERROR('The length of supported locales list is not 1.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (supportedLocales[0] !== defaultLocale) {
|
||||||
|
$ERROR('The default locale is not returned in the supported list.');
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.supportedLocalesOf
|
||||||
|
description: Tests that Intl.PluralRules.supportedLocalesOf.name is "supportedLocalesOf"
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
assert.sameValue(Intl.PluralRules.supportedLocalesOf.name, "supportedLocalesOf");
|
||||||
|
|
||||||
|
verifyNotEnumerable(Intl.PluralRules.supportedLocalesOf, "name");
|
||||||
|
verifyNotWritable(Intl.PluralRules.supportedLocalesOf, "name");
|
||||||
|
verifyConfigurable(Intl.PluralRules.supportedLocalesOf, "name");
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules.supportedLocalesOf
|
||||||
|
description: >
|
||||||
|
Tests that Intl.PluralRules.supportedLocalesOf meets the requirements for
|
||||||
|
built-in objects defined by the introduction of chapter 17 of the
|
||||||
|
ECMAScript Language Specification.
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testBuiltInObject.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.PluralRules.supportedLocalesOf, true, false, [], 1);
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright 2016 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.PluralRules
|
||||||
|
description: Tests that the this-value is ignored in PluralRules
|
||||||
|
author: Zibi Braniecki
|
||||||
|
includes: [testIntl.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithIntlConstructors(function (Constructor) {
|
||||||
|
var obj, newObj;
|
||||||
|
|
||||||
|
// variant 1: use constructor in a "new" expression
|
||||||
|
obj = new Constructor();
|
||||||
|
newObj = Intl.PluralRules.call(obj);
|
||||||
|
if (obj === newObj) {
|
||||||
|
$ERROR("PluralRules object created with \"new\" was not ignored as this-value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// variant 2: use constructor as a function
|
||||||
|
obj = Constructor();
|
||||||
|
newObj = Intl.PluralRules.call(obj);
|
||||||
|
if (obj === newObj) {
|
||||||
|
$ERROR("PluralRules object created with constructor as function was not ignored as this-value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
Loading…
Reference in New Issue