@@ -270,6 +270,58 @@ public function testLoadToctreeSkipsMissingEntryByDefault()
270270 }
271271 }
272272
273+ public function testConstructorRejectsNegativeMaxDepth ()
274+ {
275+ $ this ->expectException (InvalidArgumentException::class);
276+ $ this ->expectExceptionMessage ('The maximum depth must be a non-negative integer or null, -1 given. ' );
277+ new RstToctreeLoader (maxDepth: -1 );
278+ }
279+
280+ public function testMaxDepthZeroLoadsOnlySourceFile ()
281+ {
282+ $ loader = new RstToctreeLoader (maxDepth: 0 );
283+ $ documents = iterator_to_array ($ loader ->load ($ this ->fixturesDir .'/with_absolute_toctree/index.rst ' ), false );
284+
285+ $ titles = array_map (
286+ static fn (EmbeddableDocumentInterface $ doc ): string => $ doc ->getMetadata ()->getTitle () ?? '' ,
287+ $ documents ,
288+ );
289+
290+ $ this ->assertContains ('Main Documentation ' , $ titles );
291+ $ this ->assertNotContains ('Getting Started ' , $ titles );
292+ $ this ->assertNotContains ('Setup ' , $ titles );
293+ }
294+
295+ public function testMaxDepthOneFollowsDirectEntriesOnly ()
296+ {
297+ $ loader = new RstToctreeLoader (maxDepth: 1 );
298+ $ documents = iterator_to_array ($ loader ->load ($ this ->fixturesDir .'/with_absolute_toctree/index.rst ' ), false );
299+
300+ $ titles = array_map (
301+ static fn (EmbeddableDocumentInterface $ doc ): string => $ doc ->getMetadata ()->getTitle () ?? '' ,
302+ $ documents ,
303+ );
304+
305+ $ this ->assertContains ('Main Documentation ' , $ titles );
306+ $ this ->assertContains ('Getting Started ' , $ titles );
307+ $ this ->assertNotContains ('Setup ' , $ titles );
308+ }
309+
310+ public function testNullMaxDepthLoadsEntireTree ()
311+ {
312+ $ loader = new RstToctreeLoader (maxDepth: null );
313+ $ documents = iterator_to_array ($ loader ->load ($ this ->fixturesDir .'/with_absolute_toctree/index.rst ' ), false );
314+
315+ $ titles = array_map (
316+ static fn (EmbeddableDocumentInterface $ doc ): string => $ doc ->getMetadata ()->getTitle () ?? '' ,
317+ $ documents ,
318+ );
319+
320+ $ this ->assertContains ('Main Documentation ' , $ titles );
321+ $ this ->assertContains ('Getting Started ' , $ titles );
322+ $ this ->assertContains ('Setup ' , $ titles );
323+ }
324+
273325 public function testLoadSectionOverflowCreatesMultipleChunks ()
274326 {
275327 // Create a temporary file with a very long section
0 commit comments