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:
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/. */
8 #include "js/LocaleSensitive.h"
9 #include "jsapi-tests/tests.h"
11 BEGIN_TEST(testIntlAvailableLocales
) {
12 JSRuntime
* rt
= JS_GetRuntime(cx
);
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()) {
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"));
26 "if (Intl.Collator().resolvedOptions().locale !== "
28 " throw 'unexpected default locale';");
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;");
34 "if (Intl.Collator('az').resolvedOptions().locale !== 'az') \n"
35 " throw 'bad locale when using more-truncated default';");
37 "if (Intl.Collator('az-Cyrl-US').resolvedOptions().locale !== 'az-Cyrl') "
39 " throw 'unexpected default locale';");
42 "if (Intl.Collator('az-Cyrl-AZ', { localeMatcher: 'lookup' "
43 "}).resolvedOptions().locale !== \n"
46 " throw 'unexpected default locale with lookup matcher'; \n"
49 CHECK(JS_SetDefaultLocale(rt
, "en-US-u-co-phonebk"));
51 "if (Intl.Collator().resolvedOptions().locale !== 'en-US') \n"
52 " throw 'unexpected default locale where proposed default included a "
53 "Unicode extension';");
55 CHECK(JS_SetDefaultLocale(rt
, "this is not a language tag at all, yo"));
58 "if (Intl.Collator().resolvedOptions().locale !== 'en-GB') \n"
59 " throw 'unexpected last-ditch locale';");
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';");
65 JS_ResetDefaultLocale(rt
);
68 END_TEST(testIntlAvailableLocales
)