this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Unit test for locale-match

Tests are copied from original sources

+279 -1
+4 -1
src/utils/mem.js
··· 1 1 import moize from 'moize'; 2 2 3 - window._moize = moize; 3 + // Only assign to window if in browser environment 4 + if (typeof window !== 'undefined') { 5 + window._moize = moize; 6 + } 4 7 5 8 export default function mem(fn, opts = {}) { 6 9 return moize(fn, {
+275
tests/locale-match.spec.js
··· 1 + // @ts-check 2 + import { test, expect } from '@playwright/test'; 3 + import localeMatch from '../src/utils/locale-match.js'; 4 + 5 + // https://github.com/formatjs/formatjs/blob/e11b9b57a5ed745584b169c13b0a1812ba9e6051/packages/intl-localematcher/tests/index.test.ts 6 + test.describe('official formatjs test cases', () => { 7 + test('zh-HK', () => { 8 + expect(localeMatch(['zh-HK'], ['zh', 'zh-HANT', 'en'], 'en')).toBe( 9 + 'zh-HANT', 10 + ); 11 + }); 12 + 13 + test('Intl.LocaleMatcher - fr-XX fallback', () => { 14 + expect(localeMatch(['fr-XX', 'en'], ['fr', 'en'], 'en')).toBe('fr'); 15 + }); 16 + 17 + test('Intl.LocaleMatcher - zh-TW to zh-Hant-TW', () => { 18 + expect(localeMatch(['zh-TW', 'en'], ['zh-Hant-TW', 'en'], 'en')).toBe( 19 + 'zh-Hant-TW', 20 + ); 21 + }); 22 + 23 + test('Intl.LocaleMatcher - sr-Latn-BA complex matching', () => { 24 + expect( 25 + localeMatch( 26 + ['sr-Latn-BA'], 27 + [ 28 + 'af', 29 + 'ak', 30 + 'am', 31 + 'an', 32 + 'ar', 33 + 'ars', 34 + 'as', 35 + 'asa', 36 + 'ast', 37 + 'az', 38 + 'be', 39 + 'bem', 40 + 'bez', 41 + 'bg', 42 + 'bho', 43 + 'bm', 44 + 'bn', 45 + 'bo', 46 + 'br', 47 + 'brx', 48 + 'bs', 49 + 'ca', 50 + 'ce', 51 + 'ceb', 52 + 'cgg', 53 + 'chr', 54 + 'ckb', 55 + 'cs', 56 + 'cy', 57 + 'da', 58 + 'de', 59 + 'doi', 60 + 'dsb', 61 + 'dv', 62 + 'dz', 63 + 'ee', 64 + 'el', 65 + 'en', 66 + 'eo', 67 + 'es', 68 + 'et', 69 + 'eu', 70 + 'fa', 71 + 'ff', 72 + 'fi', 73 + 'fil', 74 + 'fo', 75 + 'fr', 76 + 'fur', 77 + 'fy', 78 + 'ga', 79 + 'gd', 80 + 'gl', 81 + 'gsw', 82 + 'gu', 83 + 'guw', 84 + 'gv', 85 + 'ha', 86 + 'haw', 87 + 'he', 88 + 'ksb', 89 + 'ksh', 90 + 'ku', 91 + 'kw', 92 + 'ky', 93 + 'lag', 94 + 'lb', 95 + 'lg', 96 + 'lij', 97 + 'lkt', 98 + 'ln', 99 + 'lo', 100 + 'lt', 101 + 'lv', 102 + 'mas', 103 + 'mg', 104 + 'mgo', 105 + 'mk', 106 + 'ml', 107 + 'mn', 108 + 'mo', 109 + 'mr', 110 + 'ms', 111 + 'mt', 112 + 'my', 113 + 'nah', 114 + 'naq', 115 + 'nb', 116 + 'nd', 117 + 'ne', 118 + 'nl', 119 + 'nn', 120 + 'nnh', 121 + 'no', 122 + 'nqo', 123 + 'nr', 124 + 'nso', 125 + 'ny', 126 + 'nyn', 127 + 'om', 128 + 'or', 129 + 'os', 130 + 'osa', 131 + 'pa', 132 + 'pap', 133 + 'pcm', 134 + 'pl', 135 + 'prg', 136 + 'ps', 137 + 'pt-PT', 138 + 'pt', 139 + 'rm', 140 + 'ro', 141 + 'rof', 142 + 'ru', 143 + 'rwk', 144 + 'sah', 145 + 'saq', 146 + 'sat', 147 + 'sc', 148 + 'scn', 149 + 'sd', 150 + 'sdh', 151 + 'se', 152 + 'seh', 153 + 'ses', 154 + 'sg', 155 + 'sh', 156 + 'shi', 157 + 'si', 158 + 'sk', 159 + 'sl', 160 + 'sma', 161 + 'smi', 162 + 'smj', 163 + 'smn', 164 + 'sms', 165 + 'sn', 166 + 'so', 167 + 'sq', 168 + 'sr', 169 + 'ss', 170 + 'ssy', 171 + 'st', 172 + 'su', 173 + 'sv', 174 + 'sw', 175 + 'syr', 176 + 'ta', 177 + 'te', 178 + 'teo', 179 + 'th', 180 + 'ti', 181 + 'tig', 182 + 'tk', 183 + 'tl', 184 + 'tn', 185 + 'to', 186 + 'tr', 187 + 'ts', 188 + 'tzm', 189 + 'ug', 190 + 'uk', 191 + 'ur', 192 + 'uz', 193 + 've', 194 + 'vi', 195 + 'vo', 196 + 'vun', 197 + 'wa', 198 + 'wae', 199 + 'wo', 200 + 'xh', 201 + 'xog', 202 + 'yi', 203 + 'yo', 204 + 'yue', 205 + 'zh', 206 + 'zu', 207 + ], 208 + 'en', 209 + ), 210 + ).toBe('sh'); 211 + }); 212 + 213 + test('empty requested', () => { 214 + expect(localeMatch([], ['zh-Hant-TW', 'en'], 'en')).toBe('en'); 215 + }); 216 + 217 + test('extension', () => { 218 + expect(localeMatch(['fr-CA-x-foo'], ['zh-Hant-TW', 'fr', 'en'], 'en')).toBe( 219 + 'fr', 220 + ); 221 + }); 222 + 223 + test('GH #4267', () => { 224 + expect(localeMatch(['fr'], ['br', 'fr'], 'en')).toBe('fr'); 225 + }); 226 + }); 227 + 228 + // https://github.com/formatjs/formatjs/blob/e11b9b57a5ed745584b169c13b0a1812ba9e6051/packages/intl-localematcher/tests/BestFitMatcher.test.ts 229 + test.describe('BestFitMatcher test cases', () => { 230 + test('BestFitMatcher basic', () => { 231 + expect(localeMatch(['fr-XX', 'en'], ['fr', 'en'], 'en')).toBe('fr'); 232 + }); 233 + 234 + test('BestFitMatcher zh-TW', () => { 235 + expect(localeMatch(['zh-TW'], ['zh', 'zh-Hant'], 'en')).toBe('zh-Hant'); 236 + }); 237 + 238 + test('BestFitMatcher en', () => { 239 + expect(localeMatch(['en'], ['en', 'und'], 'en')).toBe('en'); 240 + }); 241 + 242 + test('BestFitMatcher extension', () => { 243 + // Extensions should be handled transparently by the underlying matcher 244 + expect(localeMatch(['th-u-ca-gregory'], ['th'], 'en')).toBe('th'); 245 + }); 246 + 247 + test('GH #4272 - fallback behavior', () => { 248 + expect(localeMatch(['es'], ['fr', 'en'], 'en')).toBe('en'); 249 + expect(localeMatch(['es'], ['en', 'fr', 'en'], 'fr')).toBe('fr'); 250 + }); 251 + 252 + test('GH #4258 - best fit matching', () => { 253 + expect( 254 + localeMatch(['de-DE', 'fr'], ['en', 'en-US', 'fr-FR'], 'en-US'), 255 + ).toBe('fr-FR'); 256 + }); 257 + 258 + test('GH #4237 - exact locale preference', () => { 259 + expect( 260 + localeMatch(['en-GB', 'en-US', 'en'], ['en-US', 'nl-NL', 'nl'], 'en-US'), 261 + ).toBe('en-US'); 262 + }); 263 + 264 + test('bestFitMatcher testing zh-HK', () => { 265 + expect(localeMatch(['zh-HK'], ['zh-Hant', 'zh-MO'], 'en')).toBe('zh-MO'); 266 + }); 267 + 268 + test('bestFitMatcher testing en-CA', () => { 269 + expect(localeMatch(['en-CA'], ['en-GB', 'en-US'], 'en-US')).toBe('en-US'); 270 + }); 271 + 272 + test('bestFitMatcher testing es-KY Americas', () => { 273 + expect(localeMatch(['es-KY'], ['es', 'en', 'es-419'], 'en')).toBe('es-419'); 274 + }); 275 + });