Files: d2f2697f296dd39aed6a8b63c6d04a736a7db5b3 / node_modules / pull-utf8-decoder / test / index.js
1296 bytesRaw
1 | var pull = require('pull-stream') |
2 | var fs = require('fs') |
3 | var file = fs.readFileSync(__filename, 'utf-8').split(/(\n)/).map(function (e) { return new Buffer(e) }) |
4 | var decode = require('../') |
5 | |
6 | console.log(file) |
7 | |
8 | var test = require('tape') |
9 | |
10 | //handle old node and new node |
11 | function A(buf) { |
12 | return [].slice.call(buf) |
13 | } |
14 | |
15 | test('lines', function (t) { |
16 | |
17 | pull( |
18 | pull.values(file), |
19 | decode('utf8'), |
20 | pull.collect(function (err, ary) { |
21 | if(err) throw err |
22 | console.log(ary.join('')) |
23 | t.equal(file.map(String).join(''), ary.join('')) |
24 | t.end() |
25 | }) |
26 | ) |
27 | |
28 | }) |
29 | |
30 | test('utf-8', function (t) { |
31 | var expected = 'cents:¢\neuros:€' |
32 | |
33 | var coinage = [ |
34 | A(new Buffer('cents:')), |
35 | [0xC2, 0xA2], |
36 | A(new Buffer('\n')), |
37 | A(new Buffer('euros:')), |
38 | [0xE2, 0x82, 0xAC] |
39 | ].reduce(function (a, b) { |
40 | return a.concat(b) |
41 | }) |
42 | |
43 | function rSplit() { |
44 | var s = coinage.slice() |
45 | var a = [] |
46 | while(s.length) { |
47 | var n = ~~(Math.random()*s.length) + 1 |
48 | a.push(s.splice(0, n)) |
49 | } |
50 | return a.map(function (e) { return new Buffer(e) }) |
51 | } |
52 | |
53 | t.plan(100) |
54 | var N = 100 |
55 | |
56 | while(N--) |
57 | pull( |
58 | pull.values(rSplit()), |
59 | decode(), |
60 | pull.collect(function (err, ary) { |
61 | t.equal(ary.join(''), expected) |
62 | }) |
63 | ) |
64 | |
65 | t.end() |
66 | |
67 | }) |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 |
Built with git-ssb-web