UNPKG

1.69 kBJavaScriptView Raw
1var assert = require('assert');
2var compact2string = require('./');
3
4describe('compact2string', function() {
5
6 it('should return expected IPv4 address', function() {
7 assert.equal('10.10.10.5:65408', compact2string(new Buffer("0A0A0A05FF80", "hex")));
8 });
9 it('should return expected IPv6 address', function() {
10 assert.equal('[2a03:2880:2110:9f07:face:b00c:0:1]:80', compact2string(new Buffer("2a03288021109f07faceb00c000000010050", "hex")));
11 });
12
13 it('should throw an error if the buffer length isn\'t 6 or 18', function() {
14 assert.throws(function() {
15 compact2string(new Buffer("0A0A0A05", "hex"));
16 }, /should contain 6 or 18 bytes/);
17 });
18});
19
20describe('compact2string.multi', function() {
21 it('should return expected multi', function() {
22 assert.deepEqual([ '10.10.10.5:128', '100.56.58.99:28525' ], compact2string.multi(new Buffer("0A0A0A05008064383a636f6d", "hex")));
23 });
24
25 it('should throw an error if the buffer isn\'t a multiple of 6', function() {
26 assert.throws(function() {
27 compact2string.multi(new Buffer("0A0A0A05050505", "hex"));
28 }, /multiple of/);
29 });
30
31});
32
33describe('compact2string.multi6', function() {
34 it('should return expected multi6', function() {
35 assert.deepEqual([ '[2a03:2880:2110:9f07:face:b00c:0:1]:80', '[2a00:1450:4008:801:0:0:0:1010]:443' ], compact2string.multi6(new Buffer("2a03288021109f07faceb00c0000000100502a00145040080801000000000000101001bb", "hex")));
36 });
37
38 it('should throw an error if the buffer isn\'t a multiple of 18', function() {
39 assert.throws(function() {
40 compact2string.multi6(new Buffer("0A0A0A050505050A0A0A050505050A0A0A05050505", "hex"));
41 }, /multiple of/);
42 });
43
44});