blob: f5e97d6e93965932087aab60405185d969044b09 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001var tape = require('tape')
2var toBuffer = require('./')
3
4tape('buffer returns buffer', function (t) {
5 t.same(toBuffer(Buffer('hi')), Buffer('hi'))
6 t.end()
7})
8
9tape('string returns buffer', function (t) {
10 t.same(toBuffer('hi'), Buffer('hi'))
11 t.end()
12})
13
14tape('string + enc returns buffer', function (t) {
15 t.same(toBuffer('6869', 'hex'), Buffer('hi'))
16 t.end()
17})
18
19tape('other input throws', function (t) {
20 try {
21 toBuffer(42)
22 } catch (err) {
23 t.same(err.message, 'Input should be a buffer or a string')
24 t.end()
25 }
26})