Skip to content

Commit ebafd0d

Browse files
jderegclaude
andcommitted
Test: 12 unit tests for new TOON read options (per-instance + permanent)
ReadOptionsBuilderTest: cover the new toonExpandPaths/toonIndentSize per-instance setters and their addPermanent* siblings. Per-instance (7 tests): - toonExpandPaths: default false, toggle, copy-from-source preserves - toonIndentSize: default 2, set-and-read, copy-from-source preserves, rejects 0/negative/Integer.MIN_VALUE via JsonIoException Permanent (5 tests): - addPermanentToonExpandPaths: applies to new options, reset works - addPermanentToonIndentSize: applies to new options, rejects 0/negative/Integer.MIN_VALUE, reset works - All permanent tests use try/finally save-and-restore on BASE_* state so a mid-test failure does not leak into the rest of the suite Full suite: 4486 -> 4498 tests, all passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a4365c9 commit ebafd0d

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

json-io/src/test/java/com/cedarsoftware/io/ReadOptionsBuilderTest.java

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,110 @@ void testStrictToon_Copied() {
143143
ReadOptions copy = new ReadOptionsBuilder(source).build();
144144
assertTrue(copy.isStrictToon());
145145
}
146+
147+
// ========== toonExpandPaths (§13.4) ==========
148+
149+
@Test
150+
void testToonExpandPaths_DefaultFalse() {
151+
ReadOptions options = new ReadOptionsBuilder().build();
152+
assertFalse(options.isToonExpandPaths());
153+
}
154+
155+
@Test
156+
void testToonExpandPaths_EnableAndDisable() {
157+
ReadOptions enabled = new ReadOptionsBuilder().toonExpandPaths(true).build();
158+
assertTrue(enabled.isToonExpandPaths());
159+
160+
ReadOptions disabled = new ReadOptionsBuilder().toonExpandPaths(true).toonExpandPaths(false).build();
161+
assertFalse(disabled.isToonExpandPaths());
162+
}
163+
164+
@Test
165+
void testToonExpandPaths_Copied() {
166+
ReadOptions source = new ReadOptionsBuilder().toonExpandPaths(true).build();
167+
ReadOptions copy = new ReadOptionsBuilder(source).build();
168+
assertTrue(copy.isToonExpandPaths());
169+
}
170+
171+
// ========== toonIndentSize (§12) ==========
172+
173+
@Test
174+
void testToonIndentSize_Default2() {
175+
ReadOptions options = new ReadOptionsBuilder().build();
176+
assertEquals(2, options.getToonIndentSize());
177+
}
178+
179+
@Test
180+
void testToonIndentSize_SetAndRead() {
181+
ReadOptions options = new ReadOptionsBuilder().toonIndentSize(4).build();
182+
assertEquals(4, options.getToonIndentSize());
183+
}
184+
185+
@Test
186+
void testToonIndentSize_Copied() {
187+
ReadOptions source = new ReadOptionsBuilder().toonIndentSize(8).build();
188+
ReadOptions copy = new ReadOptionsBuilder(source).build();
189+
assertEquals(8, copy.getToonIndentSize());
190+
}
191+
192+
@Test
193+
void testToonIndentSize_RejectsZeroAndNegative() {
194+
ReadOptionsBuilder builder = new ReadOptionsBuilder();
195+
assertThrows(JsonIoException.class, () -> builder.toonIndentSize(0));
196+
assertThrows(JsonIoException.class, () -> builder.toonIndentSize(-1));
197+
assertThrows(JsonIoException.class, () -> builder.toonIndentSize(Integer.MIN_VALUE));
198+
}
199+
200+
// ========== addPermanentToonExpandPaths ==========
201+
202+
@Test
203+
void testAddPermanentToonExpandPaths_AppliesToNewOptions() {
204+
boolean originalDefault = new ReadOptionsBuilder().build().isToonExpandPaths();
205+
try {
206+
ReadOptionsBuilder.addPermanentToonExpandPaths(true);
207+
ReadOptions options = new ReadOptionsBuilder().build();
208+
assertTrue(options.isToonExpandPaths());
209+
} finally {
210+
ReadOptionsBuilder.addPermanentToonExpandPaths(originalDefault);
211+
}
212+
}
213+
214+
@Test
215+
void testAddPermanentToonExpandPaths_ResetAfterTest() {
216+
boolean originalDefault = new ReadOptionsBuilder().build().isToonExpandPaths();
217+
ReadOptionsBuilder.addPermanentToonExpandPaths(true);
218+
ReadOptionsBuilder.addPermanentToonExpandPaths(originalDefault);
219+
ReadOptions options = new ReadOptionsBuilder().build();
220+
assertEquals(originalDefault, options.isToonExpandPaths());
221+
}
222+
223+
// ========== addPermanentToonIndentSize ==========
224+
225+
@Test
226+
void testAddPermanentToonIndentSize_AppliesToNewOptions() {
227+
int originalDefault = new ReadOptionsBuilder().build().getToonIndentSize();
228+
try {
229+
ReadOptionsBuilder.addPermanentToonIndentSize(6);
230+
ReadOptions options = new ReadOptionsBuilder().build();
231+
assertEquals(6, options.getToonIndentSize());
232+
} finally {
233+
ReadOptionsBuilder.addPermanentToonIndentSize(originalDefault);
234+
}
235+
}
236+
237+
@Test
238+
void testAddPermanentToonIndentSize_RejectsZeroAndNegative() {
239+
assertThrows(JsonIoException.class, () -> ReadOptionsBuilder.addPermanentToonIndentSize(0));
240+
assertThrows(JsonIoException.class, () -> ReadOptionsBuilder.addPermanentToonIndentSize(-1));
241+
assertThrows(JsonIoException.class, () -> ReadOptionsBuilder.addPermanentToonIndentSize(Integer.MIN_VALUE));
242+
}
243+
244+
@Test
245+
void testAddPermanentToonIndentSize_ResetAfterTest() {
246+
int originalDefault = new ReadOptionsBuilder().build().getToonIndentSize();
247+
ReadOptionsBuilder.addPermanentToonIndentSize(7);
248+
ReadOptionsBuilder.addPermanentToonIndentSize(originalDefault);
249+
ReadOptions options = new ReadOptionsBuilder().build();
250+
assertEquals(originalDefault, options.getToonIndentSize());
251+
}
146252
}

0 commit comments

Comments
 (0)