Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage for Intl.DisplayNames.prototype.of() #3901

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
71 changes: 71 additions & 0 deletions test/intl402/DisplayNames/prototype/of/type-currency-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2023 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DisplayNames.prototype.of
description: Throws a RangeError for invalid `currency` codes
info: |
12.5.1 CanonicalCodeForDisplayNames ( type, code )

...
6. Assert: type is "currency".
7. If ! IsWellFormedCurrencyCode(code) is false, throw a RangeError exception.
8. Return the ASCII-uppercase of code.

IsWellFormedCurrencyCode ( code )
1. If the length of currency is not 3, return false.
2. Let normalized be the ASCII-uppercase of currency.
3. If normalized contains any code unit outside of 0x0041 through 0x005A (corresponding to Unicode characters LATIN CAPITAL LETTER A through LATIN CAPITAL LETTER Z), return false.
4. Return true.
features: [Intl.DisplayNames]
---*/

var displayNames = new Intl.DisplayNames(undefined, {type: 'currency'});

assert.throws(RangeError, function() {
displayNames.of('aa');
}, 'insufficient length');

assert.throws(RangeError, function() {
displayNames.of('aaaa');
}, 'excessive length');

assert.throws(RangeError, function() {
displayNames.of('aa1');
}, 'contains number');

assert.throws(RangeError, function() {
displayNames.of('aa@');
}, 'contains non-alphanumeric');

assert.throws(RangeError, function() {
displayNames.of('');
}, 'empty string');

assert.throws(RangeError, function() {
displayNames.of('aaa-');
}, 'trailing separator (dash)');

assert.throws(RangeError, function() {
displayNames.of('-aaa');
}, 'leading separator (dash)');

assert.throws(RangeError, function() {
displayNames.of('_aaa');
}, 'leading separator (underscore)');

assert.throws(RangeError, function() {
displayNames.of('aaa_');
}, 'trailing separator (underscore)');


assert.throws(RangeError, function() {
displayNames.of(' aaa');
}, 'leading space');

assert.throws(RangeError, function() {
displayNames.of('aaa ');
}, 'trailing space');

assert.throws(RangeError, function() {
displayNames.of('ab c');
}, 'interstitial space');
32 changes: 32 additions & 0 deletions test/intl402/DisplayNames/prototype/of/type-currency-valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DisplayNames.prototype.of
description: Returns string value for valid `currency` codes
info: |
12.5.1 CanonicalCodeForDisplayNames ( type, code )

...
6. Assert: type is "currency".
7. If ! IsWellFormedCurrencyCode(code) is false, throw a RangeError exception.
8. Return the ASCII-uppercase of code.

IsWellFormedCurrencyCode ( code )

1. If the length of currency is not 3, return false.
2. Let normalized be the ASCII-uppercase of currency.
3. If normalized contains any code unit outside of 0x0041 through 0x005A (corresponding to Unicode characters LATIN CAPITAL LETTER A through LATIN CAPITAL LETTER Z), return false.
4. Return true.
features: [Intl.DisplayNames]
---*/

var displayNames = new Intl.DisplayNames(undefined, {type: 'currency'});

assert.sameValue(typeof displayNames.of('aaa'), 'string', 'aaa');
assert.sameValue(typeof displayNames.of('nnn'), 'string', 'nnn');
assert.sameValue(typeof displayNames.of('MMM'), 'string', 'MMM');
assert.sameValue(typeof displayNames.of('ZZZ'), 'string', 'ZZZ');
assert.sameValue(typeof displayNames.of('Bbb'), 'string', 'Bbb');
assert.sameValue(typeof displayNames.of('Ooo'), 'string', 'Ooo');
assert.sameValue(typeof displayNames.of('gGg'), 'string', 'gGg');
assert.sameValue(typeof displayNames.of('tTT'), 'string', 'tTT');
80 changes: 80 additions & 0 deletions test/intl402/DisplayNames/prototype/of/type-region-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2023 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DisplayNames.prototype.of
description: Throws a RangeError for invalid `region` codes
info: |
12.5.1 CanonicalCodeForDisplayNames ( type, code )

...
2. If type is "region", then
a. If code cannot be matched by the unicode_region_subtag Unicode locale nonterminal, throw a RangeError exception.
b. Return the ASCII-uppercase of code.
features: [Intl.DisplayNames]
---*/

var displayNames = new Intl.DisplayNames(undefined, {type: 'region'});

assert.throws(RangeError, function() {
displayNames.of('00');
}, 'insufficient length, numeric');

assert.throws(RangeError, function() {
displayNames.of('a');
}, 'insufficient length, alpha');

assert.throws(RangeError, function() {
displayNames.of('aaa');
}, 'excessive length, alpha');

assert.throws(RangeError, function() {
displayNames.of('1111');
}, 'excessive length, numeric');

assert.throws(RangeError, function() {
displayNames.of('');
}, 'empty string');

assert.throws(RangeError, function() {
displayNames.of('a01');
}, 'mixed alphanumeric (alpha first, length 3)');

assert.throws(RangeError, function() {
displayNames.of('a1');
}, 'mixed alphanumeric (alpha first, length 2)');

assert.throws(RangeError, function() {
displayNames.of('1a');
}, 'mixed alphanumeric (numeric first, length 2)');

assert.throws(RangeError, function() {
displayNames.of('1a1');
}, 'mixed alphanumeric (numeric first, length 3)');

assert.throws(RangeError, function() {
displayNames.of('-111');
}, 'leading separator (dash)');

assert.throws(RangeError, function() {
displayNames.of('_111');
}, 'leading separator (underscore)');

assert.throws(RangeError, function() {
displayNames.of('111-');
}, 'trailing separator (dash)');

assert.throws(RangeError, function() {
displayNames.of('111_');
}, 'trailing separator (underscore)');

assert.throws(RangeError, function() {
displayNames.of(' aa');
}, 'leading space');

assert.throws(RangeError, function() {
displayNames.of('aa ');
}, 'trailing space');

assert.throws(RangeError, function() {
displayNames.of('a c');
}, 'interstitial space');
20 changes: 20 additions & 0 deletions test/intl402/DisplayNames/prototype/of/type-region-valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DisplayNames.prototype.of
description: Returns string value for valid `region` codes
info: |
12.5.1 CanonicalCodeForDisplayNames ( type, code )

...
2. If type is "region", then
a. If code cannot be matched by the unicode_region_subtag Unicode locale nonterminal, throw a RangeError exception.
b. Return the ASCII-uppercase of code.
features: [Intl.DisplayNames]
---*/

var displayNames = new Intl.DisplayNames(undefined, {type: 'region'});

assert.sameValue(typeof displayNames.of('aa'), 'string', 'aa');
assert.sameValue(typeof displayNames.of('AA'), 'string', 'ZZ');
assert.sameValue(typeof displayNames.of('000'), 'string', '000');
59 changes: 59 additions & 0 deletions test/intl402/DisplayNames/prototype/of/type-script-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DisplayNames.prototype.of
description: Throws a RangeError for invalid `script` codes
info: |
12.5.1 CanonicalCodeForDisplayNames ( type, code )
...
3. If type is "script", then
a. If code cannot be matched by the unicode_script_subtag Unicode locale nonterminal, throw a RangeError exception.
b. Assert: The length of code is 4, and every code unit of code represents an ASCII letter (0x0041 through 0x005A and 0x0061 through 0x007A, both inclusive).
c. Let first be the ASCII-uppercase of the substring of code from 0 to 1.
d. Let rest be the ASCII-lowercase of the substring of code from 1.
e. Return the string-concatenation of first and rest.
b. Return the ASCII-uppercase of code.
features: [Intl.DisplayNames]
---*/

var displayNames = new Intl.DisplayNames(undefined, {type: 'script'});

assert.throws(RangeError, function() {
displayNames.of('aaa');
}, 'insufficient length');

assert.throws(RangeError, function() {
displayNames.of('aaaaa');
}, 'excessive length');

assert.throws(RangeError, function() {
displayNames.of('a10a');
}, 'contains digits');

assert.throws(RangeError, function() {
displayNames.of('a@aa');
}, 'contains non-alphanumeric characters');

assert.throws(RangeError, function() {
displayNames.of('-aaaa');
}, 'leading separator, -');

assert.throws(RangeError, function() {
displayNames.of('aaaa-');
}, 'trailing separator (dash)');

assert.throws(RangeError, function() {
displayNames.of('_aaaa');
}, 'leading separator (underscore)');

assert.throws(RangeError, function() {
displayNames.of('aaaa_');
}, 'trailing separator (underscore)');

assert.throws(RangeError, function() {
displayNames.of('aa a');
}, 'contains space');

assert.throws(RangeError, function() {
displayNames.of('');
}, 'empty string');
27 changes: 27 additions & 0 deletions test/intl402/DisplayNames/prototype/of/type-script-valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DisplayNames.prototype.of
description: Returns string value for valid `script` codes
info: |
12.5.1 CanonicalCodeForDisplayNames ( type, code )

...
3. If type is "script", then
a. If code cannot be matched by the unicode_script_subtag Unicode locale nonterminal, throw a RangeError exception.
b. Assert: The length of code is 4, and every code unit of code represents an ASCII letter (0x0041 through 0x005A and 0x0061 through 0x007A, both inclusive).
c. Let first be the ASCII-uppercase of the substring of code from 0 to 1.
d. Let rest be the ASCII-lowercase of the substring of code from 1.
e. Return the string-concatenation of first and rest.
b. Return the ASCII-uppercase of code.
features: [Intl.DisplayNames]
---*/

var displayNames = new Intl.DisplayNames(undefined, {type: 'script'});

assert.sameValue(typeof displayNames.of('aaaa'), 'string', 'aaaa');
assert.sameValue(typeof displayNames.of('AAAA'), 'string', 'AAAA');
assert.sameValue(typeof displayNames.of('Aaaa'), 'string', 'Aaaa');
assert.sameValue(typeof displayNames.of('aAAa'), 'string', 'aAAa');
assert.sameValue(typeof displayNames.of('Aaaa'), 'string', 'Aaaa');