|
| 1 | +import { extractRangeFromA1Notation } from "@/appsscript"; |
| 2 | +import { IllegalArgumentException } from "@/exception"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | + |
| 5 | +describe("extractRangeFromA1Notation", () => { |
| 6 | + describe("Range Extraction (Success Cases)", () => { |
| 7 | + it("should correctly extract the range from a full A1 notation with unquoted sheet name", () => { |
| 8 | + expect(extractRangeFromA1Notation("Sheet1!A1:B2")).toBe("A1:B2"); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should correctly extract the range from a notation with a quoted sheet name", () => { |
| 12 | + expect(extractRangeFromA1Notation("'My Sheet'!C1:D4")).toBe("C1:D4"); |
| 13 | + }); |
| 14 | + |
| 15 | + it("should return the range when no sheet name is present", () => { |
| 16 | + expect(extractRangeFromA1Notation("E:E")).toBe("E:E"); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should correctly extract a single cell reference", () => { |
| 20 | + expect(extractRangeFromA1Notation("SingleCell!Z99")).toBe("Z99"); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + describe("Error and Exception Handling", () => { |
| 25 | + it("should throw IllegalArgumentException when called with no arguments", () => { |
| 26 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 27 | + expect(() => (extractRangeFromA1Notation as any)()).toThrow( |
| 28 | + IllegalArgumentException |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should throw an exception if the extracted range is an empty string", () => { |
| 33 | + expect(() => extractRangeFromA1Notation("Sheet1!")).toThrow(); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should throw an exception if the input A1 notation is an empty string", () => { |
| 37 | + expect(() => extractRangeFromA1Notation("")).toThrow(); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should throw an error on malformed A1 notation that parseA1Notation cannot handle", () => { |
| 41 | + expect(() => extractRangeFromA1Notation("Sheet1!A1:B2!")).toThrow(); |
| 42 | + }); |
| 43 | + }); |
| 44 | +}); |
0 commit comments