fix: EOF ends game loop (ConsoleIO returns null on EOF); settings.json excluded from save slots

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-01 15:39:08 +02:00
parent 8a8700994c
commit 9d3056d53e
4 changed files with 51 additions and 5 deletions

View File

@@ -50,6 +50,25 @@ class ConsoleIORenderTest {
assertThat(out).contains("Kitchen").contains("turn 7").contains("light: off");
}
@Test
void readLine_returnsNullOnEof() {
ByteArrayOutputStream sink = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(sink, true, StandardCharsets.UTF_8);
ConsoleIO io = new ConsoleIO(new BufferedReader(new StringReader("")), ps,
ConsoleIO.ColorMode.OFF, ConsoleIO.GlyphMode.UNICODE);
assertThat(io.readLine()).isNull();
}
@Test
void readLine_returnsEmptyStringForBlankLineThenNullAtEof() {
ByteArrayOutputStream sink = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(sink, true, StandardCharsets.UTF_8);
ConsoleIO io = new ConsoleIO(new BufferedReader(new StringReader("\n")), ps,
ConsoleIO.ColorMode.OFF, ConsoleIO.GlyphMode.UNICODE);
assertThat(io.readLine()).isEqualTo(""); // blank interactive line, re-prompt
assertThat(io.readLine()).isNull(); // stream now exhausted → EOF
}
@Test
void asciiGlyphMode_usesPlusDashFrame() {
ByteArrayOutputStream sink = new ByteArrayOutputStream();

View File

@@ -55,6 +55,23 @@ class SaveServiceTest {
assertThat(new SaveService(dir).list()).isEmpty();
}
@Test
void listExcludesSettingsFile(@TempDir Path dir) throws Exception {
SaveService svc = new SaveService(dir);
GameSession s = freshSession("Real Save");
svc.save(s);
Files.writeString(dir.resolve("settings.json"), "{\"color\":\"on\"}");
List<SaveSlotInfo> slots = svc.list();
assertThat(slots).hasSize(1);
assertThat(slots.getFirst().slotName()).isEqualTo("Real Save");
}
@Test
void slugForSettingsDoesNotCollideWithSettingsFile() {
assertThat(SaveService.slug("settings")).isNotEqualTo("settings");
}
@Test
void loadCorruptFileThrowsSaveException(@TempDir Path dir) throws Exception {
Files.writeString(dir.resolve("bad.json"), "{ not json");