From d20f3fd7d64d14e0329fd02399be77d9d6bfffd3 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 1 Jun 2026 20:23:41 +0200 Subject: [PATCH] fix(command): combined unknown-target message; cover both go-to summary forms - UX: unknown-target message now reads "don't know any direction or place called '...'" so direction typos (e.g. 'go nroth') make sense - clarity: resolveVisited uses equalsIgnoreCase for id/name matching; add null-world guard comment pointing to CommandTestSupport - Javadoc: note that 'to' filler word is stripped, making go-to forms equivalent - tests: assert 'through the Hallway' in 3-node route; update unknown message assertion; add adjacentWalkUsesShortSummary covering the n==2 short-form path Co-Authored-By: Claude Sonnet 4.6 --- .../jeanluc/adventure/command/impl/GoCommand.java | 8 +++++--- .../adventure/command/impl/GoCommandPathTest.java | 12 +++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java index d5b589b..ecea4df 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/GoCommand.java @@ -18,7 +18,8 @@ import java.util.Optional; * Moves the player. {@code go } steps once to a connected room. * {@code go to } auto-walks the shortest path (BFS) over already-visited * rooms, honouring locked exits and darkness. Usage: {@code go } or - * {@code go to }. + * {@code go to }. The parser strips the filler word "to", so "go to + * <room>" and "go <room>" are equivalent. */ public class GoCommand implements Command { @@ -63,7 +64,7 @@ public class GoCommand implements Command { String name = String.join(" ", args).toLowerCase(); Room target = resolveVisited(ctx, name); if (target == null) { - ctx.getIo().write("You don't know any place called '" + name + "'."); + ctx.getIo().write("You don't know any direction or place called '" + name + "'."); return; } Room start = ctx.getPlayer().getCurrentRoom(); @@ -90,6 +91,7 @@ public class GoCommand implements Command { /** Finds a visited room whose id or display name matches {@code name}. */ private Room resolveVisited(GameContext ctx, String name) { + // the command test harness (CommandTestSupport) uses a null world; production always has one if (ctx.getWorld() == null) { return null; } @@ -98,7 +100,7 @@ public class GoCommand implements Command { if (r == null) { continue; } - if (id.equals(name) || r.getName().toLowerCase().equals(name)) { + if (id.equalsIgnoreCase(name) || r.getName().equalsIgnoreCase(name)) { return r; } } diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java index 3fafb60..b980b49 100644 --- a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/command/impl/GoCommandPathTest.java @@ -51,6 +51,7 @@ class GoCommandPathTest { new GoCommand().execute(ctx, List.of("library")); assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("library"); assertThat(out(ctx)).contains("make your way"); + assertThat(out(ctx)).contains("through the Hallway"); } @Test @@ -66,7 +67,7 @@ class GoCommandPathTest { GameContext ctx = world(false, "Library"); new GoCommand().execute(ctx, List.of("dungeon")); assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("kitchen"); - assertThat(out(ctx)).contains("don't know any place called 'dungeon'"); + assertThat(out(ctx)).contains("don't know any direction or place called 'dungeon'"); } @Test @@ -90,4 +91,13 @@ class GoCommandPathTest { new GoCommand().execute(ctx, List.of("north")); assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("hallway"); } + + @Test + void adjacentWalkUsesShortSummary() { + GameContext ctx = world(false, "Library"); + new GoCommand().execute(ctx, List.of("hallway")); + assertThat(ctx.getPlayer().getCurrentRoom().getId()).isEqualTo("hallway"); + assertThat(out(ctx)).contains("make your way from the Kitchen to the Hallway"); + assertThat(out(ctx)).doesNotContain("through"); + } }