resolved-options.js 4.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2018 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.

let rtf = new Intl.RelativeTimeFormat();
// Test 1.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ()
// The default style is 'long'
assertEquals('long', rtf.resolvedOptions().style);

// The default numeric is 'always'
assertEquals('always', rtf.resolvedOptions().numeric);

// contains style, numeric and locale key
14
assertEquals(4, Object.getOwnPropertyNames(rtf.resolvedOptions()).length);
15 16

// contains style, numeric and locale key
17 18 19 20 21 22
assertEquals(
    4,
    Object.getOwnPropertyNames(
        new Intl.RelativeTimeFormat("en").resolvedOptions()
    ).length
);
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

assertEquals(
    'short',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'short'}))
        .resolvedOptions().style);

assertEquals(
    'always',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'short'}))
        .resolvedOptions().numeric);

assertEquals(
    'narrow',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'narrow'}))
        .resolvedOptions().style);

assertEquals(
    'always',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'narrow'}))
        .resolvedOptions().numeric);

assertEquals(
    'long',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'long'}))
        .resolvedOptions().style);

assertEquals(
    'always',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'long'}))
        .resolvedOptions().numeric);

assertEquals(
    'auto',
    (new Intl.RelativeTimeFormat(['sr'], {numeric: 'auto'}))
        .resolvedOptions().numeric);

assertEquals(
    'long',
    (new Intl.RelativeTimeFormat(['sr'], {numeric: 'auto'}))
        .resolvedOptions().style);

assertEquals(
    'always',
    (new Intl.RelativeTimeFormat(['sr'], {numeric: 'always'}))
        .resolvedOptions().numeric);

assertEquals(
    'long',
    (new Intl.RelativeTimeFormat(['sr'], {numeric: 'always'}))
        .resolvedOptions().style);

assertEquals(
    'long',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'auto'}))
        .resolvedOptions().style);

assertEquals(
    'auto',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'auto'}))
        .resolvedOptions().numeric);

assertEquals(
    'long',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'always'}))
        .resolvedOptions().style);

assertEquals(
    'always',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'always'}))
        .resolvedOptions().numeric);

assertEquals(
    'short',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'auto'}))
        .resolvedOptions().style);

assertEquals(
    'auto',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'auto'}))
        .resolvedOptions().numeric);

assertEquals(
    'short',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'always'}))
        .resolvedOptions().style);

assertEquals(
    'always',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'always'}))
        .resolvedOptions().numeric);

assertEquals(
    'narrow',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'auto'}))
        .resolvedOptions().style);

assertEquals(
    'auto',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'auto'}))
        .resolvedOptions().numeric);

assertEquals(
    'narrow',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'always'}))
        .resolvedOptions().style);

assertEquals(
    'always',
    (new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'always'}))
        .resolvedOptions().numeric);

assertEquals(
    'ar',
    (new Intl.RelativeTimeFormat(['ar'])).resolvedOptions().locale);

assertEquals(
    'ar',
    (new Intl.RelativeTimeFormat(['ar', 'en'])).resolvedOptions().locale);

assertEquals(
    'fr',
    (new Intl.RelativeTimeFormat(['fr', 'en'])).resolvedOptions().locale);

assertEquals(
    'ar',
    (new Intl.RelativeTimeFormat(['xyz', 'ar'])).resolvedOptions().locale);

{
  var receiver = 1;
  assertThrows(() =>
     Intl.RelativeTimeFormat.prototype.resolvedOptions.call(receiver), TypeError);

  receiver = {};
  assertThrows(() =>
     Intl.RelativeTimeFormat.prototype.resolvedOptions.call(receiver), TypeError);
}