From: Ardis Lu Date: Sat, 13 Jan 2024 06:54:02 +0000 (-0800) Subject: Add special exit case for no input X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=dc696717a60262e82736be314374923d5cda4a01;p=seed-phrase-transposer Add special exit case for no input The original message for no input ("Seed phrase of length 1 can't be arranged into a grid") does not make sense. --- diff --git a/main.ts b/main.ts index 9270ab0..2f77e63 100644 --- a/main.ts +++ b/main.ts @@ -68,6 +68,13 @@ export function getLowerFactors(num: number): Array { */ export function main() { const input = prompt("Seed phrase:"); + if (input === "") { + console.error( + "%c\nNo input provided. Enter a seed phrase to check permutations.", + "color: red", + ); + Deno.exit(0); + } const words = parseInput(input); const factors = getLowerFactors(words.length); if (factors.length === 0) { diff --git a/main_test.ts b/main_test.ts index 7ab078d..27fe3ac 100644 --- a/main_test.ts +++ b/main_test.ts @@ -212,3 +212,18 @@ Deno.test("main exits cleanly on a malformed seed phrase", () => { consoleSpy.restore(); promptStub.restore(); }); + +Deno.test("main exits cleanly on no input", () => { + const consoleSpy = spy(console, "error"); + const promptStub = stub( + globalThis, + "prompt", + () => "", + ); + + assertThrows(main); + assertSpyCalls(consoleSpy, 1); + + consoleSpy.restore(); + promptStub.restore(); +});