| 1 | program test_tree |
| 2 | use file_tree_module |
| 3 | implicit none |
| 4 | |
| 5 | type(file_entry_t), allocatable :: files(:) |
| 6 | type(tree_node_t), pointer :: root, child |
| 7 | integer :: n_files |
| 8 | |
| 9 | ! Create test data matching current git status |
| 10 | n_files = 3 |
| 11 | allocate(files(n_files)) |
| 12 | |
| 13 | files(1)%path = 'README.md' |
| 14 | files(1)%is_staged = .false. |
| 15 | files(1)%is_unstaged = .true. |
| 16 | files(1)%is_untracked = .false. |
| 17 | files(1)%has_incoming = .false. |
| 18 | |
| 19 | files(2)%path = 'src/workspace/file_tree_module.f90' |
| 20 | files(2)%is_staged = .false. |
| 21 | files(2)%is_unstaged = .true. |
| 22 | files(2)%is_untracked = .false. |
| 23 | files(2)%has_incoming = .false. |
| 24 | |
| 25 | files(3)%path = 'src/workspace/file_tree_renderer_module.f90' |
| 26 | files(3)%is_staged = .false. |
| 27 | files(3)%is_unstaged = .true. |
| 28 | files(3)%is_untracked = .false. |
| 29 | files(3)%has_incoming = .false. |
| 30 | |
| 31 | ! Build tree |
| 32 | call build_tree(files, n_files, root) |
| 33 | |
| 34 | print *, 'Tree structure:' |
| 35 | call print_tree(root, '') |
| 36 | |
| 37 | ! Check workspace children specifically |
| 38 | print *, '' |
| 39 | print *, 'Checking src/workspace children:' |
| 40 | call check_workspace_children(root) |
| 41 | |
| 42 | contains |
| 43 | |
| 44 | recursive subroutine print_tree(node, prefix) |
| 45 | type(tree_node_t), pointer, intent(in) :: node |
| 46 | character(len=*), intent(in) :: prefix |
| 47 | type(tree_node_t), pointer :: child |
| 48 | |
| 49 | if (.not. associated(node)) return |
| 50 | |
| 51 | print '(A,A,A,L,A,L)', trim(prefix), trim(node%name), & |
| 52 | ' is_file=', node%is_file, ' has_next_sib=', associated(node%next_sibling) |
| 53 | |
| 54 | child => node%first_child |
| 55 | do while (associated(child)) |
| 56 | call print_tree(child, prefix // ' ') |
| 57 | child => child%next_sibling |
| 58 | end do |
| 59 | end subroutine print_tree |
| 60 | |
| 61 | recursive subroutine check_workspace_children(node) |
| 62 | type(tree_node_t), pointer, intent(in) :: node |
| 63 | type(tree_node_t), pointer :: child |
| 64 | integer :: count |
| 65 | |
| 66 | if (.not. associated(node)) return |
| 67 | |
| 68 | ! Found workspace directory |
| 69 | if (trim(node%name) == 'workspace') then |
| 70 | print *, 'Found workspace directory!' |
| 71 | child => node%first_child |
| 72 | count = 0 |
| 73 | do while (associated(child)) |
| 74 | count = count + 1 |
| 75 | print '(A,I0,A,A,A,L)', ' Child ', count, ': ', trim(child%name), & |
| 76 | ' has_next_sib=', associated(child%next_sibling) |
| 77 | child => child%next_sibling |
| 78 | end do |
| 79 | return |
| 80 | end if |
| 81 | |
| 82 | ! Recurse to children |
| 83 | child => node%first_child |
| 84 | do while (associated(child)) |
| 85 | call check_workspace_children(child) |
| 86 | child => child%next_sibling |
| 87 | end do |
| 88 | end subroutine check_workspace_children |
| 89 | |
| 90 | end program test_tree |
| 91 |