OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-core-schemas / node_modules / compact-encoding / test.js

1 lines · javascript ref:
const e=require("./"),t=require("brittle"),a=require("b4a");t("uint",function(t){const n=e.state();e.uint.preencode(n,42),t.alike(n,e.state(0,1)),e.uint.preencode(n,4200),t.alike(n,e.state(0,4)),e.uint.preencode(n,Number.MAX_SAFE_INTEGER),t.alike(n,e.state(0,13)),n.buffer=a.alloc(n.end),e.uint.encode(n,42),t.alike(n,e.state(1,13,a.from([42,0,0,0,0,0,0,0,0,0,0,0,0]))),e.uint.encode(n,4200),t.alike(n,e.state(4,13,a.from([42,253,104,16,0,0,0,0,0,0,0,0,0]))),e.uint.encode(n,Number.MAX_SAFE_INTEGER),t.alike(n,e.state(13,13,a.from([42,253,104,16,255,255,255,255,255,255,255,31,0]))),n.start=0,t.is(e.uint.decode(n),42),t.is(e.uint.decode(n),4200),t.is(e.uint.decode(n),Number.MAX_SAFE_INTEGER),t.is(n.start,n.end),t.exception(()=>e.uint.decode(n))}),t("int",function(t){const n=e.state();e.int.preencode(n,42),t.alike(n,e.state(0,1)),e.int.preencode(n,-4200),t.alike(n,e.state(0,4)),n.buffer=a.alloc(n.end),e.int.encode(n,42),t.alike(n,e.state(1,4,a.from([84,0,0,0]))),e.int.encode(n,-4200),t.alike(n,e.state(4,4,a.from([84,253,207,32]))),n.start=0,t.is(e.int.decode(n),42),t.is(e.int.decode(n),-4200),t.is(n.start,n.end),t.exception(()=>e.int.decode(n))}),t("float64",function(t){const n=e.state();e.float64.preencode(n,162.2377294),t.alike(n,e.state(0,8)),n.buffer=a.alloc(n.end),t.alike(n,e.state(0,8,a.from([0,0,0,0,0,0,0,0]))),e.float64.encode(n,162.2377294),t.alike(n,e.state(8,8,a.from([135,201,175,122,155,71,100,64]))),n.start=0,t.is(e.float64.decode(n),162.2377294),t.is(n.start,n.end),t.exception(()=>e.float64.decode(n)),n.start=0,n.end=0,n.buffer=null,e.int.preencode(n,0),e.float64.preencode(n,162.2377294),t.alike(n,e.state(0,9)),n.buffer=a.alloc(n.end),t.alike(n,e.state(0,9,a.from([0,0,0,0,0,0,0,0,0]))),e.int.encode(n,0),e.float64.encode(n,162.2377294),t.alike(n,e.state(9,9,a.from([0,135,201,175,122,155,71,100,64]))),n.start=0,t.is(e.int.decode(n),0),t.is(e.float64.decode(n),162.2377294),t.is(n.start,n.end);const o=a.alloc(10);n.start=0,n.buffer=o.subarray(1),t.alike(n,e.state(0,9,a.from([0,0,0,0,0,0,0,0,0]))),e.int.encode(n,0),e.float64.encode(n,162.2377294),t.alike(n,e.state(9,9,a.from([0,135,201,175,122,155,71,100,64]))),t.alike(o,a.from([0,0,135,201,175,122,155,71,100,64])),n.start=0,t.is(e.int.decode(n),0),t.is(e.float64.decode(n),162.2377294),t.is(n.start,n.end),n.start=0,n.end=0,n.buffer=null,e.float64.preencode(n,162.2377294),n.buffer=a.alloc(n.end),e.float64.encode(n,0),t.alike(n,e.state(8,8,a.from([0,0,0,0,0,0,0,0]))),n.start=0,t.is(e.float64.decode(n),0),t.is(n.start,n.end),n.start=0,n.end=0,n.buffer=null,e.float64.preencode(n,1/0),n.buffer=a.alloc(n.end),e.float64.encode(n,1/0),t.alike(n,e.state(8,8,a.from([0,0,0,0,0,0,240,127]))),n.start=0,t.is(e.float64.decode(n),1/0),t.is(n.start,n.end),n.start=0,n.end=0,n.buffer=null,e.float64.preencode(n,.1+.2),n.buffer=a.alloc(n.end),e.float64.encode(n,.1+.2),t.alike(n,e.state(8,8,a.from([52,51,51,51,51,51,211,63]))),n.start=0,t.is(e.float64.decode(n),.1+.2),t.is(n.start,n.end)}),t("biguint64",function(t){const n=e.state(),o=0x0102030405060708n;e.biguint64.preencode(n,o),t.alike(n,e.state(0,8)),n.buffer=a.alloc(n.end),e.biguint64.encode(n,o),t.alike(n,e.state(8,8,a.from([8,7,6,5,4,3,2,1]))),n.start=0,t.is(e.biguint64.decode(n),o),t.is(n.start,n.end),t.exception(()=>e.biguint64.decode(n))}),t("bigint64",function(t){const n=e.state(),o=-0x0102030405060708n;e.bigint64.preencode(n,o),t.alike(n,e.state(0,8)),n.buffer=a.alloc(n.end),e.bigint64.encode(n,o),t.alike(n,e.state(8,8,a.from([15,14,12,10,8,6,4,2]))),n.start=0,t.is(e.bigint64.decode(n),o),t.is(n.start,n.end),t.exception(()=>e.bigint64.decode(n))}),t("biguint",function(t){const n=e.state(),o=0x0102030405060708090a0b0cn;e.biguint.preencode(n,o),t.alike(n,e.state(0,17)),n.buffer=a.alloc(n.end),e.biguint.encode(n,o),t.alike(n,e.state(17,17,a.from([2,12,11,10,9,8,7,6,5,4,3,2,1,0,0,0,0]))),n.start=0,t.is(e.biguint.decode(n),o),t.is(n.start,n.end),t.exception(()=>e.biguint.decode(n))}),t("bigint",function(t){const n=e.state(),o=-0x0102030405060708090a0b0cn;e.bigint.preencode(n,o),t.alike(n,e.state(0,17)),n.buffer=a.alloc(n.end),e.bigint.encode(n,o),t.alike(n,e.state(17,17,a.from([2,23,22,20,18,16,14,12,10,8,6,4,2,0,0,0,0]))),n.start=0,t.is(e.bigint.decode(n),o),t.is(n.start,n.end),t.exception(()=>e.bigint.decode(n))}),t("buffer",function(t){const n=e.state();e.buffer.preencode(n,a.from("hi")),t.alike(n,e.state(0,3)),e.buffer.preencode(n,a.from("hello")),t.alike(n,e.state(0,9)),e.buffer.preencode(n,null),t.alike(n,e.state(0,10)),n.buffer=a.alloc(n.end),e.buffer.encode(n,a.from("hi")),t.alike(n,e.state(3,10,a.from("hi\0\0\0\0\0\0\0"))),e.buffer.encode(n,a.from("hello")),t.alike(n,e.state(9,10,a.from("hihello\0"))),e.buffer.encode(n,null),t.alike(n,e.state(10,10,a.from("hihello\0"))),n.start=0,t.alike(e.buffer.decode(n),a.from("hi")),t.alike(e.buffer.decode(n),a.from("hello")),t.is(e.buffer.decode(n),null),t.is(n.start,n.end),t.exception(()=>e.buffer.decode(n))}),t("arraybuffer",function(t){const n=e.state(),o=new ArrayBuffer(4);a.from(o).fill("a");const r=new ArrayBuffer(8);a.from(r).fill("b"),e.arraybuffer.preencode(n,o),t.alike(n,e.state(0,5)),e.arraybuffer.preencode(n,r),t.alike(n,e.state(0,14)),n.buffer=a.alloc(n.end),e.arraybuffer.encode(n,o),t.alike(n,e.state(5,14,a.from("aaaa\0\0\0\0\0\0\0\0\0"))),e.arraybuffer.encode(n,r),t.alike(n,e.state(14,14,a.from("aaaa\bbbbbbbbb"))),n.start=0,t.alike(e.arraybuffer.decode(n),o),t.alike(e.arraybuffer.decode(n),r),t.is(n.start,n.end),t.exception(()=>e.arraybuffer.decode(n))}),t("raw",function(t){const n=e.state();e.raw.preencode(n,a.from("hi")),t.alike(n,e.state(0,2)),n.buffer=a.alloc(n.end),e.raw.encode(n,a.from("hi")),t.alike(n,e.state(2,2,a.from("hi"))),n.start=0,t.alike(e.raw.decode(n),a.from("hi")),t.is(n.start,n.end)}),t("raw uint8array",function(t){const n=e.state();e.raw.uint8array.preencode(n,Uint8Array.of(1,2)),t.alike(n,e.state(0,2)),e.raw.uint8array.preencode(n,Uint8Array.of(3,4)),t.alike(n,e.state(0,4)),n.buffer=a.alloc(n.end),e.raw.uint8array.encode(n,Uint8Array.of(1,2)),t.alike(n,e.state(2,4,a.from([1,2,0,0]))),e.raw.uint8array.encode(n,Uint8Array.of(3,4)),t.alike(n,e.state(4,4,a.from([1,2,3,4]))),n.start=0,t.alike(e.raw.uint8array.decode(n),Uint8Array.of(1,2,3,4)),t.alike(e.raw.uint8array.decode(n),Uint8Array.of())}),t("uint16array",function(t){const n=e.state();e.uint16array.preencode(n,new Uint16Array([1,2,3])),t.alike(n,e.state(0,7)),n.buffer=a.alloc(n.end),e.uint16array.encode(n,new Uint16Array([1,2,3])),t.alike(n,e.state(7,7,a.from([3,1,0,2,0,3,0]))),n.start=0,t.alike(e.uint16array.decode(n),new Uint16Array([1,2,3])),t.is(n.start,n.end),t.exception(()=>e.uint16array.decode(n))}),t("uint32array",function(t){const n=e.state();e.uint32array.preencode(n,new Uint32Array([1])),t.alike(n,e.state(0,5)),e.uint32array.preencode(n,new Uint32Array([42,43])),t.alike(n,e.state(0,14)),n.buffer=a.alloc(n.end),e.uint32array.encode(n,new Uint32Array([1])),t.alike(n,e.state(5,14,a.from([1,1,0,0,0,0,0,0,0,0,0,0,0,0]))),e.uint32array.encode(n,new Uint32Array([42,43])),t.alike(n,e.state(14,14,a.from([1,1,0,0,0,2,42,0,0,0,43,0,0,0]))),n.start=0,t.alike(e.uint32array.decode(n),new Uint32Array([1])),t.alike(e.uint32array.decode(n),new Uint32Array([42,43])),t.is(n.start,n.end),t.exception(()=>e.uint32array.decode(n))}),t("int16array",function(t){const n=e.state();e.int16array.preencode(n,new Int16Array([1,-2,3])),t.alike(n,e.state(0,7)),n.buffer=a.alloc(n.end),e.int16array.encode(n,new Int16Array([1,-2,3])),t.alike(n,e.state(7,7,a.from([3,1,0,254,255,3,0]))),n.start=0,t.alike(e.int16array.decode(n),new Int16Array([1,-2,3])),t.is(n.start,n.end),t.exception(()=>e.int16array.decode(n))}),t("int32array",function(t){const n=e.state();e.int32array.preencode(n,new Int32Array([1,-2,3])),t.alike(n,e.state(0,13)),n.buffer=a.alloc(n.end),e.int32array.encode(n,new Int32Array([1,-2,3])),t.alike(n,e.state(13,13,a.from([3,1,0,0,0,254,255,255,255,3,0,0,0]))),n.start=0,t.alike(e.int32array.decode(n),new Int32Array([1,-2,3])),t.is(n.start,n.end),t.exception(()=>e.int32array.decode(n))}),t("biguint64array",function(t){const n=e.state(),o=new BigUint64Array([0x01020304n,0x05060708n,0x090a0b0cn]);e.biguint64array.preencode(n,o),t.alike(n,e.state(0,25)),n.buffer=a.alloc(n.end),e.biguint64array.encode(n,o),t.alike(n,e.state(25,25,a.from([3,4,3,2,1,0,0,0,0,8,7,6,5,0,0,0,0,12,11,10,9,0,0,0,0]))),n.start=0,t.alike(e.biguint64array.decode(n),o),t.is(n.start,n.end),t.exception(()=>e.biguint64array.decode(n))}),t("bigint64array",function(t){const n=e.state(),o=new BigInt64Array([-0x01020304n,0x05060708n,-0x090a0b0cn]);e.bigint64array.preencode(n,o),t.alike(n,e.state(0,25)),n.buffer=a.alloc(n.end),e.bigint64array.encode(n,o),t.alike(n,e.state(25,25,a.from([3,252,252,253,254,255,255,255,255,8,7,6,5,0,0,0,0,244,244,245,246,255,255,255,255]))),n.start=0,t.alike(e.bigint64array.decode(n),o),t.is(n.start,n.end),t.exception(()=>e.bigint64array.decode(n))}),t("float32array",function(t){const n=e.state();e.float32array.preencode(n,new Float32Array([1.1,-2.2,3.3])),t.alike(n,e.state(0,13)),n.buffer=a.alloc(n.end),e.float32array.encode(n,new Float32Array([1.1,-2.2,3.3])),t.alike(n,e.state(13,13,a.from([3,205,204,140,63,205,204,12,192,51,51,83,64]))),n.start=0,t.alike(e.float32array.decode(n),new Float32Array([1.1,-2.2,3.3])),t.is(n.start,n.end),t.exception(()=>e.float32array.decode(n))}),t("float64array",function(t){const n=e.state();e.float64array.preencode(n,new Float64Array([1.1,-2.2,3.3])),t.alike(n,e.state(0,25)),n.buffer=a.alloc(n.end),e.float64array.encode(n,new Float64Array([1.1,-2.2,3.3])),t.alike(n,e.state(25,25,a.from([3,154,153,153,153,153,153,241,63,154,153,153,153,153,153,1,192,102,102,102,102,102,102,10,64]))),n.start=0,t.alike(e.float64array.decode(n),new Float64Array([1.1,-2.2,3.3])),t.is(n.start,n.end),t.exception(()=>e.float64array.decode(n))}),t("string",function(t){const n=e.state();e.string.preencode(n,"🌾"),t.alike(n,e.state(0,5)),e.string.preencode(n,"høsten er fin"),t.alike(n,e.state(0,20)),n.buffer=a.alloc(n.end),e.string.encode(n,"🌾"),t.alike(n,e.state(5,20,a.from("🌾\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"))),e.string.encode(n,"høsten er fin"),t.alike(n,e.state(20,20,a.from("🌾høsten er fin"))),n.start=0,t.is(e.string.decode(n),"🌾"),t.is(e.string.decode(n),"høsten er fin"),t.is(n.start,n.end),t.exception(()=>e.string.decode(n))}),t("raw string",function(t){const n=e.state();e.raw.string.preencode(n,"hello"),t.alike(n,e.state(0,5)),e.raw.string.preencode(n," world"),t.alike(n,e.state(0,11)),n.buffer=a.alloc(n.end),e.raw.string.encode(n,"hello"),e.raw.string.encode(n," world"),t.alike(n,e.state(11,11,a.from("hello world"))),n.start=0,t.is(e.raw.string.decode(n),"hello world"),t.is(e.raw.string.decode(n),"")}),t("fixed32",function(t){const n=e.state();e.fixed32.preencode(n,a.alloc(32).fill("a")),t.alike(n,e.state(0,32)),e.fixed32.preencode(n,a.alloc(32).fill("b")),t.alike(n,e.state(0,64)),n.buffer=a.alloc(n.end),e.fixed32.encode(n,a.alloc(32).fill("a")),t.alike(n,e.state(32,64,a.alloc(64).fill("a",0,32))),e.fixed32.encode(n,a.alloc(32).fill("b")),t.alike(n,e.state(64,64,a.alloc(64).fill("a",0,32).fill("b",32,64))),n.start=0,t.alike(e.fixed32.decode(n),a.alloc(32).fill("a")),t.alike(e.fixed32.decode(n),a.alloc(32).fill("b")),t.is(n.start,n.end),t.exception(()=>e.fixed32.decode(n))}),t("fixed64",function(t){const n=e.state();e.fixed64.preencode(n,a.alloc(64).fill("a")),t.alike(n,e.state(0,64)),e.fixed64.preencode(n,a.alloc(64).fill("b")),t.alike(n,e.state(0,128)),n.buffer=a.alloc(n.end),e.fixed64.encode(n,a.alloc(64).fill("a")),t.alike(n,e.state(64,128,a.alloc(128).fill("a",0,64))),e.fixed64.encode(n,a.alloc(64).fill("b")),t.alike(n,e.state(128,128,a.alloc(128).fill("a",0,64).fill("b",64,128))),n.start=0,t.alike(e.fixed64.decode(n),a.alloc(64).fill("a")),t.alike(e.fixed64.decode(n),a.alloc(64).fill("b")),t.is(n.start,n.end),t.exception(()=>e.fixed64.decode(n))}),t("fixed n",function(t){const n=e.state(),o=e.fixed(3);o.preencode(n,a.alloc(3).fill("a")),t.alike(n,e.state(0,3)),o.preencode(n,a.alloc(3).fill("b")),t.alike(n,e.state(0,6)),n.buffer=a.alloc(n.end),o.encode(n,a.alloc(3).fill("a")),t.alike(n,e.state(3,6,a.alloc(6).fill("a",0,3))),o.encode(n,a.alloc(3).fill("b")),t.alike(n,e.state(6,6,a.alloc(6).fill("a",0,3).fill("b",3,6))),n.start=0,t.alike(o.decode(n),a.alloc(3).fill("a")),t.alike(o.decode(n),a.alloc(3).fill("b")),t.is(n.start,n.end),t.exception(()=>o.decode(n)),n.start=4,t.exception(()=>o.decode(n))}),t("error for incorrect buffer sizes when encoding fixed-length buffers",function(t){const n=a.from("aa","hex"),o=a.from("aa".repeat(500),"hex");t.exception(()=>e.encode(e.fixed32,n),/Incorrect buffer size/),t.exception(()=>e.encode(e.fixed64,n),/Incorrect buffer size/),t.exception(()=>e.encode(e.fixed(100),n),/Incorrect buffer size/),t.exception(()=>e.encode(e.fixed32,o),/Incorrect buffer size/),t.exception(()=>e.encode(e.fixed64,o),/Incorrect buffer size/),t.exception(()=>e.encode(e.fixed(100),o),/Incorrect buffer size/)}),t("array",function(t){const n=e.state(),o=e.array(e.bool);o.preencode(n,[!0,!1,!0]),t.alike(n,e.state(0,4)),o.preencode(n,[!1,!1,!0,!0]),t.alike(n,e.state(0,9)),n.buffer=a.alloc(n.end),o.encode(n,[!0,!1,!0]),t.alike(n,e.state(4,9,a.from([3,1,0,1,0,0,0,0,0]))),o.encode(n,[!1,!1,!0,!0]),t.alike(n,e.state(9,9,a.from([3,1,0,1,4,0,0,1,1]))),n.start=0,t.alike(o.decode(n),[!0,!1,!0]),t.alike(o.decode(n),[!1,!1,!0,!0]),t.is(n.start,n.end),t.exception(()=>o.decode(n))}),t("raw array",function(t){const n=e.state(),o=e.raw.array(e.bool);o.preencode(n,[!0]),t.alike(n,e.state(0,1)),o.preencode(n,[!0]),t.alike(n,e.state(0,2)),n.buffer=a.alloc(n.end),o.encode(n,[!0]),t.alike(n,e.state(1,2,a.from([1,0]))),o.encode(n,[!0]),t.alike(n,e.state(2,2,a.from([1,1]))),n.start=0,t.alike(o.decode(n),[!0,!0]),t.alike(o.decode(n),[])}),t("json",function(t){const n=e.state();e.json.preencode(n,{a:1,b:2}),t.alike(n,e.state(0,14)),n.buffer=a.alloc(n.end),e.json.encode(n,{a:1,b:2}),t.alike(n,e.state(14,14,a.concat([a.from([13]),a.from('{"a":1,"b":2}')]))),n.start=0,t.alike(e.json.decode(n),{a:1,b:2}),t.exception(()=>e.json.decode(n))}),t("raw json",function(t){const n=e.state();e.raw.json.preencode(n,{a:1,b:2}),t.alike(n,e.state(0,13)),n.buffer=a.alloc(n.end),e.raw.json.encode(n,{a:1,b:2}),t.alike(n,e.state(13,13,a.from('{"a":1,"b":2}'))),n.start=0,t.alike(e.raw.json.decode(n),{a:1,b:2}),t.exception(()=>e.json.decode(n))}),t("lexint: big numbers",function(t){t.plan(1);let n,o=e.encode(e.lexint,0),r=1;for(n=1;n<Number.MAX_VALUE;n+=r){const t=e.encode(e.lexint,n);if(a.compare(t,o)<1)break;o=t,r=1+Math.pow(245,Math.ceil(Math.log(n)/Math.log(256)))}t.is(n,1/0)}),t("lexint: range precision",function(t){t.plan(2);const a=1e55,n=10000000000001e42,o=e.encode(e.lexint,a).toString("hex"),r=e.encode(e.lexint,n).toString("hex");t.not(a,n),t.not(o,r)}),t("lexint: range precision",function(t){let n=e.encode(e.lexint,0);for(let o=0,r=1e55;o<1e3;r=1e55+1e46*++o){const o=e.encode(e.lexint,r);a.compare(o,n)<1&&t.fail("cur <= prev"),n=o}t.ok(!0),t.end()}),t("lexint: small numbers",function(t){let n=e.encode(e.lexint,0);for(let o=1;o<1048576;o++){const r=e.encode(e.lexint,o);a.compare(r,n)<1&&t.fail("cur <= prev"),n=r}t.ok(!0),t.end()}),t("lexint: throws",function(t){t.exception(()=>{e.decode(e.lexint,a.alloc(1,251))});let n=252;const o=e.state();e.lexint.preencode(o,n),o.buffer=a.alloc(o.end-o.start),e.lexint.encode(o,n),t.exception(()=>{e.decode(e.lexint,o.buffer.subarray(0,o.buffer.byteLength-2))}),n<<=8,o.start=0,o.end=0,o.buffer=null,e.lexint.preencode(o,n),o.buffer=a.alloc(o.end-o.start),e.lexint.encode(o,n),t.exception(()=>{e.decode(e.lexint,o.buffer.subarray(0,o.buffer.byteLength-2))}),n<<=8,o.start=0,o.end=0,o.buffer=null,e.lexint.preencode(o,n),o.buffer=a.alloc(o.end-o.start),e.lexint.encode(o,n),t.exception(()=>{e.decode(e.lexint,o.buffer.subarray(0,o.buffer.byteLength-2))}),n*=256,o.start=0,o.end=0,o.buffer=null,e.lexint.preencode(o,n),o.buffer=a.alloc(o.end-o.start),e.lexint.encode(o,n),t.exception(()=>{e.decode(e.lexint,o.buffer.subarray(0,o.buffer.byteLength-2))}),n*=65536,o.start=0,o.end=0,o.buffer=null,e.lexint.preencode(o,n),o.buffer=a.alloc(o.end-o.start),e.lexint.encode(o,n),t.exception(()=>{e.decode(e.lexint,o.buffer.subarray(0,o.buffer.byteLength-2))}),t.end()}),t("lexint: unpack",function(t){let a,n=1;for(a=1;a<Number.MAX_VALUE;a+=n){const t=e.encode(e.lexint,a);o(a,e.decode(e.lexint,t)),n=1+Math.pow(245,Math.ceil(Math.log(a)/Math.log(256)))}function o(e,a){const n=e+" !=~ "+a;/e\+\d+$/.test(e)||/e\+\d+$/.test(a)?String(e).slice(0,8)===String(a).slice(0,8)&&/e\+(\d+)$/.exec(e)[1]===/e\+(\d+)$/.exec(a)[1]||t.fail(n):String(e).slice(0,8)===String(a).slice(0,8)&&String(e).length===String(a).length||t.fail(n)}t.is(a,1/0),t.end()}),t("date",function(t){const a=new Date;t.alike(e.decode(e.date,e.encode(e.date,a)),a)}),t("any",function(t){const a={hello:"world",num:42,neg:-42,arr:[{yes:1},{no:!1}],nest:{},today:new Date,float:.54};t.alike(e.decode(e.any,e.encode(e.any,a)),a);const n=new Array(3);t.alike(e.decode(e.any,e.encode(e.any,n)),[null,null,null])}),t("framed",function(t){const n=e.frame(e.uint);t.alike(e.encode(n,42),a.from([1,42])),t.alike(e.decode(n,a.from([1,42])),42),t.alike(e.encode(n,4200),a.from([3,253,104,16])),t.alike(e.decode(n,a.from([3,253,104,16])),4200)}),t("port",function(t){const a=Buffer.from([52,18]);t.alike(e.encode(e.port,4660),a),t.alike(e.decode(e.port,a),4660)}),t("ipv4",function(t){const a="1.2.3.4",n=Buffer.from([1,2,3,4]);t.alike(e.encode(e.ipv4,a),n),t.alike(e.decode(e.ipv4,n),a)}),t("ipv4 + port",function(t){const a="1.2.3.4";t.alike(e.decode(e.ipv4Address,e.encode(e.ipv4Address,{host:a,port:1234})),{host:a,family:4,port:1234})}),t("ipv6",function(t){const a="1:2:3:4:5:6:7:8",n=Buffer.from([0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8]);t.alike(e.encode(e.ipv6,a),n),t.alike(e.decode(e.ipv6,n),a),t.test("abbreviated",function(t){const a=Buffer.from([0,1,0,2,0,0,0,0,0,0,0,0,0,7,0,8]);t.alike(e.encode(e.ipv6,"1:2::7:8"),a),t.alike(e.decode(e.ipv6,a),"1:2:0:0:0:0:7:8")}),t.test("prefix abbreviated",function(t){const a=Buffer.from([0,0,0,0,0,0,0,0,0,5,0,6,0,7,0,8]);t.alike(e.encode(e.ipv6,"::5:6:7:8"),a),t.alike(e.decode(e.ipv6,a),"0:0:0:0:5:6:7:8")}),t.test("suffix abbreviated",function(t){const a=Buffer.from([0,1,0,2,0,3,0,4,0,0,0,0,0,0,0,0]);t.alike(e.encode(e.ipv6,"1:2:3:4::"),a),t.alike(e.decode(e.ipv6,a),"1:2:3:4:0:0:0:0")}),t.test("any",function(t){const a=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);t.alike(e.encode(e.ipv6,"::"),a),t.alike(e.decode(e.ipv6,a),"0:0:0:0:0:0:0:0")}),t.test("lowercase hex",function(t){const a=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,171,205]);t.alike(e.encode(e.ipv6,"::abcd"),a),t.alike(e.decode(e.ipv6,a),"0:0:0:0:0:0:0:abcd")}),t.test("uppercase hex",function(t){const a=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,171,205]);t.alike(e.encode(e.ipv6,"::ABCD"),a),t.alike(e.decode(e.ipv6,a),"0:0:0:0:0:0:0:abcd")})}),t("ipv6 + port",function(t){const a="1:2:3:4:5:6:7:8";t.alike(e.decode(e.ipv6Address,e.encode(e.ipv6Address,{host:a,port:1234})),{host:a,family:6,port:1234})}),t("dual ip",function(t){{const a="1.2.3.4";t.alike(e.decode(e.ip,e.encode(e.ip,a)),a,"ipv4")}{const a="1:2:3:4:5:6:7:8";t.alike(e.decode(e.ip,e.encode(e.ip,a)),a,"ipv6")}}),t("dual ip + port",function(t){const a=1234;{const n="1.2.3.4";t.alike(e.decode(e.ipAddress,e.encode(e.ipAddress,{host:n,port:a})),{host:n,family:4,port:a},"ipv4")}{const n="1:2:3:4:5:6:7:8";t.alike(e.decode(e.ipAddress,e.encode(e.ipAddress,{host:n,port:a})),{host:n,family:6,port:a},"ipv6")}}),t("record",function(t){const a=e.record(e.string,e.string);t.alike(e.decode(a,e.encode(a,{a:"hello",b:"world"})),Object.assign(Object.create(null),{a:"hello",b:"world"}))}),t("record - nested",function(t){const a=e.record(e.string,e.record(e.string,e.string));t.alike(e.decode(a,e.encode(a,{a:{b:"record"},c:{d:"nested",e:"test"}})),Object.assign(Object.create(null),{a:Object.assign(Object.create(null),{b:"record"}),c:Object.assign(Object.create(null),{d:"nested",e:"test"})}))}),t("stringRecord",function(t){t.alike(e.decode(e.stringRecord,e.encode(e.stringRecord,{a:"hello",b:"world"})),Object.assign(Object.create(null),{a:"hello",b:"world"}))});