Files: 2d4523dffda72662b6872ac393ee20e811eee7b1 / test / compose.js
1189 bytesRaw
1 | var pull = require('../') |
2 | var test = require('tape') |
3 | //test through streams compose on pipe! |
4 | |
5 | test('join through streams with pipe', function (t) { |
6 | |
7 | var map = pull.map |
8 | |
9 | var pipeline = |
10 | pull( |
11 | map(function (d) { |
12 | //make exciting! |
13 | return d + '!' |
14 | }), |
15 | map(function (d) { |
16 | //make loud |
17 | return d.toUpperCase() |
18 | }), |
19 | map(function (d) { |
20 | //add sparkles |
21 | return '*** ' + d + ' ***' |
22 | }) |
23 | ) |
24 | //the pipe line does not have a source stream. |
25 | //so it should be a reader (function that accepts |
26 | //a read function) |
27 | |
28 | t.equal('function', typeof pipeline) |
29 | t.equal(1, pipeline.length) |
30 | |
31 | //if we pipe a read function to the pipeline, |
32 | //the pipeline will become readable! |
33 | |
34 | var read = |
35 | pull( |
36 | pull.values(['billy', 'joe', 'zeke']), |
37 | pipeline |
38 | ) |
39 | |
40 | t.equal('function', typeof read) |
41 | //we will know it's a read function, |
42 | //because read takes two args. |
43 | t.equal(2, read.length) |
44 | |
45 | pull( |
46 | read, |
47 | pull.collect(function (err, array) { |
48 | console.log(array) |
49 | t.deepEqual( |
50 | array, |
51 | [ '*** BILLY! ***', '*** JOE! ***', '*** ZEKE! ***' ] |
52 | ) |
53 | t.end() |
54 | }) |
55 | ) |
56 | |
57 | }) |
58 |
Built with git-ssb-web