UNPKG

list-open-files

Version:
132 lines 6.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); describe("toInteger", () => { it("should return numbers as is", () => { expect(utils_1.toInteger(-100)).toBe(-100); expect(utils_1.toInteger(-1)).toBe(-1); expect(utils_1.toInteger(0)).toBe(0); expect(utils_1.toInteger(1)).toBe(1); expect(utils_1.toInteger(100)).toBe(100); expect(utils_1.toInteger(Infinity)).toBe(Infinity); expect(utils_1.toInteger(-Infinity)).toBe(-Infinity); expect(utils_1.toInteger(NaN)).toBe(NaN); }); it("should parse decimal string by default", () => { expect(utils_1.toInteger("-100")).toBe(-100); expect(utils_1.toInteger("-1")).toBe(-1); expect(utils_1.toInteger("0")).toBe(0); expect(utils_1.toInteger("1")).toBe(1); expect(utils_1.toInteger("100")).toBe(100); expect(utils_1.toInteger("Infinity")).toBe(NaN); expect(utils_1.toInteger("-Infinity")).toBe(NaN); expect(utils_1.toInteger("NaN")).toBe(NaN); }); it("should parse decimal string explicitly", () => { expect(utils_1.toInteger("0t-100")).toBe(-100); expect(utils_1.toInteger("0t-1")).toBe(-1); expect(utils_1.toInteger("0t0")).toBe(0); expect(utils_1.toInteger("0t1")).toBe(1); expect(utils_1.toInteger("0t100")).toBe(100); expect(utils_1.toInteger("0tInfinity")).toBe(NaN); expect(utils_1.toInteger("0t-Infinity")).toBe(NaN); expect(utils_1.toInteger("0tNaN")).toBe(NaN); }); it("should parse hexadecimal string explicitly", () => { expect(utils_1.toInteger("0x-100")).toBe(-256); expect(utils_1.toInteger("0x-1")).toBe(-1); expect(utils_1.toInteger("0x0")).toBe(0); expect(utils_1.toInteger("0x1")).toBe(1); expect(utils_1.toInteger("0x100")).toBe(256); expect(utils_1.toInteger("0xInfinity")).toBe(NaN); expect(utils_1.toInteger("0x-Infinity")).toBe(NaN); expect(utils_1.toInteger("0xNaN")).toBe(NaN); }); }); describe("tryToInteger", () => { describe("don't default to raw", () => { it("should return numbers as is", () => { expect(utils_1.tryToInteger(-100)).toBe(-100); expect(utils_1.tryToInteger(-1)).toBe(-1); expect(utils_1.tryToInteger(0)).toBe(0); expect(utils_1.tryToInteger(1)).toBe(1); expect(utils_1.tryToInteger(100)).toBe(100); expect(utils_1.tryToInteger(Infinity)).toBe(Infinity); expect(utils_1.tryToInteger(-Infinity)).toBe(-Infinity); expect(utils_1.tryToInteger(NaN)).toBe(NaN); }); it("should parse decimal string by default", () => { expect(utils_1.tryToInteger("-100")).toBe(-100); expect(utils_1.tryToInteger("-1")).toBe(-1); expect(utils_1.tryToInteger("0")).toBe(0); expect(utils_1.tryToInteger("1")).toBe(1); expect(utils_1.tryToInteger("100")).toBe(100); expect(utils_1.tryToInteger("Infinity")).toBe(NaN); expect(utils_1.tryToInteger("-Infinity")).toBe(NaN); expect(utils_1.tryToInteger("NaN")).toBe(NaN); }); it("should parse decimal string explicitly", () => { expect(utils_1.tryToInteger("0t-100")).toBe(-100); expect(utils_1.tryToInteger("0t-1")).toBe(-1); expect(utils_1.tryToInteger("0t0")).toBe(0); expect(utils_1.tryToInteger("0t1")).toBe(1); expect(utils_1.tryToInteger("0t100")).toBe(100); expect(utils_1.tryToInteger("0tInfinity")).toBe(NaN); expect(utils_1.tryToInteger("0t-Infinity")).toBe(NaN); expect(utils_1.tryToInteger("0tNaN")).toBe(NaN); }); it("should parse hexadecimal string explicitly", () => { expect(utils_1.tryToInteger("0x-100")).toBe(-256); expect(utils_1.tryToInteger("0x-1")).toBe(-1); expect(utils_1.tryToInteger("0x0")).toBe(0); expect(utils_1.tryToInteger("0x1")).toBe(1); expect(utils_1.tryToInteger("0x100")).toBe(256); expect(utils_1.tryToInteger("0xInfinity")).toBe(NaN); expect(utils_1.tryToInteger("0x-Infinity")).toBe(NaN); expect(utils_1.tryToInteger("0xNaN")).toBe(NaN); }); }); describe("default to raw", () => { it("should return numbers as is", () => { expect(utils_1.tryToInteger(-100, true)).toBe(-100); expect(utils_1.tryToInteger(-1, true)).toBe(-1); expect(utils_1.tryToInteger(0, true)).toBe(0); expect(utils_1.tryToInteger(1, true)).toBe(1); expect(utils_1.tryToInteger(100, true)).toBe(100); expect(utils_1.tryToInteger(Infinity, true)).toBe(Infinity); expect(utils_1.tryToInteger(-Infinity, true)).toBe(-Infinity); expect(utils_1.tryToInteger(NaN, true)).toBe(NaN); }); it("should parse decimal string by default", () => { expect(utils_1.tryToInteger("-100", true)).toBe(-100); expect(utils_1.tryToInteger("-1", true)).toBe(-1); expect(utils_1.tryToInteger("0", true)).toBe(0); expect(utils_1.tryToInteger("1", true)).toBe(1); expect(utils_1.tryToInteger("100", true)).toBe(100); expect(utils_1.tryToInteger("Infinity", true)).toBe("Infinity"); expect(utils_1.tryToInteger("-Infinity", true)).toBe("-Infinity"); expect(utils_1.tryToInteger("NaN", true)).toBe("NaN"); }); it("should parse decimal string explicitly", () => { expect(utils_1.tryToInteger("0t-100", true)).toBe(-100); expect(utils_1.tryToInteger("0t-1", true)).toBe(-1); expect(utils_1.tryToInteger("0t0", true)).toBe(0); expect(utils_1.tryToInteger("0t1", true)).toBe(1); expect(utils_1.tryToInteger("0t100", true)).toBe(100); expect(utils_1.tryToInteger("0tInfinity", true)).toBe("0tInfinity"); expect(utils_1.tryToInteger("0t-Infinity", true)).toBe("0t-Infinity"); expect(utils_1.tryToInteger("0tNaN", true)).toBe("0tNaN"); }); it("should parse hexadecimal string explicitly", () => { expect(utils_1.tryToInteger("0x-100", true)).toBe(-256); expect(utils_1.tryToInteger("0x-1", true)).toBe(-1); expect(utils_1.tryToInteger("0x0", true)).toBe(0); expect(utils_1.tryToInteger("0x1", true)).toBe(1); expect(utils_1.tryToInteger("0x100", true)).toBe(256); expect(utils_1.tryToInteger("0xInfinity", true)).toBe("0xInfinity"); expect(utils_1.tryToInteger("0x-Infinity", true)).toBe("0x-Infinity"); expect(utils_1.tryToInteger("0xNaN", true)).toBe("0xNaN"); }); }); }); //# sourceMappingURL=utils.spec.js.map