1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:38:10 +00:00

Spreadsheet: Allow integer() to throw in weird cases

Also makes numericResolve use parseInt to avoid using our own integer()
This commit is contained in:
u9g 2022-03-04 02:30:37 +00:00 committed by Ali Mohammad Pur
parent 75a02300ba
commit 4147b56e79
2 changed files with 37 additions and 1 deletions

View file

@ -203,3 +203,36 @@ describe("Lookup", () => {
expect(reflookup("80", R`A0:A9`, R`B0:B9`, undefined, "nextlargest").name).toEqual("B9");
});
});
describe("integer() function", () => {
test("undefined", () => {
expect(() => integer(undefined)).toThrow(Error);
});
test("null", () => {
expect(() => integer(null)).toThrow(Error);
});
test("NaN", () => {
expect(() => integer(NaN)).toThrow(Error);
});
test("object", () => {
expect(() => integer({})).toThrow(Error);
});
test("function", () => {
expect(() => integer(() => {})).toThrow(Error);
});
test("try 1 as string", () => {
expect(integer("1")).toBe(1);
});
test("try 1 as number", () => {
expect(integer(1)).toBe(1);
});
test("try 1000000 as string", () => {
expect(integer("1000000")).toBe(1000000);
});
test("try 1000000 as number", () => {
expect(integer(1000000)).toBe(1000000);
});
test("don't just allow any strings", () => {
expect(() => integer("is this NaN yet?")).toThrow();
});
});