Copy "invalid options" test from RelativeTimeFormat to NumberFormat/DateTimeFormat

The invalid 'numberingSystem' options test from RelativeTimeFormat covers a few
more cases, so let's reuse it for NumberFormat and DateTimeFormat.
While there, also add tests using non-ASCII inputs.

Fixes #2540
This commit is contained in:
André Bargull 2020-03-30 04:46:44 -07:00 committed by Rick Waldron
parent 299cd74ef2
commit ae8694b4b7
6 changed files with 123 additions and 53 deletions

View File

@ -0,0 +1,40 @@
// Copyright 2020 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializedatetimeformat
description: >
Checks error cases for the options argument to the DateTimeFormat constructor.
info: |
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
...
7. If calendar is not undefined, then
a. If calendar does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
---*/
/*
alphanum = (ALPHA / DIGIT) ; letters and numbers
numberingSystem = (3*8alphanum) *("-" (3*8alphanum))
*/
const invalidCalendarOptions = [
"",
"a",
"ab",
"abcdefghi",
"abc-abcdefghi",
"!invalid!",
"-gregory-",
"gregory-",
"gregory--",
"gregory-nu",
"gregory-nu-",
"gregory-nu-latn",
"gregoryé",
"gregory역법",
];
for (const calendar of invalidCalendarOptions) {
assert.throws(RangeError, function() {
new Intl.DateTimeFormat('en', {calendar});
}, `new Intl.DateTimeFormat("en", {calendar: "${calendar}"}) throws RangeError`);
}

View File

@ -0,0 +1,40 @@
// Copyright 2020 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializedatetimeformat
description: >
Checks error cases for the options argument to the DateTimeFormat constructor.
info: |
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
...
10. If numberingSystem is not undefined, then
a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
---*/
/*
alphanum = (ALPHA / DIGIT) ; letters and numbers
numberingSystem = (3*8alphanum) *("-" (3*8alphanum))
*/
const invalidNumberingSystemOptions = [
"",
"a",
"ab",
"abcdefghi",
"abc-abcdefghi",
"!invalid!",
"-latn-",
"latn-",
"latn--",
"latn-ca",
"latn-ca-",
"latn-ca-gregory",
"latné",
"latn编号",
];
for (const numberingSystem of invalidNumberingSystemOptions) {
assert.throws(RangeError, function() {
new Intl.DateTimeFormat('en', {numberingSystem});
}, `new Intl.DateTimeFormat("en", {numberingSystem: "${numberingSystem}"}) throws RangeError`);
}

View File

@ -1,30 +0,0 @@
// Copyright 2020 Google Inc, Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializedatetimeformat
description: >
Tests that invalid numberingSystem and calendar option throws RangeError.
author: Caio Lima
---*/
let invalidValues = ["ab", "aaaaaaaabbbbbababa."];
var defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
invalidValues.forEach(function (value) {
assert.throws(RangeError, function () {
return new Intl.DateTimeFormat([defaultLocale], {numberingSystem: value});
}, "Invalid numberingSystem value " + value + " was not rejected.");
assert.throws(RangeError, function () {
return new Intl.DateTimeFormat([defaultLocale + "-u-nu-" + value]);
}, "Invalid numberingSystem value " + value + " was not rejected.");
assert.throws(RangeError, function () {
return new Intl.DateTimeFormat([defaultLocale], {calendar: value});
}, "Invalid calendar value " + value + " was not rejected.");
assert.throws(RangeError, function () {
return new Intl.DateTimeFormat([defaultLocale + "-u-ca-" + value]);
}, "Invalid calendar value " + value + " was not rejected.");
});

View File

@ -0,0 +1,40 @@
// Copyright 2020 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: >
Checks error cases for the options argument to the NumberFormat constructor.
info: |
InitializeNumberFormat ( numberFormat, locales, options )
...
8. If numberingSystem is not undefined, then
a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
---*/
/*
alphanum = (ALPHA / DIGIT) ; letters and numbers
numberingSystem = (3*8alphanum) *("-" (3*8alphanum))
*/
const invalidNumberingSystemOptions = [
"",
"a",
"ab",
"abcdefghi",
"abc-abcdefghi",
"!invalid!",
"-latn-",
"latn-",
"latn--",
"latn-ca",
"latn-ca-",
"latn-ca-gregory",
"latné",
"latn编号",
];
for (const numberingSystem of invalidNumberingSystemOptions) {
assert.throws(RangeError, function() {
new Intl.NumberFormat('en', {numberingSystem});
}, `new Intl.NumberFormat("en", {numberingSystem: "${numberingSystem}"}) throws RangeError`);
}

View File

@ -1,22 +0,0 @@
// Copyright 2020 Google Inc, Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: >
Tests that invalid numberingSystem option throws RangeError.
author: Caio Lima
---*/
let invalidValues = ["ab", "aaaaaaaabbbbbababa."];
var defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
invalidValues.forEach(function (value) {
assert.throws(RangeError, function () {
return new Intl.NumberFormat([defaultLocale], {numberingSystem: value});
}, "Invalid numberingSystem value " + value + " was not rejected.");
assert.throws(RangeError, function () {
return new Intl.NumberFormat([defaultLocale + "-u-nu-" + value]);
}, "Invalid numberingSystem value " + value + " was not rejected.");
});

View File

@ -10,7 +10,7 @@ info: |
...
8. If numberingSystem is not undefined, then
a. If numberingSystem does not match the [(3*8alphanum) *("-" (3*8alphanum))] sequence, throw a RangeError exception.
a. If numberingSystem does not match the type sequence (from UTS 35 Unicode Locale Identifier, section 3.2), throw a RangeError exception.
features: [Intl.RelativeTimeFormat]
---*/
@ -34,6 +34,8 @@ const invalidNumberingSystemOptions = [
"latn-ca",
"latn-ca-",
"latn-ca-gregory",
"latné",
"latn编号",
];
for (const numberingSystem of invalidNumberingSystemOptions) {
assert.throws(RangeError, function() {