UNPKG

@pdfme/pdf-lib

Version:

Create and modify PDF files with JavaScript

39 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("../../../src/core"); const utils_1 = require("../../../src/utils"); describe(`PDFNumber`, () => { it(`can be constructed from PDFNumber.of(...)`, () => { expect(core_1.PDFNumber.of(21)).toBeInstanceOf(core_1.PDFNumber); expect(core_1.PDFNumber.of(-43)).toBeInstanceOf(core_1.PDFNumber); expect(core_1.PDFNumber.of(-0.1e7)).toBeInstanceOf(core_1.PDFNumber); }); it(`can be cloned`, () => { const original = core_1.PDFNumber.of(-21.42); const clone = original.clone(); expect(clone).not.toBe(original); expect(clone.toString()).toBe(original.toString()); }); it(`can be converted to a string`, () => { expect(String(core_1.PDFNumber.of(21))).toEqual('21'); expect(String(core_1.PDFNumber.of(-43))).toEqual('-43'); expect(String(core_1.PDFNumber.of(3.403e38))).toEqual('340300000000000000000000000000000000000'); expect(String(core_1.PDFNumber.of(-3.403e38))).toEqual('-340300000000000000000000000000000000000'); expect(String(core_1.PDFNumber.of(-3.403e-38))).toContain('-0.00000000000000000000000000000000000003403'); }); it(`can provide its size in bytes`, () => { expect(core_1.PDFNumber.of(21).sizeInBytes()).toBe(2); expect(core_1.PDFNumber.of(-43).sizeInBytes()).toBe(3); expect(core_1.PDFNumber.of(3.403e38).sizeInBytes()).toBe(39); expect(core_1.PDFNumber.of(-3.403e38).sizeInBytes()).toBe(40); }); it(`can be serialized`, () => { const buffer1 = new Uint8Array(8).fill((0, utils_1.toCharCode)(' ')); expect(core_1.PDFNumber.of(21).copyBytesInto(buffer1, 3)).toBe(2); expect(buffer1).toEqual((0, utils_1.typedArrayFor)(' 21 ')); const buffer2 = new Uint8Array(40).fill((0, utils_1.toCharCode)(' ')); expect(core_1.PDFNumber.of(-3.403e38).copyBytesInto(buffer2, 0)).toBe(40); expect(buffer2).toEqual((0, utils_1.typedArrayFor)('-340300000000000000000000000000000000000')); }); }); //# sourceMappingURL=PDFNumber.spec.js.map