forked from fc00/node-pad-ipv6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
34 lines (27 loc) · 1.02 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
var pad = require("./index");
var countColons = function (x) {
var n = 0;
x.replace(/:/g, function (c) { n++; });
return n;
};
[
["fc00::", "fc00:0000:0000:0000:0000:0000:0000:0000"],
["fe80:685::ff:fe72:c4fa", "fe80:0685:0000:0000:0000:00ff:fe72:c4fa"],
["::", "0000:0000:0000:0000:0000:0000:0000:0000"],
["::1", "0000:0000:0000:0000:0000:0000:0000:0001"],
].forEach(function (pair) {
var input = pair[0];
var expected = pair[1];
var padded = pad(input);
false && console.log({
input: input,
inputLength: input.length,
inputColons: countColons(input),
output: padded,
outputLength: padded.length,
outputColons: countColons(padded),
});
if (countColons(padded) !== 7) { throw new Error("Expected more colons"); }
if (padded.length !== 39) { throw new Error("Expected a 39 character IP"); }
if (padded !== expected) { throw new Error(padded + " !== " + expected); }
});