Files: 48f11ee4bbabe3ee3bf0c9e02f75c39456e53582 / test / find.js
1482 bytesRaw
1 | |
2 | var pull = require('../') |
3 | var test = require('tape') |
4 | |
5 | test('find 7', function (t) { |
6 | pull( |
7 | pull.values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), |
8 | pull.find(function (d) { |
9 | return d == 7 |
10 | }, function (err, seven) { |
11 | t.equal(seven, 7) |
12 | t.notOk(err) |
13 | t.end() |
14 | }) |
15 | ) |
16 | }) |
17 | |
18 | var target = Math.random() |
19 | test('find ' + target, function (t) { |
20 | var f = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(Math.random) |
21 | |
22 | f.push(target) |
23 | pull( |
24 | pull.values(f.sort()), |
25 | pull.find(function (d) { |
26 | return d == target |
27 | }, function (err, found) { |
28 | t.equal(found, target) |
29 | t.notOk(err) |
30 | t.end() |
31 | }) |
32 | ) |
33 | }) |
34 | |
35 | test('find missing', function (t) { |
36 | var f = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
37 | |
38 | pull( |
39 | pull.values(f.sort()), |
40 | pull.find(function (d) { |
41 | return d == target |
42 | }, function (err, found) { |
43 | t.equal(found, null) |
44 | t.notOk(err) |
45 | t.end() |
46 | }) |
47 | ) |
48 | }) |
49 | |
50 | |
51 | test('there can only be one', function (t) { |
52 | |
53 | pull( |
54 | pull.values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), |
55 | pull.asyncMap(function (e, cb) { |
56 | process.nextTick(function () { |
57 | cb(null, e) |
58 | }) |
59 | }), |
60 | pull.find(function (d) { |
61 | return d >= 7 |
62 | }, function (err, seven) { |
63 | t.equal(seven, 7) |
64 | t.notOk(err) |
65 | t.end() |
66 | }) |
67 | ) |
68 | |
69 | }) |
70 | |
71 | test('find null', function (t) { |
72 | pull( |
73 | pull.values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), |
74 | pull.find(null, function (err, first) { |
75 | t.equal(first, 1) |
76 | t.notOk(err) |
77 | t.end() |
78 | }) |
79 | ) |
80 | }) |
Built with git-ssb-web