util.x509: Nameprep commonName once
[prosody.git] / spec / util_iterators_spec.lua
blob4cf6f19dfd9c863f1ff76c4d023e1098dbac21e6
1 local iter = require "util.iterators";
3 describe("util.iterators", function ()
4 describe("join", function ()
5 it("should produce a joined iterator", function ()
6 local expect = { "a", "b", "c", 1, 2, 3 };
7 local output = {};
8 for x in iter.join(iter.values({"a", "b", "c"})):append(iter.values({1, 2, 3})) do
9 table.insert(output, x);
10 end
11 assert.same(output, expect);
12 end);
13 end);
15 describe("sorted_pairs", function ()
16 it("should produce sorted pairs", function ()
17 local orig = { b = 1, c = 2, a = "foo", d = false };
18 local n, last_key = 0, nil;
19 for k, v in iter.sorted_pairs(orig) do
20 n = n + 1;
21 if last_key then
22 assert(k > last_key, "Expected "..k.." > "..last_key)
23 end
24 assert.equal(orig[k], v);
25 last_key = k;
26 end
27 assert.equal("d", last_key);
28 assert.equal(4, n);
29 end);
31 it("should allow a custom sort function", function ()
32 local orig = { b = 1, c = 2, a = "foo", d = false };
33 local n, last_key = 0, nil;
34 for k, v in iter.sorted_pairs(orig, function (a, b) return a > b end) do
35 n = n + 1;
36 if last_key then
37 assert(k < last_key, "Expected "..k.." > "..last_key)
38 end
39 assert.equal(orig[k], v);
40 last_key = k;
41 end
42 assert.equal("a", last_key);
43 assert.equal(4, n);
44 end);
45 end);
46 end);