| 1 | program test_buffer_only |
| 2 | ! Simple test to verify buffer module works correctly |
| 3 | use text_buffer_module |
| 4 | use iso_fortran_env, only: output_unit |
| 5 | implicit none |
| 6 | |
| 7 | type(buffer_t) :: buffer |
| 8 | character(len=:), allocatable :: line |
| 9 | integer :: line_count |
| 10 | |
| 11 | print *, "Testing buffer module..." |
| 12 | |
| 13 | ! Test 1: Initialize empty buffer |
| 14 | call init_buffer(buffer) |
| 15 | print *, "✓ Buffer initialized" |
| 16 | |
| 17 | ! Test 2: Insert some text |
| 18 | call buffer_insert(buffer, 1, "Hello World") |
| 19 | print *, "✓ Text inserted" |
| 20 | |
| 21 | ! Test 3: Get buffer size |
| 22 | print *, "Buffer logical size:", buffer%size |
| 23 | print *, "Buffer gap start:", buffer%gap_start |
| 24 | print *, "Buffer gap end:", buffer%gap_end |
| 25 | |
| 26 | ! Test 4: Get line |
| 27 | line = buffer_get_line(buffer, 1) |
| 28 | print *, "Line 1: '", line, "'" |
| 29 | if (line == "Hello World") then |
| 30 | print *, "✓ Line retrieval works" |
| 31 | else |
| 32 | print *, "✗ Line retrieval failed" |
| 33 | end if |
| 34 | |
| 35 | ! Test 5: Insert newline |
| 36 | call buffer_insert(buffer, 6, char(10)) ! After "Hello" |
| 37 | print *, "✓ Newline inserted" |
| 38 | |
| 39 | ! Test 6: Get line count |
| 40 | line_count = buffer_get_line_count(buffer) |
| 41 | print *, "Line count:", line_count |
| 42 | if (line_count == 2) then |
| 43 | print *, "✓ Line count correct" |
| 44 | else |
| 45 | print *, "✗ Line count wrong" |
| 46 | end if |
| 47 | |
| 48 | ! Test 7: Get second line |
| 49 | line = buffer_get_line(buffer, 2) |
| 50 | print *, "Line 2: '", line, "'" |
| 51 | if (line == " World") then |
| 52 | print *, "✓ Second line correct" |
| 53 | else |
| 54 | print *, "✗ Second line wrong" |
| 55 | end if |
| 56 | |
| 57 | ! Clean up |
| 58 | call cleanup_buffer(buffer) |
| 59 | print *, "✓ Buffer cleaned up" |
| 60 | |
| 61 | print *, "" |
| 62 | print *, "Buffer module tests complete!" |
| 63 | |
| 64 | end program test_buffer_only |