From adf06af59850684a378173609c89f156bee1236e Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sat, 14 Nov 2026 20:35:47 -0700 Subject: [PATCH] Accept score answers with surrounding whitespace Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- .../parpt/command/CreateProjectCommand.java | 3 ++- .../command/CreateProjectCommandTest.java | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5549d16..75c463a 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Project names are matched exactly, including capitalization and spaces. `view "m You'll be prompted to enter: - Project name and description - Detailed scoring for each category (1-5 scale): each category asks four questions, and its score is their average, rounded to the nearest whole number -- Each answer must be a whole number from 1 to 5. Any other answer prints `Invalid score. Must be between 1 and 5.` (or `Invalid score. Must be a number between 1 and 5.` when it is not a number), and that category's four questions are asked again from the first; answers already given for it are discarded +- Each answer must be a whole number from 1 to 5; spaces before or after it are ignored. Any other answer prints `Invalid score. Must be between 1 and 5.` (or `Invalid score. Must be a number between 1 and 5.` when it is not a number), and that category's four questions are asked again from the first; answers already given for it are discarded - Entering `q` or `quit` at any prompt (or pressing Ctrl-D) cancels creation without saving anything - Parpt will then: - Calculate ICE and RICE scores diff --git a/src/main/java/com/preponderous/parpt/command/CreateProjectCommand.java b/src/main/java/com/preponderous/parpt/command/CreateProjectCommand.java index 612d1fe..e65a525 100644 --- a/src/main/java/com/preponderous/parpt/command/CreateProjectCommand.java +++ b/src/main/java/com/preponderous/parpt/command/CreateProjectCommand.java @@ -56,7 +56,8 @@ private int getAverageScore(String[] prompts) throws InvalidScoreException, Crea int total = 0; for (String prompt : prompts) { try { - int score = Integer.parseInt(readInput(prompt)); + // Surrounding whitespace is treated as a stray keystroke, as it is for quit tokens + int score = Integer.parseInt(readInput(prompt).trim()); if (!InputValidator.isValidScore(score)) { throw new InvalidScoreException("Invalid score. Must be between 1 and 5."); } diff --git a/src/test/java/com/preponderous/parpt/command/CreateProjectCommandTest.java b/src/test/java/com/preponderous/parpt/command/CreateProjectCommandTest.java index dc04783..0dc49b9 100644 --- a/src/test/java/com/preponderous/parpt/command/CreateProjectCommandTest.java +++ b/src/test/java/com/preponderous/parpt/command/CreateProjectCommandTest.java @@ -323,6 +323,26 @@ void testNonNumericAnswerReprompts() throws Exception { assertEquals(4, projectService.getProject("Numeric Project").getEffort()); } + @Test + void testScoreAnswerWithSurroundingWhitespaceIsAccepted() throws Exception { + String[] reachPrompts = promptProperties.getReach(); + String[] paddedAnswers = {" 3 ", "3\t", " 3", "3 "}; + for (int i = 0; i < reachPrompts.length; i++) { + // A second ask quits, so a rejected padded answer fails the assertion instead of looping + when(inputProvider.readLine(reachPrompts[i])).thenReturn(paddedAnswers[i], "q"); + } + + String output = captureStandardOutput(() -> assertEquals( + "Project created successfully: Padded Project\nICE Score: 125.00\nRICE Score: 15.00", + command.execute("Padded Project", "Padded Description", 5, 5, 5, null, 5))); + + assertFalse(output.contains("Invalid score")); + for (String prompt : reachPrompts) { + verify(inputProvider, times(1)).readLine(prompt); + } + assertEquals(3, projectService.getProject("Padded Project").getReach()); + } + @Test void testTakenNameAtPromptIsRejectedBeforeAnyFurtherQuestion() throws Exception { projectService.createProject("Existing Project", "Original Description", 1, 1, 1, 1, 1);