| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
*/ |
| 4 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 7 |
|
| 8 |
#include "js/LocaleSensitive.h" |
| 9 |
#include "jsapi-tests/tests.h" |
| 10 |
|
| 11 |
BEGIN_TEST(testIntlAvailableLocales) { |
| 12 |
JSRuntime* rt = JS_GetRuntime(cx); |
| 13 |
|
| 14 |
// This test should only attempt to run if we have Intl support. |
| 15 |
JS::Rooted<JS::Value> haveIntl(cx); |
| 16 |
EVAL("typeof Intl !== 'undefined'", &haveIntl); |
| 17 |
if (!haveIntl.toBoolean()) { |
| 18 |
return true; |
| 19 |
} |
| 20 |
|
| 21 |
// Assumption: our Intl support always includes "az" (Azerbaijani) support, |
| 22 |
// and our Intl support *does not* natively support az-Cyrl-AZ. |
| 23 |
CHECK(JS_SetDefaultLocale(rt, "az-Cyrl-AZ")); |
| 24 |
|
| 25 |
EXEC( |
| 26 |
"if (Intl.Collator().resolvedOptions().locale !== " |
| 27 |
"'az-Cyrl-AZ') \n" |
| 28 |
" throw 'unexpected default locale';"); |
| 29 |
EXEC( |
| 30 |
"var used = Intl.Collator('az-Cyrl').resolvedOptions().locale; \n" |
| 31 |
"if (used !== 'az-Cyrl') \n" |
| 32 |
" throw 'bad locale when using truncated default: ' + used;"); |
| 33 |
EXEC( |
| 34 |
"if (Intl.Collator('az').resolvedOptions().locale !== 'az') \n" |
| 35 |
" throw 'bad locale when using more-truncated default';"); |
| 36 |
EXEC( |
| 37 |
"if (Intl.Collator('az-Cyrl-US').resolvedOptions().locale !== 'az-Cyrl') " |
| 38 |
"\n" |
| 39 |
" throw 'unexpected default locale';"); |
| 40 |
|
| 41 |
EXEC( |
| 42 |
"if (Intl.Collator('az-Cyrl-AZ', { localeMatcher: 'lookup' " |
| 43 |
"}).resolvedOptions().locale !== \n" |
| 44 |
" 'az-Cyrl-AZ') \n" |
| 45 |
"{ \n" |
| 46 |
" throw 'unexpected default locale with lookup matcher'; \n" |
| 47 |
"}"); |
| 48 |
|
| 49 |
CHECK(JS_SetDefaultLocale(rt, "en-US-u-co-phonebk")); |
| 50 |
EXEC( |
| 51 |
"if (Intl.Collator().resolvedOptions().locale !== 'en-US') \n" |
| 52 |
" throw 'unexpected default locale where proposed default included a " |
| 53 |
"Unicode extension';"); |
| 54 |
|
| 55 |
CHECK(JS_SetDefaultLocale(rt, "this is not a language tag at all, yo")); |
| 56 |
|
| 57 |
EXEC( |
| 58 |
"if (Intl.Collator().resolvedOptions().locale !== 'en-GB') \n" |
| 59 |
" throw 'unexpected last-ditch locale';"); |
| 60 |
EXEC( |
| 61 |
"if (Intl.Collator('en-GB').resolvedOptions().locale !== 'en-GB') \n" |
| 62 |
" throw 'unexpected used locale when specified, with last-ditch " |
| 63 |
"locale as default';"); |
| 64 |
|
| 65 |
JS_ResetDefaultLocale(rt); |
| 66 |
return true; |
| 67 |
} |
| 68 |
END_TEST(testIntlAvailableLocales) |