v8/test/cctest/test-api-icu.cc
Frank Tang b9a48232b7 [Intl] Update ICU to 70-1 on v8
Diary  https://docs.google.com/document/d/1NqMw7DAVFCZRx67auC7sgOvrikHvCYuaB87JUf21yG8/edit#
eedbaf76..3e05d9da

chromium roll in https://chromium-review.googlesource.com/c/chromium/src/+/3224333

Bug: chromium:1260116
Change-Id: Ie1922a129310106985f3bf1bffd9101fce6bb73a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3237532
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77868}
2021-11-12 11:35:09 +00:00

59 lines
1.8 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef V8_INTL_SUPPORT
#include <stdlib.h>
#include "include/v8-isolate.h"
#include "include/v8-local-handle.h"
#include "src/objects/objects-inl.h"
#include "test/cctest/cctest.h"
#include "unicode/locid.h"
namespace {
void CheckLocaleSpecificValues(const char* locale, const char* date,
const char* number) {
CHECK(v8_str(locale)->StrictEquals(
CompileRun("Intl.NumberFormat().resolvedOptions().locale")));
CHECK(v8_str(date)->StrictEquals(
CompileRun("new Date('02/14/2020 13:45').toLocaleString()")));
CHECK(v8_str(number)->StrictEquals(
CompileRun("Number(10000.3).toLocaleString()")));
}
void SetIcuLocale(const char* locale_name) {
UErrorCode error_code = U_ZERO_ERROR;
icu::Locale locale(locale_name);
icu::Locale::setDefault(locale, error_code);
CHECK(U_SUCCESS(error_code));
}
} // namespace
TEST(LocaleConfigurationChangeNotification) {
icu::Locale default_locale = icu::Locale::getDefault();
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope scope(isolate);
SetIcuLocale("en_US");
isolate->LocaleConfigurationChangeNotification();
CheckLocaleSpecificValues("en-US", "2/14/2020, 1:45:00 PM", "10,000.3");
SetIcuLocale("ru_RU");
isolate->LocaleConfigurationChangeNotification();
CheckLocaleSpecificValues("ru-RU", "14.02.2020, 13:45:00", "10 000,3");
SetIcuLocale("zh_CN");
isolate->LocaleConfigurationChangeNotification();
CheckLocaleSpecificValues("zh-CN", "2020/2/14 13:45:00", "10,000.3");
UErrorCode error_code = U_ZERO_ERROR;
icu::Locale::setDefault(default_locale, error_code);
CHECK(U_SUCCESS(error_code));
}
#endif // V8_INTL_SUPPORT