import { CborByte } from "."; describe("CborByte", () => { describe("encode", () => { describe("when encoding f1980ebcf616bc54b2206795bbec8a9217613de6c4fc041158b581d4", () => { test("should return 581cf1980ebcf616bc54b2206795bbec8a9217613de6c4fc041158b581d4", () => { expect( CborByte.encode( "f1980ebcf616bc54b2206795bbec8a9217613de6c4fc041158b581d4" ) ).toBe("581cf1980ebcf616bc54b2206795bbec8a9217613de6c4fc041158b581d4"); }); }); describe("when encoding 4D7574616E7443726F633032", () => { test("should return 4c4D7574616E7443726F633032", () => { expect(CborByte.encode("4D7574616E7443726F633032")).toBe( "4c4D7574616E7443726F633032" ); }); }); describe("when encoding 4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e", () => { test("should return 574d7574616e7443726f6330324d7574616e6e6e6e6e6e6e", () => { expect( CborByte.encode("4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e") ).toBe("574d7574616e7443726f6330324d7574616e6e6e6e6e6e6e"); }); }); describe("when encoding 4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e", () => { test("should return 582e4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e", () => { expect( CborByte.encode( "4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e" ) ).toBe( "582e4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e4d7574616e7443726f6330324d7574616e6e6e6e6e6e6e" ); }); }); describe("when encoding a value with 276 bytes", () => { test("should return the 590114 as length", () => { const value = "4".repeat(276 * 2); expect(CborByte.encode(value)).toBe("590114" + "4".repeat(276 * 2)); }); }); describe("when encoding a value with 276 bytes", () => { test("should return the 590114 as length", () => { const value = "4".repeat(276 * 2); expect(CborByte.encode(value)).toBe("590114" + "4".repeat(276 * 2)); }); }); describe("when encoding a value with more than 65535 bytes", () => { test("should throw as not supported", () => { const value = "4".repeat(65536 * 2); expect(() => CborByte.encode(value)).toThrow( "Byte is too long, not supported" ); }); }); }); describe("read", () => { test("case 1", () => { expect( CborByte.read("5750726F6A656374576967687473496368696D6933393137") ).toBe("50726F6A656374576967687473496368696D6933393137"); }); }); });