@@ -322,5 +322,48 @@ describe('DataView task collection', () => {
322322 expect ( result ) . toContain ( '\t- [ ] Child task 1' ) ;
323323 expect ( result ) . toContain ( '\t- [x] Child task 2' ) ;
324324 } ) ;
325+
326+ it ( 'preserves space indentation pattern when outputting' , ( ) => {
327+ // Use 2-space indentation (2 spaces = level 1, 4 spaces = level 2)
328+ sut = new DataViewTaskCollection (
329+ '## Header 1\n\n- [ ] Parent\n - [ ] Child level 1\n - [ ] Child level 2\n'
330+ ) ;
331+
332+ const tasks = sut . getAllTasks ( ) ;
333+ expect ( tasks . length ) . toEqual ( 1 ) ;
334+ expect ( tasks [ 0 ] . hasChildren ( ) ) . toBe ( true ) ;
335+
336+ const result = tasks [ 0 ] . toString ( ) ;
337+ // Should preserve the 2-space pattern
338+ expect ( result ) . toContain ( '- [ ] Parent' ) ;
339+ expect ( result ) . toContain ( ' - [ ] Child level 1' ) ;
340+ expect ( result ) . toContain ( ' - [ ] Child level 2' ) ;
341+ } ) ;
342+
343+ it ( 'handles orphaned sub-tasks when parent indent is skipped' , ( ) => {
344+ // Task at level 2 without a level 1 parent - should be added as top-level
345+ sut = new DataViewTaskCollection (
346+ '## Header 1\n\n- [ ] Parent\n\t\t- [ ] Orphaned child at level 2\n'
347+ ) ;
348+
349+ const tasks = sut . getAllTasks ( ) ;
350+ // The orphaned task should be added as a top-level task since there's no level 1 parent
351+ expect ( tasks . length ) . toEqual ( 2 ) ;
352+ expect ( tasks [ 0 ] . getName ( ) ) . toEqual ( 'Parent' ) ;
353+ expect ( tasks [ 1 ] . getName ( ) ) . toEqual ( 'Orphaned child at level 2' ) ;
354+ } ) ;
355+
356+ it ( 'handles task with due date in toString when dueDate is set' , ( ) => {
357+ sut = new DataViewTaskCollection ( '## Header 1\n\n- [ ] Task with due [due:: 2024-01-15]\n' ) ;
358+
359+ const tasks = sut . getAllTasks ( ) ;
360+ const task = tasks [ 0 ] ;
361+
362+ // Call isDue to set the dueDate property
363+ task . isDue ( ) ;
364+
365+ const result = task . toString ( ) ;
366+ expect ( result ) . toContain ( '[due:: 2024-01-15]' ) ;
367+ } ) ;
325368 } ) ;
326369} ) ;
0 commit comments