summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_calIteratorUtils.js
blob: db5158d6c9dc93a858534343201b9a7160e6be9c (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * Tests for cal.iterate.*
 */

var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { CalReadableStreamFactory } = ChromeUtils.import(
  "resource:///modules/CalReadableStreamFactory.jsm"
);

/**
 * Test streamValues() iterates over all values found in a stream.
 */
add_task(async function testStreamValues() {
  let src = Array(10)
    .fill(null)
    .map((_, i) => i + 1);
  let stream = CalReadableStreamFactory.createReadableStream({
    start(controller) {
      for (let i = 0; i < src.length; i++) {
        controller.enqueue(src[i]);
      }
      controller.close();
    },
  });

  let dest = [];
  for await (let value of cal.iterate.streamValues(stream)) {
    dest.push(value);
  }
  Assert.ok(
    src.every((val, idx) => (dest[idx] = val)),
    "all values were read from the stream"
  );
});