format-to-parts-plural.js 906 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// 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.

// Check plural w/ formatToParts
// http://tc39.github.io/proposal-intl-relative-time/

let rtf = new Intl.RelativeTimeFormat();

// Test 1.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit )
function verifyElement(part, expectedUnit) {
  assertEquals(true, part.type == 'literal' || part.type == 'integer');
  assertEquals('string', typeof part.value);
  if (part.type == 'integer') {
    assertEquals('string', typeof part.unit);
    assertEquals(expectedUnit, part.unit);
  }
};

20
['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second'].forEach(
21 22 23 24 25 26
    function(unit) {
      rtf.formatToParts(100, unit + 's').forEach(
          function(part) {
            verifyElement(part, unit);
          });
    });