test fixes
- SHA
521d7db3483eb8b84eb13fc6d4d451cbb2428372- Parents
-
a85fba0 - Tree
ff5fc86
521d7db
521d7db3483eb8b84eb13fc6d4d451cbb2428372a85fba0
ff5fc86| Status | File | + | - |
|---|---|---|---|
| A |
test/test_buffer_debug.f90
|
44 | 0 |
| A |
test/test_buffer_only.f90
|
64 | 0 |
| M |
test/test_driver_module.f90
|
52 | 12 |
test/test_buffer_debug.f90added@@ -0,0 +1,44 @@ | ||
| 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 | |
test/test_buffer_only.f90added@@ -0,0 +1,64 @@ | ||
| 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 | |
test/test_driver_module.f90modified@@ -66,8 +66,13 @@ contains | ||
| 66 | 66 | |
| 67 | 67 | do i = 1, len(text) |
| 68 | 68 | ! Convert character to key string |
| 69 | - write(key_str, '(A)') text(i:i) | |
| 70 | - call handle_key_command(trim(key_str), editor, buffer, should_quit) | |
| 69 | + key_str = text(i:i) ! Don't use write statement, just assign directly | |
| 70 | + ! Don't trim spaces - they're valid input | |
| 71 | + if (text(i:i) == ' ') then | |
| 72 | + call handle_key_command(' ', editor, buffer, should_quit) | |
| 73 | + else | |
| 74 | + call handle_key_command(trim(key_str), editor, buffer, should_quit) | |
| 75 | + end if | |
| 71 | 76 | end do |
| 72 | 77 | end subroutine simulate_typing |
| 73 | 78 | |
@@ -94,19 +99,47 @@ contains | ||
| 94 | 99 | function get_buffer_text(buffer) result(text) |
| 95 | 100 | type(buffer_t), intent(in) :: buffer |
| 96 | 101 | character(len=:), allocatable :: text |
| 97 | - integer :: i, pos | |
| 102 | + integer :: i, pos, logical_size | |
| 98 | 103 | character :: ch |
| 99 | 104 | |
| 100 | - allocate(character(len=buffer%size) :: text) | |
| 105 | + ! Calculate logical size (total size minus gap) | |
| 106 | + logical_size = buffer%size - (buffer%gap_end - buffer%gap_start) | |
| 107 | + | |
| 108 | + if (logical_size <= 0) then | |
| 109 | + text = '' | |
| 110 | + return | |
| 111 | + end if | |
| 112 | + | |
| 113 | + allocate(character(len=logical_size) :: text) | |
| 114 | + text = repeat(' ', logical_size) ! Initialize with spaces instead of empty string | |
| 101 | 115 | pos = 0 |
| 102 | 116 | |
| 103 | - do i = 1, buffer%size | |
| 104 | - ch = buffer_get_char_at(buffer, i) | |
| 105 | - pos = pos + 1 | |
| 106 | - text(pos:pos) = ch | |
| 117 | + ! Get text before gap | |
| 118 | + do i = 1, buffer%gap_start - 1 | |
| 119 | + if (i <= len(buffer%data)) then | |
| 120 | + ch = buffer%data(i:i) | |
| 121 | + pos = pos + 1 | |
| 122 | + if (pos <= len(text)) text(pos:pos) = ch | |
| 123 | + end if | |
| 124 | + end do | |
| 125 | + | |
| 126 | + ! Get text after gap | |
| 127 | + do i = buffer%gap_end, buffer%size | |
| 128 | + if (i <= len(buffer%data)) then | |
| 129 | + ch = buffer%data(i:i) | |
| 130 | + if (ch /= char(0)) then ! Skip null characters | |
| 131 | + pos = pos + 1 | |
| 132 | + if (pos <= len(text)) text(pos:pos) = ch | |
| 133 | + end if | |
| 134 | + end if | |
| 107 | 135 | end do |
| 108 | 136 | |
| 109 | - text = text(1:pos) | |
| 137 | + ! Trim to actual content length | |
| 138 | + if (pos > 0) then | |
| 139 | + text = text(1:pos) | |
| 140 | + else | |
| 141 | + text = '' | |
| 142 | + end if | |
| 110 | 143 | end function get_buffer_text |
| 111 | 144 | |
| 112 | 145 | function get_line_text(buffer, line_num) result(text) |
@@ -181,7 +214,7 @@ contains | ||
| 181 | 214 | |
| 182 | 215 | if (actual /= expected) then |
| 183 | 216 | if (present(test_name)) then |
| 184 | - write(msg, '(A,A,I0)') trim(test_name), ": Line ", line_num, " mismatch" | |
| 217 | + write(msg, '(A,A,I0,A)') trim(test_name), ": Line ", line_num, " mismatch" | |
| 185 | 218 | else |
| 186 | 219 | write(msg, '(A,I0,A)') "Line ", line_num, " mismatch" |
| 187 | 220 | end if |
@@ -196,16 +229,23 @@ contains | ||
| 196 | 229 | type(buffer_t), intent(in) :: buffer |
| 197 | 230 | integer, intent(in) :: position |
| 198 | 231 | character :: ch |
| 232 | + integer :: actual_pos | |
| 199 | 233 | |
| 200 | 234 | if (position < 1 .or. position > buffer%size) then |
| 201 | 235 | ch = char(0) |
| 202 | 236 | return |
| 203 | 237 | end if |
| 204 | 238 | |
| 205 | - if (position <= buffer%gap_start) then | |
| 239 | + if (position < buffer%gap_start) then | |
| 206 | 240 | ch = buffer%data(position:position) |
| 207 | 241 | else |
| 208 | - ch = buffer%data(position + (buffer%gap_end - buffer%gap_start - 1):position + (buffer%gap_end - buffer%gap_start - 1)) | |
| 242 | + ! Adjust position for gap | |
| 243 | + actual_pos = position + (buffer%gap_end - buffer%gap_start) | |
| 244 | + if (actual_pos <= len(buffer%data)) then | |
| 245 | + ch = buffer%data(actual_pos:actual_pos) | |
| 246 | + else | |
| 247 | + ch = char(0) | |
| 248 | + end if | |
| 209 | 249 | end if |
| 210 | 250 | end function buffer_get_char_at |
| 211 | 251 | |