2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const blueslip = require("./lib/zblueslip");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-08-03 23:57:48 +02:00
|
|
|
const {LazySet} = zrequire("lazy_set");
|
2020-01-14 23:29:54 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
We mostly test LazySet indirectly. This code
|
|
|
|
may be short-lived, anyway, once we change
|
|
|
|
how we download subscribers in page_params.
|
|
|
|
*/
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("map", () => {
|
2020-02-03 07:48:50 +01:00
|
|
|
const ls = new LazySet([1, 2]);
|
2020-01-14 23:29:54 +01:00
|
|
|
|
2021-01-23 02:36:54 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
ls.map((n) => n * 3),
|
|
|
|
[3, 6],
|
|
|
|
);
|
2020-01-14 23:29:54 +01:00
|
|
|
});
|
|
|
|
|
2023-10-31 19:13:24 +01:00
|
|
|
run_test("size", () => {
|
|
|
|
const ls = new LazySet([1, 2]);
|
|
|
|
assert.deepEqual(ls.size, 2);
|
|
|
|
|
|
|
|
ls._make_set();
|
|
|
|
assert.deepEqual(ls.size, 2);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("conversions", () => {
|
|
|
|
blueslip.expect("error", "not a number", 2);
|
2020-02-03 07:48:50 +01:00
|
|
|
const ls = new LazySet([1, 2]);
|
2020-07-15 01:29:15 +02:00
|
|
|
ls.add("3");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(ls.has("3"));
|
2020-01-14 23:29:54 +01:00
|
|
|
});
|