| 1 | program test_buffer_debug |
| 2 | use text_buffer_module |
| 3 | use iso_fortran_env, only: output_unit |
| 4 | implicit none |
| 5 | |
| 6 | type(buffer_t) :: buffer |
| 7 | character :: ch |
| 8 | |
| 9 | print *, "Testing buffer initialization..." |
| 10 | |
| 11 | ! Initialize buffer |
| 12 | call init_buffer(buffer) |
| 13 | |
| 14 | ! Check if buffer%data is allocated |
| 15 | if (allocated(buffer%data)) then |
| 16 | print *, "Buffer data allocated" |
| 17 | print *, "Buffer data length:", len(buffer%data) |
| 18 | print *, "Buffer size field:", buffer%size |
| 19 | print *, "Gap start:", buffer%gap_start |
| 20 | print *, "Gap end:", buffer%gap_end |
| 21 | else |
| 22 | print *, "ERROR: Buffer data not allocated!" |
| 23 | end if |
| 24 | |
| 25 | ! Try to get a character |
| 26 | print *, "Attempting to get character at position 1..." |
| 27 | ch = buffer_get_char(buffer, 1) |
| 28 | print *, "Character retrieved (as integer):", ichar(ch) |
| 29 | |
| 30 | ! Try to insert text |
| 31 | print *, "Attempting to insert text..." |
| 32 | call buffer_insert(buffer, 1, "Test") |
| 33 | print *, "Text inserted" |
| 34 | |
| 35 | ! Check buffer state after insert |
| 36 | print *, "After insert:" |
| 37 | print *, "Gap start:", buffer%gap_start |
| 38 | print *, "Gap end:", buffer%gap_end |
| 39 | |
| 40 | ! Clean up |
| 41 | call cleanup_buffer(buffer) |
| 42 | print *, "Buffer cleaned up" |
| 43 | |
| 44 | end program test_buffer_debug |