forked from kesla/node-snappy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
123 lines (105 loc) · 3.28 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var test = require('tap').test
, snappy = require('./snappy')
, inputString = 'beep boop, hello world. OMG OMG OMG'
, inputBuffer = new Buffer(inputString)
, compressed
test('compress() string', function (t) {
snappy.compress(inputString, function (err, buffer) {
compressed = buffer
t.error(err)
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer')
t.end()
})
})
test('compressSync() string', function (t) {
var buffer = snappy.compressSync(inputString)
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer')
t.deepEqual(buffer, compressed, 'should compress to same as async version')
t.end()
})
test('compress() buffer', function (t) {
snappy.compress(inputBuffer, function (err, buffer) {
t.error(err)
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer')
t.deepEqual(buffer, compressed, 'should compress to same as string')
t.end()
})
})
test('compressSync() buffer', function (t) {
var buffer = snappy.compressSync(inputBuffer)
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer')
t.deepEqual(buffer, compressed, 'should compress to same as async version')
t.end()
})
test('isValidCompressed() on valid data', function (t) {
snappy.isValidCompressed(compressed, function (err, results) {
t.error(err)
t.equal(results, true)
t.end()
})
})
test('isValidCompressed() on invalid data', function (t) {
snappy.isValidCompressed(new Buffer('beep boop'), function (err, results) {
t.error(err)
t.equal(results, false)
t.end()
})
})
test('isValidCompressedSync() on valid data', function (t) {
var results = snappy.isValidCompressedSync(compressed)
t.equal(results, true)
t.end()
})
test('isValidCompressedSync() on invalid data', function (t) {
var results = snappy.isValidCompressedSync(new Buffer('beep boop'))
t.equal(results, false)
t.end()
})
test('uncompress() defaults to Buffer', function (t) {
snappy.uncompress(compressed, function (err, buffer) {
t.error(err)
t.deepEqual(buffer, inputBuffer)
t.end()
})
})
test('uncompress() returning a Buffer', function (t) {
snappy.uncompress(compressed, { asBuffer: true }, function (err, buffer) {
t.error(err)
t.deepEqual(buffer, inputBuffer)
t.end()
})
})
test('uncompress() returning a String', function (t) {
snappy.uncompress(compressed, { asBuffer: false }, function (err, buffer) {
t.error(err)
t.deepEqual(buffer, inputString)
t.end()
})
})
test('uncompress() on bad input', function (t) {
snappy.uncompress(new Buffer('beep boop OMG OMG OMG'), function (err) {
t.equal(err.message, 'Invalid input')
t.end()
})
})
test('uncompressSync() defaults to Buffer', function (t) {
var results = snappy.uncompressSync(compressed)
t.deepEqual(results, inputBuffer)
t.end()
})
test('uncompressSync() returning a Buffer', function (t) {
var results = snappy.uncompressSync(compressed, { asBuffer: true })
t.deepEqual(results, inputBuffer)
t.end()
})
test('uncompressSync() returning a String', function (t) {
var results = snappy.uncompressSync(compressed, { asBuffer: false })
t.deepEqual(results, inputString)
t.end()
})
test('uncompressSync() on bad input', function (t) {
t.throws(function () {
snappy.uncompressSync(new Buffer('beep boop OMG OMG OMG'))
}, 'Invalid input')
t.end()
})