| 1 |
// Copyright 2020 Jeff Walden, Mozilla Corporation. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-isstructurallyvalidlanguagetag |
| 6 |
description: > |
| 7 |
Verifies that just as duplicate variants in a tag ("en-emodeng-emodeng") make |
| 8 |
the tag structurally invalid, so too do duplicate variants in the tlang |
| 9 |
component of an otherwise structurally valid tag ("de-t-emodeng-emodeng"), |
| 10 |
make it structurally invalid. |
| 11 |
info: | |
| 12 |
if a `transformed_extensions` component that contains a `tlang` component is |
| 13 |
present, then |
| 14 |
the `tlang` component contains no duplicate `unicode_variant_subtag` |
| 15 |
subtags. |
| 16 |
features: [Intl.Locale] |
| 17 |
---*/ |
| 18 |
|
| 19 |
assert.sameValue(typeof Intl.Locale, "function"); |
| 20 |
|
| 21 |
function mustReject(tag) { |
| 22 |
assert.throws(RangeError, () => { |
| 23 |
// Direct matches are rejected. |
| 24 |
new Intl.Locale(tag); |
| 25 |
}, `tag "${tag}" must be considered structurally invalid`); |
| 26 |
} |
| 27 |
|
| 28 |
// BCP47 since forever, and ECMA-402 as consequence, do not consider tags that |
| 29 |
// contain duplicate variants to be structurally valid. This restriction also |
| 30 |
// applies within the |tlang| component (indicating the source locale from which |
| 31 |
// relevant content was transformed) of a broader language tag. |
| 32 |
|
| 33 |
// Direct matches are rejected. |
| 34 |
mustReject("de-t-en-emodeng-emodeng"); |
| 35 |
// Case-insensitive matches are also rejected. |
| 36 |
mustReject("de-t-en-Emodeng-emodeng"); |
| 37 |
// ...and in either order. |
| 38 |
mustReject("de-t-en-emodeng-Emodeng"); |
| 39 |
|
| 40 |
// Repeat the above tests with additional variants interspersed at each point |
| 41 |
// for completeness. |
| 42 |
mustReject("de-t-en-variant-emodeng-emodeng"); |
| 43 |
mustReject("de-t-en-variant-Emodeng-emodeng"); |
| 44 |
mustReject("de-t-en-variant-emodeng-Emodeng"); |
| 45 |
mustReject("de-t-en-emodeng-variant-emodeng"); |
| 46 |
mustReject("de-t-en-Emodeng-variant-emodeng"); |
| 47 |
mustReject("de-t-en-emodeng-variant-Emodeng"); |
| 48 |
mustReject("de-t-en-emodeng-emodeng-variant"); |
| 49 |
mustReject("de-t-en-Emodeng-emodeng-variant"); |
| 50 |
mustReject("de-t-en-emodeng-Emodeng-variant"); |
| 51 |
|
| 52 |
reportCompare(0, 0); |