From 0ec5b02ac6e5255a6171295eaff4006483be6f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 17 Jan 2018 10:28:24 -0800 Subject: [PATCH] Add test case for tc39/ecma402#204 --- .../resolved-locale-with-hc-unicode.js | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/intl402/DateTimeFormat/prototype/resolvedOptions/resolved-locale-with-hc-unicode.js diff --git a/test/intl402/DateTimeFormat/prototype/resolvedOptions/resolved-locale-with-hc-unicode.js b/test/intl402/DateTimeFormat/prototype/resolvedOptions/resolved-locale-with-hc-unicode.js new file mode 100644 index 0000000000..61e747ef99 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/resolvedOptions/resolved-locale-with-hc-unicode.js @@ -0,0 +1,87 @@ +// Copyright 2018 André Bargull. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-Intl.DateTimeFormat.prototype.resolvedOptions +description: > + The resolved locale doesn't include a hc Unicode extension value if the + hour12 or hourCycle option is also present. +info: | + 12.1.1 InitializeDateTimeFormat(dateTimeFormat, locales, options) + ... + 6. Let hour12 be ? GetOption(options, "hour12", "boolean", undefined, undefined). + 7. Let hourCycle be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined). + 8. If hour12 is not undefined, then + a. Let hourCycle be null. + 9. Set opt.[[hc]] to hourCycle. + ... + + 9.2.6 ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) + ... + 8. For each element key of relevantExtensionKeys in List order, do + ... + i. If options has a field [[]], then + i. Let optionsValue be options.[[]]. + ii. Assert: Type(optionsValue) is either String, Undefined, or Null. + iii. If keyLocaleData contains optionsValue, then + 1. If SameValue(optionsValue, value) is false, then + a. Let value be optionsValue. + b. Let supportedExtensionAddition be "". + ... +---*/ + +var defaultLocale = new Intl.DateTimeFormat().resolvedOptions().locale; +var defaultLocaleWithHourCycle = defaultLocale + "-u-hc-h11"; + +function assertLocale(locale, expectedLocale, options, message) { + var resolved = new Intl.DateTimeFormat(locale, { + hour: "2-digit", + hour12: options.hour12, + hourCycle: options.hourCycle, + }).resolvedOptions(); + assert.sameValue(resolved.locale, expectedLocale, message + " (With hour option.)"); + + // Also test the case when no hour option is present at all. + // The resolved options don't include hour12 and hourCycle if the date-time + // formatter doesn't include an hour option. This restriction doesn't apply + // to the hc Unicode extension value. + resolved = new Intl.DateTimeFormat(locale, { + hour12: options.hour12, + hourCycle: options.hourCycle, + }).resolvedOptions(); + assert.sameValue(resolved.locale, expectedLocale, message + " (Without hour option.)"); +} + +assertLocale(defaultLocaleWithHourCycle, defaultLocale, { + hour12: false, + hourCycle: "h23", +}, "hour12 and hourCycle options and hc Unicode extension value are present."); + +assertLocale(defaultLocaleWithHourCycle, defaultLocale, { + hour12: false, +}, "hour12 option and hc Unicode extension value are present."); + +assertLocale(defaultLocaleWithHourCycle, defaultLocale, { + hourCycle: "h23", +}, "hourCycle option and hc Unicode extension value are present."); + +assertLocale(defaultLocaleWithHourCycle, defaultLocaleWithHourCycle, { +}, "Only hc Unicode extension value is present."); + +// And make sure the hc Unicode extension doesn't get added if it's not present +// in the requested locale. +assertLocale(defaultLocale, defaultLocale, { + hour12: false, + hourCycle: "h23", +}, "hour12 and hourCycle options are present, but no hc Unicode extension value."); + +assertLocale(defaultLocale, defaultLocale, { + hour12: false, +}, "hourCycle option is present, but no hc Unicode extension value."); + +assertLocale(defaultLocale, defaultLocale, { + hourCycle: "h23", +}, "hourCycle option is present, but no hc Unicode extension value."); + +assertLocale(defaultLocale, defaultLocale, { +}, "No options are present and no hc Unicode extension value.");