diff --git a/test/intl402/Locale/prototype/getTextInfo/language-subtag-with-more-than-three-letters.js b/test/intl402/Locale/prototype/getTextInfo/language-subtag-with-more-than-three-letters.js new file mode 100644 index 00000000000..0642f6a6af6 --- /dev/null +++ b/test/intl402/Locale/prototype/getTextInfo/language-subtag-with-more-than-three-letters.js @@ -0,0 +1,54 @@ +// Copyright 2026 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.getTextInfo +description: > + Language subtags with more than three letters are supported. +info: | + TextDirectionOfLocale ( loc ) + ... + 2. Let script be GetLocaleScript(locale). + 3. If script is undefined, then + a. Let maximal be the result of the Add Likely Subtags algorithm applied to locale. If an error is signaled, return undefined. + b. Set script to GetLocaleScript(maximal). + c. If script is undefined, return undefined. + 4. If the default general ordering of characters within a line in script is right-to-left, return "rtl". + 5. If the default general ordering of characters within a line in script is left-to-right, return "ltr". + 6. Return undefined. + + NOTE 1: + When the direction of default general ordering of characters within a line in + the script cannot be determined, or the direction is neither right-to-left nor + left-to-right, then undefined will be returned. +features: [Intl.Locale, Intl.Locale-info] +---*/ + +// "abcdefgh" is not a registered language, so it's not possible to infer its script +// through adding likely subtags. +assert.sameValue( + new Intl.Locale("abcdefgh").getTextInfo().direction, + undefined, + `with locale "abcdefgh"` +); + +// Script subtag is present, "Latn" is written left-to-right. +assert.sameValue( + new Intl.Locale("abcdefgh-Latn").getTextInfo().direction, + "ltr", + `with locale "abcdefgh-Latn"` +); + +// Script subtag is present, "Arab" is written right-to-left. +assert.sameValue( + new Intl.Locale("abcdefgh-Arab").getTextInfo().direction, + "rtl", + `with locale "abcdefgh-Arab"` +); + +// Script subtag is present, "Zzzz" is neither written left-to-right nor right-to-left. +assert.sameValue( + new Intl.Locale("abcdefgh-Zzzz").getTextInfo().direction, + undefined, + `with locale "abcdefgh-Zzzz"` +); diff --git a/test/intl402/Locale/prototype/getTextInfo/script-metadata-rtl-is-unknown.js b/test/intl402/Locale/prototype/getTextInfo/script-metadata-rtl-is-unknown.js new file mode 100644 index 00000000000..3c46e3fdf2c --- /dev/null +++ b/test/intl402/Locale/prototype/getTextInfo/script-metadata-rtl-is-unknown.js @@ -0,0 +1,57 @@ +// Copyright 2026 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.getTextInfo +description: > + Returns undefined if the RTL field in scriptMetadata.txt is UNKNOWN. +info: | + TextDirectionOfLocale ( loc ) + ... + 4. If the default general ordering of characters within a line in script is right-to-left, return "rtl". + 5. If the default general ordering of characters within a line in script is left-to-right, return "ltr". + 6. Return undefined. + + NOTE 1: + When the direction of default general ordering of characters within a line in + the script cannot be determined, or the direction is neither right-to-left nor + left-to-right, then undefined will be returned. +features: [Intl.Locale, Intl.Locale-info] +---*/ + +// All scripts whose RTL field in scriptMetadata.txt is UNKNOWN. +const scripts = [ + "Zyyy", + "Zinh", + "Zzzz", + "Brai", +]; + +const languages = [ + // Undetermined language. + "und", + + // English as a sample language whose default script is left-to-right. + "en", + + // Arabic as a sample language whose default script is right-to-left. + "ar", + + // Klingon as sample constructed language. + "tlh", + + // "qfz" as a CLDR private use, excluded language subtag. + "qfz", +]; + +for (let script of scripts) { + for (let language of languages) { + let locale = `${language}-${script}`; + + assert.sameValue( + new Intl.Locale(locale).getTextInfo().direction, + undefined, + `with locale "${locale}"` + ); + } +} diff --git a/test/intl402/Locale/prototype/getTextInfo/script-metadata-unlisted-language-script-is-rtl.js b/test/intl402/Locale/prototype/getTextInfo/script-metadata-unlisted-language-script-is-rtl.js new file mode 100644 index 00000000000..e306893055e --- /dev/null +++ b/test/intl402/Locale/prototype/getTextInfo/script-metadata-unlisted-language-script-is-rtl.js @@ -0,0 +1,30 @@ +// Copyright 2026 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.getTextInfo +description: > + Don't return "ltr" direction for scripts which aren't left-to-right. +info: | + TextDirectionOfLocale ( loc ) + ... + 4. If the default general ordering of characters within a line in script is right-to-left, return "rtl". + 5. If the default general ordering of characters within a line in script is left-to-right, return "ltr". + 6. Return undefined. + + NOTE 1: + When the direction of default general ordering of characters within a line in + the script cannot be determined, or the direction is neither right-to-left nor + left-to-right, then undefined will be returned. +features: [Intl.Locale, Intl.Locale-info] +---*/ + +// Arabic, spoken-only content. +var arDir = new Intl.Locale("ar-Zxxx").getTextInfo().direction; +// Allow absent data, returning undefined, but reject "ltr". +assert(arDir === "rtl" || arDir === undefined, "with locale 'ar-Zxxx'"); + +// Urdu, with script Arabic (Nastaliq variant). +var urDir = new Intl.Locale("ur-Aran").getTextInfo().direction; +// Allow absent data, returning undefined, but reject "ltr". +assert(urDir === "rtl" || urDir === undefined, "with locale 'ur-Aran'"); diff --git a/test/intl402/Locale/prototype/getTextInfo/script-subtag-missing.js b/test/intl402/Locale/prototype/getTextInfo/script-subtag-missing.js new file mode 100644 index 00000000000..e8350c774c2 --- /dev/null +++ b/test/intl402/Locale/prototype/getTextInfo/script-subtag-missing.js @@ -0,0 +1,68 @@ +// Copyright 2026 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.getTextInfo +description: > + Add likely subtags if the script subtag is missing. +info: | + TextDirectionOfLocale ( loc ) + ... + 2. Let script be GetLocaleScript(locale). + 3. If script is undefined, then + a. Let maximal be the result of the Add Likely Subtags algorithm applied to locale. If an error is signaled, return undefined. + b. Set script to GetLocaleScript(maximal). + c. If script is undefined, return undefined. + 4. If the default general ordering of characters within a line in script is right-to-left, return "rtl". + 5. If the default general ordering of characters within a line in script is left-to-right, return "ltr". + 6. Return undefined. + + NOTE 1: + When the direction of default general ordering of characters within a line in + the script cannot be determined, or the direction is neither right-to-left nor + left-to-right, then undefined will be returned. +features: [Intl.Locale, Intl.Locale-info] +---*/ + +const locales = [ + // Undetermined language. + "und", + + // English as a sample language whose default script is left-to-right. + "en", + + // Arabic as a sample language whose default script is right-to-left. + "ar", + + // Klingon as sample constructed language. + "tlh", + + // "qfz" as a CLDR private use, excluded language subtag. + "qfz", + + // Region subtag can alter likely subtags: "pa" maximizes to "pa-Guru-IN", + // whereas "pa-PK" maximizes to "pa-Arab-PK". (Gurmukhi is written + // left-to-right, Arabic is written right-to-left.) + "pa", + "pa-PK", +]; + +for (let locale of locales) { + let loc = new Intl.Locale(locale); + let maximized = loc.maximize(); + + let direction = loc.getTextInfo().direction; + assert.sameValue( + direction, + maximized.getTextInfo().direction, + `same direction as maximized locale, with locale "${locale}"` + ); + + if (maximized.script === undefined) { + assert.sameValue( + direction, + undefined, + `maximized script is undefined for locale "${locale}"` + ); + } +} diff --git a/test/intl402/Locale/prototype/getTextInfo/script-subtag-present.js b/test/intl402/Locale/prototype/getTextInfo/script-subtag-present.js new file mode 100644 index 00000000000..76f391ff9e8 --- /dev/null +++ b/test/intl402/Locale/prototype/getTextInfo/script-subtag-present.js @@ -0,0 +1,59 @@ +// Copyright 2026 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.getTextInfo +description: > + Determine text direction from script subtag, ignore the language subtag. +info: | + TextDirectionOfLocale ( loc ) + ... + 2. Let script be GetLocaleScript(locale). + ... + 4. If the default general ordering of characters within a line in script is right-to-left, return "rtl". + 5. If the default general ordering of characters within a line in script is left-to-right, return "ltr". + 6. Return undefined. + + NOTE 1: + When the direction of default general ordering of characters within a line in + the script cannot be determined, or the direction is neither right-to-left nor + left-to-right, then undefined will be returned. +features: [Intl.Locale, Intl.Locale-info] +---*/ + +const languages = [ + // Undetermined language. + "und", + + // English as a sample language whose default script is left-to-right. + "en", + + // Arabic as a sample language whose default script is right-to-left. + "ar", + + // Klingon as a sample constructed language. + "tlh", + + // "qfz" as a CLDR private use, excluded language subtag. + "qfz", +]; + +const scripts = { + // Latin script is written left-to-right. + Latn: "ltr", + + // Arabic script is written right-to-left. + Arab: "rtl", +}; + +for (let [script, direction] of Object.entries(scripts)) { + for (let language of languages) { + let locale = `${language}-${script}`; + + assert.sameValue( + new Intl.Locale(locale).getTextInfo().direction, + direction, + `with locale "${locale}"` + ); + } +} diff --git a/test/intl402/Locale/prototype/getTextInfo/script-unregistered-or-privateuse.js b/test/intl402/Locale/prototype/getTextInfo/script-unregistered-or-privateuse.js new file mode 100644 index 00000000000..49a3031d3bc --- /dev/null +++ b/test/intl402/Locale/prototype/getTextInfo/script-unregistered-or-privateuse.js @@ -0,0 +1,65 @@ +// Copyright 2026 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.getTextInfo +description: > + Returns undefined for unregistered and private-use script codes. +info: | + TextDirectionOfLocale ( loc ) + ... + 4. If the default general ordering of characters within a line in script is right-to-left, return "rtl". + 5. If the default general ordering of characters within a line in script is left-to-right, return "ltr". + 6. Return undefined. + + NOTE 1: + When the direction of default general ordering of characters within a line in + the script cannot be determined, or the direction is neither right-to-left nor + left-to-right, then undefined will be returned. +features: [Intl.Locale, Intl.Locale-info] +---*/ + +const scripts = [ + // "Aaaa" is not a registered script code. + // + // https://www.unicode.org/iso15924/iso15924-codes.html + "Aaaa", + + // Use the private use script code "Qaaq", because it's guaranteed to never + // get particular semantics in CLDR. + // + // https://unicode.org/reports/tr35/tr35.html#Private_Use_Codes + "Qaaq", + + // Exceptionally reserved by ISO 15924, will not be assigned for any purpose. + "True", +]; + +const languages = [ + // Undetermined language. + "und", + + // English as a sample language whose default script is left-to-right. + "en", + + // Arabic as a sample language whose default script is right-to-left. + "ar", + + // Klingon as a sample constructed language. + "tlh", + + // "qfz" as a CLDR private use, excluded language subtag. + "qfz", +]; + +for (let script of scripts) { + for (let language of languages) { + let locale = `${language}-${script}`; + + assert.sameValue( + new Intl.Locale(locale).getTextInfo().direction, + undefined, + `with locale "${locale}"` + ); + } +} diff --git a/test/intl402/Locale/prototype/maximize/language-subtag-with-more-than-three-letters.js b/test/intl402/Locale/prototype/maximize/language-subtag-with-more-than-three-letters.js new file mode 100644 index 00000000000..552242c3820 --- /dev/null +++ b/test/intl402/Locale/prototype/maximize/language-subtag-with-more-than-three-letters.js @@ -0,0 +1,24 @@ +// Copyright 2026 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Locale.prototype.maximize +description: > + Language subtags with more than three letters are supported. +info: | + Intl.Locale.prototype.maximize ( ) + + 1. Let loc be the this value. + 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). + 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set maximal to loc.[[Locale]]. + 4. Return ! Construct(%Intl.Locale%, « maximal »). +features: [Intl.Locale, Intl.Locale-info] +---*/ + +// "abcdefgh" is not a registered language, so it's not possible to infer its script +// through adding likely subtags. +assert.sameValue( + new Intl.Locale("abcdefgh").maximize().script, + undefined, + `can't infer script for locale "abcdefgh" by adding likely subtags` +);