summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/ListFormat/prototype/format/es-es-short.js
blob: b812906d1b0a5eae4fa19a18ccbc28c6486d650b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-Intl.ListFormat.prototype.format
description: >
    Checks the behavior of Intl.ListFormat.prototype.format() in English.
features: [Intl.ListFormat]
locale: [en-US]
---*/

function CustomIterator(array) {
  this.i = 0;
  this.array = array;
}

CustomIterator.prototype[Symbol.iterator] = function() {
  return this;
}

CustomIterator.prototype.next = function() {
  if (this.i >= this.array.length) {
    return {
      "done": true,
    };
  }

  return {
    "value": this.array[this.i++],
    "done": false,
  };
}

const transforms = [
  a => a,
  a => a[Symbol.iterator](),
  a => new CustomIterator(a),
];

const lf = new Intl.ListFormat("es-ES", {
  "style": "short",
  "type": "unit",
});

assert.sameValue(typeof lf.format, "function", "format should be supported");

for (const f of transforms) {
  assert.sameValue(lf.format(f([])), "");
  assert.sameValue(lf.format(f(["foo"])), "foo");
  assert.sameValue(lf.format(f(["foo", "bar"])), "foo y bar");
  assert.sameValue(lf.format(f(["foo", "bar", "baz"])), "foo, bar, baz");
  assert.sameValue(lf.format(f(["foo", "bar", "baz", "quux"])), "foo, bar, baz, quux");
}

assert.sameValue(lf.format("foo"), "f, o, o");

reportCompare(0, 0);