constructor-options-hourcycle-valid.js (2352B)
1 // Copyright 2018 Igalia, S.L. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-intl.locale 6 description: > 7 Checks valid cases for the options argument to the Locale constructor. 8 info: | 9 Intl.Locale( tag [, options] ) 10 11 ... 12 20. Let hc be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined). 13 21. Set opt.[[hc]] to hc. 14 ... 15 30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys). 16 ... 17 18 ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys ) 19 20 ... 21 8. Let locale be the String value that is tag with all Unicode locale extension sequences removed. 22 9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords). 23 10. If newExtension is not the empty String, then 24 a. Let locale be ! InsertUnicodeExtension(locale, newExtension). 25 ... 26 27 CanonicalizeUnicodeExtension( attributes, keywords ) 28 ... 29 4. Repeat for each element entry of keywords in List order, 30 a. Let keyword be entry.[[Key]]. 31 b. If entry.[[Value]] is not the empty String, then 32 i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]]. 33 c. Append keyword to fullKeywords. 34 ... 35 features: [Intl.Locale] 36 ---*/ 37 38 const validHourCycleOptions = [ 39 'h11', 40 'h12', 41 'h23', 42 'h24', 43 { toString() { return 'h24'; } }, 44 ]; 45 for (const hourCycle of validHourCycleOptions) { 46 const expected = String(hourCycle); 47 let expect = 'en-u-hc-' + expected; 48 49 assert.sameValue( 50 new Intl.Locale('en', {hourCycle}).toString(), 51 expect, 52 `new Intl.Locale("en", {hourCycle: "${hourCycle}"}).toString() returns "${expect}"` 53 ); 54 55 assert.sameValue( 56 new Intl.Locale('en-u-hc-h00', {hourCycle}).toString(), 57 expect, 58 `new Intl.Locale("en-u-hc-h00", {hourCycle: "${hourCycle}"}).toString() returns "${expect}"` 59 ); 60 61 assert.sameValue( 62 new Intl.Locale('en-u-hc-h12', {hourCycle}).toString(), 63 expect, 64 `new Intl.Locale("en-u-hc-h12", {hourCycle: "${hourCycle}"}).toString() returns "${expect}"` 65 ); 66 67 assert.sameValue( 68 new Intl.Locale('en-u-hc-h00', {hourCycle}).hourCycle, 69 expected, 70 `new Intl.Locale("en-u-hc-h00", {hourCycle: "${hourCycle}"}).hourCycle equals "${expected}"` 71 ); 72 } 73 74 reportCompare(0, 0);