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(testDateToLocaleString
) {
12 JSRuntime
* rt
= JS_GetRuntime(cx
);
14 // This test should only attempt to run if we have Intl support: necessary
15 // to properly assume that changes to the default locale will predictably
16 // affect the behavior of the locale-sensitive Date methods tested here.
17 JS::Rooted
<JS::Value
> haveIntl(cx
);
18 EVAL("typeof Intl !== 'undefined'", &haveIntl
);
19 if (!haveIntl
.toBoolean()) {
23 // Pervasive assumption: our Intl support includes "de" (German) and
24 // "en" (English) and treats them differently for purposes of
25 // Date.prototype.toLocale{,Date,Time}String behavior.
28 CHECK(JS_SetDefaultLocale(rt
, "de"));
30 // The (constrained) Date object we'll use to test behavior.
31 EXEC("var d = new Date(Date.UTC(2015, 9 - 1, 17));");
33 // Test that toLocaleString behavior changes with default locale changes.
34 EXEC("var deAll = d.toLocaleString();");
36 CHECK(JS_SetDefaultLocale(rt
, "en"));
38 "if (d.toLocaleString() === deAll) \n"
39 " throw 'toLocaleString results should have changed with system locale "
42 // Test that toLocaleDateString behavior changes with default locale changes.
43 EXEC("var enDate = d.toLocaleDateString();");
45 CHECK(JS_SetDefaultLocale(rt
, "de"));
47 "if (d.toLocaleDateString() === enDate) \n"
48 " throw 'toLocaleDateString results should have changed with system "
51 // Test that toLocaleTimeString behavior changes with default locale changes.
52 EXEC("var deTime = d.toLocaleTimeString();");
54 CHECK(JS_SetDefaultLocale(rt
, "en"));
56 "if (d.toLocaleTimeString() === deTime) \n"
57 " throw 'toLocaleTimeString results should have changed with system "
60 JS_ResetDefaultLocale(rt
);
63 END_TEST(testDateToLocaleString
)